Skip to content

Commit

Permalink
Merge pull request #215 from yast/device_map_dialog_test
Browse files Browse the repository at this point in the history
Add test for device map dialog and fix discovered bug
  • Loading branch information
jreidinger committed Feb 12, 2015
2 parents 8e64640 + 002ec37 commit af88b4e
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/lib/bootloader/device_map_dialog.rb
Expand Up @@ -32,8 +32,11 @@ def run
private

def create_dialog
Yast::UI.OpenDialog dialog_content
res = Yast::UI.OpenDialog dialog_content
return false unless res
refresh_buttons

true
end

def close_dialog
Expand Down
70 changes: 70 additions & 0 deletions test/device_map_dialog_test.rb
@@ -0,0 +1,70 @@
require_relative "test_helper"

require "bootloader/device_map_dialog"

describe Bootloader::DeviceMapDialog do
# just simple tests to avoid typos as logic is not so easy to test
describe "#run" do
before do
Yast.import "BootStorage"

device_map = Bootloader::DeviceMap.new(
"/dev/sda" => "hd0",
"/dev/sdb" => "hd1"
)
allow(Yast::BootStorage).to receive(:DisksOrder)
.and_return(device_map.disks_order)

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)
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)

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

0 comments on commit af88b4e

Please sign in to comment.