Skip to content

Commit

Permalink
Suggest interface name change when the VLAN Id is modified
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed Jan 22, 2021
1 parent a82fc24 commit 52dd9ca
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
22 changes: 22 additions & 0 deletions src/lib/y2network/widgets/vlan_id.rb
Expand Up @@ -42,6 +42,9 @@ def init
end

def store
return unless modified?

@config.name = suggested_name if suggest_vlan_name
@config.vlan_id = value
end

Expand All @@ -52,6 +55,25 @@ def minimum
def maximum
9999
end

private

def modified?
@config.vlan_id != value
end

def suggested_name
"vlan#{value}"
end

def suggest_vlan_name
Yast::Popup.YesNo(
format(
_("Would you like to adapt the interface name from '%s' to '%s'?"),
@config.name, suggested_name
)
)
end
end
end
end
44 changes: 43 additions & 1 deletion test/y2network/widgets/vlan_id_test.rb
Expand Up @@ -24,8 +24,50 @@
require "y2network/interface_config_builder"

describe Y2Network::Widgets::VlanID do
let(:builder) { Y2Network::InterfaceConfigBuilder.for("vlan") }
let(:builder) do
Y2Network::InterfaceConfigBuilder.for("vlan").tap do |vlan|
vlan.name = "vlan0"
end
end

subject { described_class.new(builder) }

include_examples "CWM::IntField"

describe "#store" do
let(:value) { 0 }

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

context "when the value is modified since read" do
let(:value) { 20 }

it "suggest the user to modify also the interface name" do
expect(Yast::Popup).to receive(:YesNo).with(/from 'vlan0' to 'vlan20'/)

subject.store
end

context "and the user accepts the suggestion" do
before do
allow(Yast::Popup).to receive(:YesNo).and_return(true)
end

it "modifies the vlan interface name" do
expect { subject.store }.to change { builder.name }.from("vlan0").to("vlan20")
end
end
end

context "when the value is not modified since read" do
it "does nothing" do
expect(Yast::Popup).to_not receive(:YesNo)
expect(builder).to_not receive(:vlan_id=)

subject.store
end
end
end
end

0 comments on commit 52dd9ca

Please sign in to comment.