/
proposal_runner_test.rb
executable file
·190 lines (163 loc) · 7.24 KB
/
proposal_runner_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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#! /usr/bin/env rspec
require_relative "./test_helper"
require "installation/proposal_runner"
Yast.import "ProductControl"
Yast.import "GetInstArgs"
Yast.import "Mode"
describe ::Installation::ProposalRunner do
let(:autoyast_proposals) { [] }
before do
# mock constant to avoid dependency on autoyast
autoinst_config = double(Confirm: false, getProposalList: autoyast_proposals)
stub_const("Yast::AutoinstConfig", autoinst_config)
allow(Yast::UI).to receive(:UserInput).and_return(:accept)
end
describe ".new" do
it "Allows passing different store implementation" do
class C < ::Installation::ProposalStore; end
expect { ::Installation::ProposalRunner.new(C) }.to_not raise_error
end
end
describe "#run" do
PROPERTIES = {
"enable_skip" => "no",
"label" => "Installation Settings",
"mode" => "autoinstallation",
"name" => "initial",
"stage" => "initial",
"unique_id" => "auto_inst_proposal",
"proposal_modules" => [
{ "name" => "hwinfo", "presentation_order" => "90" },
{ "name" => "keyboard", "presentation_order" => "15" }
]
}.freeze
let(:properties) { PROPERTIES }
let(:proposals) { [["keyboard_proposal", 90], ["hwinfo_proposal", 15]] }
let(:keyboard_description) do
{ "id" => "keyboard_stuff", "menu_title" => "&Keyboard Layout", "rich_text_title" => "Keyboard Layout" }
end
let(:hwinfo_description) do
{ "id" => "init_hwinfo", "menu_title" => "S&ystem", "rich_text_title" => "System" }
end
before do
allow(Yast::ProductControl).to receive(:getProposalProperties)
.and_return(properties)
allow(Yast::ProductControl).to receive(:getProposals)
.and_return(proposals)
allow_any_instance_of(::Installation::ProposalStore).to receive(:proposal_names)
.and_return(proposals.map(&:first))
allow(Yast::WFM).to receive(:CallFunction).and_call_original
allow(Yast::WFM).to receive(:CallFunction)
.with("keyboard_proposal", ["Description", {}]).and_return(keyboard_description)
allow(Yast::WFM).to receive(:CallFunction)
.with("hwinfo_proposal", ["Description", {}]).and_return(hwinfo_description)
end
it "do nothing if run non-interactive" do
allow(Yast::Mode).to receive(:autoinst).and_return(true)
expect(subject.run).to eq :auto
end
it "do nothing if given proposal type is disabled" do
allow(Yast::ProductControl).to receive(:GetDisabledProposals).and_return(["initial"])
allow(Yast::GetInstArgs).to receive(:proposal).and_return("initial")
expect(subject.run).to eq :auto
end
describe "#html_header" do
it "returns clickable header when forced" do
allow(Yast::GetInstArgs).to receive(:proposal).and_return("software")
expect_any_instance_of(::Installation::ProposalRunner)
.to receive(:submod_descriptions_and_build_menu)
.and_return(false)
expect_any_instance_of(::Installation::ProposalStore)
.to receive(:title_for)
.and_return("Software")
expect_any_instance_of(::Installation::ProposalStore)
.to receive(:id_for)
.and_return("software")
expect_any_instance_of(::Installation::ProposalStore)
.not_to receive(:read_only?)
# initialization of internal state
expect(subject.run).to eq :auto
expect(subject.send(:html_header, "software", force_rw: true)).to eql Yast::HTML.Heading(Yast::HTML.Link("Software", "software"))
end
end
context "when proposal contains tabs" do
let(:properties) do
PROPERTIES.merge(
"proposal_tabs" => [
{ "label" => "Overview", "proposal_modules" => ["keyboard"] },
{ "label" => "Expert", "proposal_modules" => ["hwinfo", "keyboard"] }
]
)
end
it "makes a proposal" do
expect_any_instance_of(::Installation::ProposalStore).to receive(:make_proposal)
.with("keyboard_proposal", anything).and_return("preformatted_proposal" => "")
expect_any_instance_of(::Installation::ProposalStore).to receive(:make_proposal)
.with("hwinfo_proposal", anything).and_return("preformatted_proposal" => "")
expect(subject.run).to eq(:next)
end
context "and the proposal screen is configured through AutoYaST" do
let(:autoyast_proposals) { ["keyboard_proposal"] } # check bsc#1013976
it "makes a proposal" do
expect_any_instance_of(::Installation::ProposalStore).to receive(:make_proposal)
.with("keyboard_proposal", anything).and_return("preformatted_proposal" => "")
expect_any_instance_of(::Installation::ProposalStore).to receive(:make_proposal)
.with("hwinfo_proposal", anything).and_return("preformatted_proposal" => "")
expect(subject.run).to eq(:next)
end
end
end
context "when proposal does not contain tabs" do
it "makes a proposal" do
expect_any_instance_of(::Installation::ProposalStore).to receive(:make_proposal)
.with("keyboard_proposal", anything).and_return("preformatted_proposal" => "")
expect_any_instance_of(::Installation::ProposalStore).to receive(:make_proposal)
.with("hwinfo_proposal", anything).and_return("preformatted_proposal" => "")
expect(subject.run).to eq(:next)
end
context "and the proposal screen is configured through AutoYaST" do
let(:autoyast_proposals) { ["keyboard_proposal"] } # check bsc#1013976
it "makes a proposal" do
expect_any_instance_of(::Installation::ProposalStore).to receive(:make_proposal)
.with("keyboard_proposal", anything).and_return("preformatted_proposal" => "")
expect_any_instance_of(::Installation::ProposalStore).to receive(:make_proposal)
.with("hwinfo_proposal", anything).and_return("preformatted_proposal" => "")
expect(subject.run).to eq(:next)
end
end
context "and it enables soft r/o proposal in case of error" do
PROPERTIES = {
"enable_skip" => "no",
"label" => "Installation Settings",
"mode" => "autoinstallation",
"name" => "initial",
"stage" => "initial",
"unique_id" => "auto_inst_proposal",
"proposal_modules" => [
{ "name" => "software", "presentation_order" => "15", "read_only" => "soft" }
]
}.freeze
let(:proposals) { [["software_proposal", 15]] }
it "makes a proposal" do
allow(subject)
.to receive(:html_header)
.with("software_proposal")
.and_call_original
# we need ProposalStore#make_proposal to call the callback
expect(Yast::WFM)
.to receive(:CallFunction)
.and_return(
"preformated_proposal" => "",
"warning_lever" => :error
)
expect(subject)
.to receive(:html_header)
.with("software_proposal", force_rw: true)
.at_least(:once)
.and_call_original
expect(subject.run).to eq(:next)
end
end
end
end
end