-
Notifications
You must be signed in to change notification settings - Fork 7
/
query_dialog_test.rb
executable file
·113 lines (92 loc) · 3.59 KB
/
query_dialog_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#! /usr/bin/rspec
# Copyright (c) 2014 SUSE LLC.
# All Rights Reserved.
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 or 3 of the GNU General
# Public License as published by the Free Software Foundation.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, contact SUSE LLC.
# To contact Novell about this file by physical or electronic mail,
# you may find current contact information at www.suse.com
require_relative "spec_helper"
require "y2journal/query_dialog"
if !ENV["TRAVIS"]
describe Y2Journal::QueryDialog do
def property(id, property)
Yast::UI.QueryWidget(Id(id), property)
end
# Sends a user input to libyui, optionally running some code before.
#
# @param value [Symbol/String] the input expected by UI.UserInput
# @param pre_hook [Proc] code used to tie the expectations or any other
# action to input events. For example, checking the final status of the
# dialog before closing it. The effect of an input can be checked on the
# pre_hook of the next one to make sure libyui has already applied all the
# changes.
def send_user_input(value, pre_hook: nil)
expect(Yast::UI).to receive(:UserInput) do
pre_hook.call if pre_hook
value
end
end
before(:all) do
Yast.ui_component = "ncurses"
end
before(:each) do
Yast::UI.OpenUI
# The QueryPresenter needs to check the number of previous boots
allow_to_execute(/journalctl --list-boots/)
.and_return(cmd_result_for("list-boots-11"))
# Ensure initial status of the dialog:
# all filter checkboxes unchecked...
Yast::UI.ChangeWidget(Id("unit"), :Value, false)
Yast::UI.ChangeWidget(Id("match"), :Value, false)
Yast::UI.ChangeWidget(Id("priority"), :Value, false)
# ...and interval set to 'since system's boot'
Yast::UI.ChangeWidget(Id(:interval), :CurrentButton, "0")
end
after(:each) do
Yast::UI.CloseUI
end
subject(:dialog) do
query_presenter = Y2Journal::QueryPresenter.new
Y2Journal::QueryDialog.new(query_presenter)
end
describe "#match_value_handler" do
it "automatically checks the 'match' checkbox when value changes" do
send_user_input :match_value
send_user_input :ok,
pre_hook: -> { expect(property("match", :Value)).to eq true }
dialog.run
end
end
describe "#unit_value_handler" do
it "automatically checks the 'unit' checkbox when value changes" do
send_user_input :unit_value
send_user_input :ok,
pre_hook: -> { expect(property("unit", :Value)).to eq true }
dialog.run
end
end
describe "#until_date_handler" do
it "automatically checks the dates checkbox when 'until date' changes" do
send_user_input :until_date
send_user_input :ok,
pre_hook: -> { expect(property(:interval, :CurrentButton)).to eq "Hash" }
dialog.run
end
end
describe "#since_time_handler" do
it "automatically checks the dates checkbox when 'since time' changes" do
send_user_input :since_time
send_user_input :ok,
pre_hook: -> { expect(property(:interval, :CurrentButton)).to eq "Hash" }
dialog.run
end
end
end
end