-
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.
- Loading branch information
Showing
2 changed files
with
279 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,242 @@ | ||
#!/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" | ||
|
||
require "cwm/rspec" | ||
require "y2firewall/firewalld/interface" | ||
require "y2firewall/widgets/zone" | ||
|
||
describe Y2Firewall::Dialogs::NameWidget do | ||
subject(:widget) { described_class.new(eth0, disabled: disabled) } | ||
|
||
let(:eth0) { Y2Firewall::Firewalld::Interface.new("eth0") } | ||
let(:disabled) { false } | ||
let(:value) { "zone_name" } | ||
|
||
before do | ||
allow(subject).to receive(:value).and_return(value) | ||
end | ||
|
||
include_examples "CWM::AbstractWidget" | ||
|
||
describe "#init" do | ||
it "sets the value with interface name" do | ||
expect(subject).to receive(:value=).with("eth0") | ||
|
||
subject.init | ||
end | ||
|
||
context "when widget was created enabled" do | ||
xit "returns true" do | ||
expect(subject.init).to be(true) | ||
end | ||
end | ||
|
||
context "when widget was created disabled" do | ||
let(:disabled) { true } | ||
|
||
xit "returns false" do | ||
expect(subject.init).to be(false) | ||
end | ||
end | ||
end | ||
|
||
describe "#validate" do | ||
context "when value only contains alphanumeric chars" do | ||
it "returns true" do | ||
expect(subject.validate).to be(true) | ||
end | ||
end | ||
|
||
context "when value has any not alphanumeric char" do | ||
let(:value) { "Invalid zone name" } | ||
|
||
before do | ||
allow(Yast::Report).to receive(:Error) | ||
allow(Yast::UI).to receive(:SetFocus) | ||
end | ||
|
||
it "reports an error" do | ||
expect(Yast::Report).to receive(:Error).with(/alphanumeric/) | ||
|
||
subject.validate | ||
end | ||
|
||
it "receives the focus" do | ||
expect(Yast::UI).to receive(:SetFocus).with(Id(subject.widget_id)) | ||
|
||
subject.validate | ||
end | ||
|
||
it "returns false" do | ||
expect(subject.validate).to be(false) | ||
end | ||
end | ||
end | ||
|
||
describe "#store" do | ||
it "sets value as zone name" do | ||
expect(eth0).to receive(:name=).with(value) | ||
|
||
subject.store | ||
end | ||
end | ||
|
||
describe("#focus") do | ||
it "sets focus on itself" do | ||
expect(Yast::UI).to receive(:SetFocus).with(Id(subject.widget_id)) | ||
|
||
subject.focus | ||
end | ||
end | ||
end | ||
|
||
describe Y2Firewall::Dialogs::DescriptionWidget do | ||
subject(:widget) { described_class.new(eth0) } | ||
|
||
let(:eth0) { Y2Firewall::Firewalld::Interface.new("eth0") } | ||
let(:initial_value) { "The inicial zone desription" } | ||
let(:new_value) { "A new zone description" } | ||
|
||
before do | ||
allow(subject).to receive(:value).and_return(new_value) | ||
allow(eth0).to receive(:description).and_return(initial_value) | ||
end | ||
|
||
include_examples "CWM::AbstractWidget" | ||
|
||
describe "#init" do | ||
it "sets the value with the interface description" do | ||
expect(subject).to receive(:value=).with(initial_value) | ||
|
||
subject.init | ||
end | ||
end | ||
|
||
describe "#validate" do | ||
context "when value is not empty" do | ||
it "returns true" do | ||
expect(subject.validate).to be(true) | ||
end | ||
end | ||
|
||
context "when value is empty" do | ||
let(:new_value) { "" } | ||
|
||
before do | ||
allow(Yast::Report).to receive(:Error) | ||
allow(Yast::UI).to receive(:SetFocus) | ||
end | ||
|
||
it "reports an error" do | ||
expect(Yast::Report).to receive(:Error).with(/provide a description/) | ||
|
||
subject.validate | ||
end | ||
|
||
it "receives the focus" do | ||
expect(Yast::UI).to receive(:SetFocus).with(Id(subject.widget_id)) | ||
|
||
subject.validate | ||
end | ||
|
||
it "returns false" do | ||
expect(subject.validate).to be(false) | ||
end | ||
end | ||
end | ||
|
||
describe "#store" do | ||
it "sets value as zone description" do | ||
expect(eth0).to receive(:description=).with(new_value) | ||
|
||
subject.store | ||
end | ||
end | ||
|
||
describe("#focus") do | ||
it "sets focus on itself" do | ||
expect(Yast::UI).to receive(:SetFocus).with(Id(subject.widget_id)) | ||
|
||
subject.focus | ||
end | ||
end | ||
end | ||
|
||
describe Y2Firewall::Dialogs::TargetWidget do | ||
subject(:widget) { described_class.new(eth0) } | ||
|
||
let(:eth0) { Y2Firewall::Firewalld::Interface.new("eth0") } | ||
|
||
include_examples "CWM::ComboBox" | ||
|
||
describe "#init" do | ||
before do | ||
allow(eth0).to receive(:target).and_return(target) | ||
end | ||
|
||
context "when zone has a target" do | ||
let(:target) { :accept } | ||
|
||
it "sets value to target" do | ||
expect(subject).to receive(:value=).with(target) | ||
|
||
subject.init | ||
end | ||
end | ||
|
||
context "when zone does not have a target" do | ||
let(:target) { nil } | ||
|
||
it "sets value to 'default'" do | ||
expect(subject).to receive(:value=).with("default") | ||
|
||
subject.init | ||
end | ||
end | ||
end | ||
|
||
describe "#store" do | ||
it "sets the zone target" do | ||
expect(eth0).to receive(:target=).with(subject.value) | ||
|
||
subject.store | ||
end | ||
end | ||
end | ||
|
||
describe Y2Firewall::Dialogs::MasqueradeWidget do | ||
subject(:widget) { described_class.new(eth0) } | ||
|
||
let(:eth0) { Y2Firewall::Firewalld::Interface.new("eth0") } | ||
|
||
include_examples "CWM::CheckBox" | ||
|
||
describe "#store" do | ||
it "sets the zone masquerade" do | ||
expect(eth0).to receive(:masquerade=).with(subject.value) | ||
|
||
subject.store | ||
end | ||
end | ||
end |