Skip to content

Commit

Permalink
Merge 0fa5d06 into a157ec7
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Sep 20, 2018
2 parents a157ec7 + 0fa5d06 commit 4ff7e62
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/lib/y2firewall/dialogs/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

require "yast"
require "cwm/dialog"
require "y2firewall/widgets/overview"
require "y2firewall/widgets/overview_tree_pager"

Yast.import "Label"

Expand Down
48 changes: 48 additions & 0 deletions src/lib/y2firewall/widgets/overview_tree.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# encoding: utf-8

# ------------------------------------------------------------------------------
# Copyright (c) 2018 SUSE LLC
#
#
# 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.
#
# To contact SUSE about this file by physical or electronic mail, you may find
# current contact information at www.suse.com.
# ------------------------------------------------------------------------------

require "yast"
require "cwm/tree"

module Y2Firewall
module Widgets
# A tree that is told what its items are.
# We need a tree whose items include Pages that point to the OverviewTreePager.
class OverviewTree < CWM::Tree
# @!attribute [r] items
# @return [Array<CWM::PagerTreeItem>] List of tree items
attr_reader :items

# Constructor
#
# @param items [Array<CWM::PagerTreeItem>] List of tree items to be included
def initialize(items)
textdomain "firewall"
@items = items
end

# @macro seeAbstractWidget
def label
_("System View")
end
end
end
end
Original file line number Diff line number Diff line change
@@ -1,50 +1,33 @@
# encoding: utf-8

# ------------------------------------------------------------------------------
# Copyright (c) 2018 SUSE LLC
# 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 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.
# 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.
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE about this file by physical or electronic mail, you may find
# current contact information at www.suse.com.
# ------------------------------------------------------------------------------
# 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/widget"
require "cwm/tree"
require "cwm/tree_pager"
require "y2firewall/firewalld"
require "y2firewall/widgets/overview_tree"
require "y2firewall/widgets/pages"
require "y2firewall/helpers/interfaces"
require "y2firewall/ui_state"

module Y2Firewall
module Widgets
# A tree that is told what its items are.
# We need a tree whose items include Pages that point to the OverviewTreePager.
class OverviewTree < CWM::Tree
def initialize(items)
textdomain "firewall"
@items = items
end

# @macro seeAbstractWidget
def label
_("System View")
end

attr_reader :items
end

# 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.
Expand Down Expand Up @@ -74,6 +57,8 @@ def items

# 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
Expand Down
53 changes: 53 additions & 0 deletions test/lib/y2firewall/widgets/overview_tree_pager_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/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"

describe Y2Firewall::Widgets::OverviewTreePager do
subject(:widget) { described_class.new }

let(:startup_page) { double("Startup").as_null_object }

before do
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) { Y2Firewall::Widgets::Pages::Zones.new(double("pager")) }

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
end
39 changes: 39 additions & 0 deletions test/lib/y2firewall/widgets/overview_tree_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/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"
require "cwm/tree_pager"

describe Y2Firewall::Widgets::OverviewTree do
subject(:widget) { described_class.new([tree_item1, tree_item2]) }

let(:tree_item1) { instance_double(CWM::PagerTreeItem) }
let(:tree_item2) { instance_double(CWM::PagerTreeItem) }

describe "#items" do
it "returns the list of included items" do
expect(widget.items).to eq([tree_item1, tree_item2])
end
end
end

0 comments on commit 4ff7e62

Please sign in to comment.