-
Notifications
You must be signed in to change notification settings - Fork 22
/
device_map_dialog_test.rb
90 lines (66 loc) · 2.52 KB
/
device_map_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
require_relative "test_helper"
require "bootloader/device_map_dialog"
describe Bootloader::DeviceMapDialog do
let(:device_map) do
device_map = Bootloader::DeviceMap.new
device_map.add_mapping("hd0", "/dev/sda")
device_map.add_mapping("hd1", "/dev/sdb")
device_map
end
subject { Bootloader::DeviceMapDialog.new(device_map) }
# just simple tests to avoid typos as logic is not so easy to test
describe "#run" do
before do
allow(Yast::UI).to receive(:QueryWidget).and_return("/dev/sda")
allow(Yast::UI).to receive(:OpenDialog).and_return(true)
allow(Yast::UI).to receive(:CloseDialog).and_return(true)
allow(Yast::BootStorage).to receive(:assign_mbr_disk_by_name)
end
def mock_ui_events(*events)
allow(Yast::UI).to receive(:UserInput).and_return(*events)
end
it "always returns symbol :back" do
mock_ui_events(:ok)
expect(subject.run).to eq :back
mock_ui_events(:cancel)
expect(subject.run).to eq :back
end
it "allows adding disks after clicking on button" do
# need additional ok for adding dialog
mock_ui_events(:add, :ok, :ok)
allow(Yast::UI).to receive(:QueryWidget).with(anything, :SelectedItems)
.and_return(["/dev/sda", "/dev/sda", "/dev/sdb"])
expect(subject.run).to eq :back
end
it "allows adding disks in config mode after clicking on button" do
# need additional ok for adding dialog
mock_ui_events(:add, :ok, :ok)
allow(Yast::Mode).to receive(:config).and_return(true)
expect(subject.run).to eq :back
end
it "allows adding disks in auto mode after clicking on button" do
# need additional ok for adding dialog
mock_ui_events(:add, :ok, :ok)
allow(Yast::Mode).to receive(:auto).and_return(true)
expect(subject.run).to eq :back
end
it "allows removing disks after clicking on button" do
mock_ui_events(:delete, :ok)
# need to simulate that disk gone
allow(Yast::UI).to receive(:QueryWidget).and_return("/dev/sda", "/dev/sda", "/dev/sdb")
expect(subject.run).to eq :back
end
it "allows moving disk in order up by clicking on button" do
mock_ui_events(:up, :ok)
expect(subject.run).to eq :back
end
it "allows moving disk in order down by clicking on button" do
mock_ui_events(:down, :ok)
expect(subject.run).to eq :back
end
it "react when user change selection in disk order" do
mock_ui_events(:disks, :ok)
expect(subject.run).to eq :back
end
end
end