-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract OverviewTreePager to its own file and add unit tests
- Loading branch information
Showing
4 changed files
with
175 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
# encoding: utf-8 | ||
|
||
# Copyright (c) [2018] SUSE LLC | ||
# | ||
# All Rights Reserved. | ||
# | ||
# This program is free software; you can redistribute it and/or modify it | ||
# under the terms of version 2 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 SUSE LLC about this file by physical or electronic mail, you may | ||
# find current contact information at www.suse.com. | ||
|
||
require "yast" | ||
require "cwm/tree_pager" | ||
require "y2firewall/firewalld" | ||
require "y2firewall/widgets/overview_tree" | ||
require "y2firewall/widgets/pages" | ||
require "y2firewall/helpers/interfaces" | ||
|
||
module Y2Firewall | ||
module Widgets | ||
# Widget representing firewall overview pager with tree on left side and rest on right side. | ||
# | ||
# It has replace point where it displays more details about selected element in firewall. | ||
class OverviewTreePager < CWM::TreePager | ||
include Y2Firewall::Helpers::Interfaces | ||
|
||
# Constructor | ||
def initialize | ||
textdomain "firewall" | ||
|
||
@fw = Y2Firewall::Firewalld.instance | ||
super(OverviewTree.new(items)) | ||
end | ||
|
||
# @see http://www.rubydoc.info/github/yast/yast-yast2/CWM%2FTree:items | ||
def items | ||
[ | ||
startup_item, | ||
interfaces_item, | ||
zones_item, | ||
# masquerade_item, | ||
# broadcast_item, | ||
# logging_item, | ||
# custom_rules_item | ||
] | ||
end | ||
|
||
# Overrides default behavior of TreePager to register the new state with | ||
# {UIState} before jumping to the tree node | ||
# | ||
# @param page [CWM::Page] Page to switch to | ||
def switch_page(page) | ||
UIState.instance.go_to_tree_node(page) | ||
super | ||
end | ||
|
||
# Ensures the tree is properly initialized according to {UIState} after | ||
# a redraw. | ||
def initial_page | ||
UIState.instance.find_tree_node(@pages) || super | ||
end | ||
|
||
private | ||
|
||
# @return [CWM::PagerTreeItem] | ||
def startup_item | ||
page = Pages::Startup.new(self) | ||
CWM::PagerTreeItem.new(page) | ||
end | ||
|
||
# @return [CWM::PagerTreeItem] | ||
def interfaces_item | ||
page = Pages::Interfaces.new(self) | ||
CWM::PagerTreeItem.new(page) | ||
end | ||
|
||
# @return [CWM::PagerTreeItem] | ||
def zones_item | ||
zones = @fw.zones | ||
children = zones.map { |z| zone_item(z) } | ||
page = Pages::Zones.new(self) | ||
CWM::PagerTreeItem.new(page, children: children) | ||
end | ||
|
||
# @return [CWM::PagerTreeItem] | ||
def zone_item(z) | ||
page = Pages::Zone.new(z, self) | ||
CWM::PagerTreeItem.new(page) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#!/usr/bin/env rspec | ||
# encoding: utf-8 | ||
|
||
# Copyright (c) [2018] SUSE LLC | ||
# | ||
# All Rights Reserved. | ||
# | ||
# This program is free software; you can redistribute it and/or modify it | ||
# under the terms of version 2 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 SUSE LLC about this file by physical or electronic mail, you may | ||
# find current contact information at www.suse.com. | ||
|
||
require_relative "../../../test_helper.rb" | ||
require "cwm/rspec" | ||
require "y2firewall/widgets/overview_tree_pager" | ||
require "y2firewall/widgets/pages" | ||
|
||
RSpec.shared_examples "CWM::TreePager" do | ||
include_examples "CWM::Pager" | ||
end | ||
|
||
describe Y2Firewall::Widgets::OverviewTreePager do | ||
let(:widget) { described_class.new } | ||
|
||
before do | ||
fw = double("fake firewall") | ||
z1 = double(name: "air") | ||
allow(Y2Firewall::Firewalld).to receive(:instance).and_return(fw) | ||
allow(fw).to receive(:zones).and_return([z1]) | ||
|
||
if1 = { | ||
"id" => "eth0", | ||
"name" => "Intel Ethernet Connection I217-LM", | ||
"zone" => "external" | ||
} | ||
allow_any_instance_of(Y2Firewall::Helpers::Interfaces) | ||
.to receive(:known_interfaces).and_return([if1]) | ||
|
||
startup_page = double("fake page", widget_id: "fake", label: "f", initial: false) | ||
allow(Y2Firewall::Widgets::Pages::Startup) | ||
.to receive(:new) | ||
.and_return startup_page | ||
end | ||
|
||
describe "#initial_page" do | ||
it "navigates to the page stored in the UIState instance" do | ||
expect(Y2Firewall::UIState.instance).to receive(:find_tree_node) | ||
widget.initial_page | ||
end | ||
end | ||
|
||
describe "#switch_page" do | ||
let(:page) { double("zones page", widget_id: "zones", label: "z", initial: false) } | ||
|
||
it "registers the page in the UIState instance" do | ||
expect(Y2Firewall::UIState.instance).to receive(:go_to_tree_node).with(page) | ||
widget.switch_page(page) | ||
end | ||
end | ||
|
||
include_examples "CWM::TreePager" | ||
end |