Skip to content

Commit

Permalink
Improve test coverage (#89)
Browse files Browse the repository at this point in the history
* Minor improvements in InterfacesTable
* Add more unit tests to ZonesTable
  • Loading branch information
imobachgs committed Sep 21, 2018
1 parent 2b7c1d4 commit 9616059
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/lib/y2firewall/widgets/interfaces_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def initialize(interfaces, change_zone_button)
textdomain "firewall"
@interfaces = interfaces
@change_zone_button = change_zone_button
self.widget_id = "interfaces_table"
end

# @macro seeAbstractWidget
Expand Down Expand Up @@ -81,7 +82,7 @@ def items

# @macro seeAbstractWidget
def handle(event)
return nil unless event["EventReason"] == "SelectionChanged"
return nil unless my_event?(event) && event["EventReason"] == "SelectionChanged"
UIState.instance.select_row(value)
change_zone_button.interface = selected_interface
nil
Expand Down
2 changes: 2 additions & 0 deletions src/lib/y2firewall/widgets/zones_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# find current contact information at www.suse.com.

require "cwm/table"
require "y2firewall/ui_state"

module Y2Firewall
module Widgets
Expand All @@ -43,6 +44,7 @@ def initialize(zones, interfaces, default_zone_button)
@zones = zones
@interfaces = interfaces
@default_zone_button = default_zone_button
self.widget_id = "zones_table"
end

# @macro seeAbstractWidget
Expand Down
6 changes: 2 additions & 4 deletions test/lib/y2firewall/widgets/interfaces_table_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@

describe "#handle" do
context "when the selection is changed" do
let(:event) { { "EventReason" => "SelectionChanged" } }
let(:event) { { "ID" => "interfaces_table", "EventReason" => "SelectionChanged" } }

before do
allow(widget).to receive(:value).and_return(:eth1)
Expand All @@ -125,14 +125,12 @@
end

context "when the selection is not changed" do
let(:event) { { "EventReason" => "Whatever" } }
let(:event) { { "ID" => "interfaces_table", "EventReason" => "Whatever" } }

it "does not select the current row in the UI state" do
expect(Y2Firewall::UIState.instance).to_not receive(:select_row)
widget.handle(event)
end
end
end

describe "#selected_interface"
end
54 changes: 54 additions & 0 deletions test/lib/y2firewall/widgets/zones_table_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,58 @@
)
end
end

describe "#init" do
before do
allow(Y2Firewall::UIState.instance).to receive(:row_id).and_return(row_id)
allow(widget).to receive(:value).and_return(nil)
end

context "when no row has been visited previously" do
let(:row_id) { nil }

it "does not select any specific row" do
expect(widget).to_not receive(:value=)
widget.init
end
end

context "when a row has been visited" do
let(:row_id) { :dmz }

it "does selects the visited row" do
expect(widget).to receive(:value=).with(:dmz)
widget.init
end
end
end

describe "#handle" do
context "when the selection is changed" do
let(:event) { { "ID" => "zones_table", "EventReason" => "SelectionChanged" } }

before do
allow(widget).to receive(:value).and_return(:dmz)
end

it "selects the current row in the UI state" do
expect(Y2Firewall::UIState.instance).to receive(:select_row).with(:dmz)
widget.handle(event)
end

it "updates the button to set the default zone" do
expect(default_zone_button).to receive(:zone=).with(dmz_zone)
widget.handle(event)
end
end

context "when the selection is not changed" do
let(:event) { { "ID" => "zones_table", "EventReason" => "Whatever" } }

it "does not select the current row in the UI state" do
expect(Y2Firewall::UIState.instance).to_not receive(:select_row)
widget.handle(event)
end
end
end
end

0 comments on commit 9616059

Please sign in to comment.