Skip to content

Commit

Permalink
Split overview classes (#84)
Browse files Browse the repository at this point in the history
* Extract OverviewTree to its own file and add unit tests
* Extract OverviewTreePager to its own file and add unit tests
* Remove old overview widgets tests
  • Loading branch information
imobachgs committed Sep 20, 2018
1 parent 14ac627 commit d3a38cb
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 54 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
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
#!/usr/bin/env rspec
# 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_relative "../../../test_helper.rb"
require "cwm/rspec"
require "y2firewall/widgets/overview"

RSpec.shared_examples "CWM::Tree" do
include_examples "CWM::CustomWidget"
end
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")
Expand All @@ -52,10 +52,21 @@
.and_return startup_page
end

include_examples "CWM::TreePager"
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) }

describe Y2Firewall::Widgets::OverviewTree do
subject { described_class.new([]) }
include_examples "CWM::Tree"
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
43 changes: 43 additions & 0 deletions test/lib/y2firewall/widgets/overview_tree_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/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
include_examples "CWM::CustomWidget"

subject(:widget) { described_class.new([]) }

describe "#items" do
subject(:widget) { described_class.new([tree_item1, tree_item2]) }

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

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

0 comments on commit d3a38cb

Please sign in to comment.