Skip to content

Commit

Permalink
Merge pull request #1153 from yast/minor-ui-fixes
Browse files Browse the repository at this point in the history
Fix minor usability issues
  • Loading branch information
imobachgs committed Jan 26, 2021
2 parents 981dda1 + 562e9b4 commit 12e4859
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 3 deletions.
9 changes: 9 additions & 0 deletions package/yast2-network.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
-------------------------------------------------------------------
Tue Jan 26 11:23:33 UTC 2021 - Imobach Gonzalez Sosa <igonzalezsosa@suse.com>

- Fixes some usability issues (bsc#1177834):
- Disable "Edit" and "Delete" buttons when no interfaces
are detected.
- Disable the "Scan Network" button when the interface does not
exist.

-------------------------------------------------------------------
Fri Jan 22 17:03:54 UTC 2021 - Knut Anderssen <kanderssen@suse.com>

Expand Down
5 changes: 5 additions & 0 deletions src/lib/y2network/widgets/delete_interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ def label
Yast::Label.DeleteButton
end

# @see CWM::AbstractWidget#init
def init
disable unless @table.value
end

def handle
config = Yast::Lan.yast_config
connection_config = config.connections.by_name(@table.value)
Expand Down
5 changes: 5 additions & 0 deletions src/lib/y2network/widgets/edit_interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ def initialize(table)
@table = table
end

# @see CWM::AbstractWidget#init
def init
disable unless @table.value
end

def label
Yast::Label.EditButton
end
Expand Down
4 changes: 4 additions & 0 deletions src/lib/y2network/widgets/wireless_essid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ def label
_("Scan Network")
end

def init
disable if @settings.newly_added?
end

def handle
return unless scan_supported?

Expand Down
26 changes: 23 additions & 3 deletions test/y2network/widgets/delete_interface_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
Yast.import "Lan"

describe Y2Network::Widgets::DeleteInterface do
subject { described_class.new(double(value: interface_to_delete)) }
subject { described_class.new(table) }

let(:table) { double("table", value: selected) }
let(:selected) { "eth0" }
let(:eth0) { Y2Network::Interface.new("eth0") }
let(:br0) { Y2Network::VirtualInterface.new("br0", type: Y2Network::InterfaceType::BRIDGE) }
let(:interfaces) { Y2Network::InterfacesCollection.new([eth0, br0]) }
Expand All @@ -49,19 +51,37 @@
Y2Network::Config.new(interfaces: interfaces, connections: connections, source: :testing)
end

let(:interface_to_delete) { "eth0" }
let(:selected) { "eth0" }

before do
allow(Yast::Lan).to receive(:yast_config).and_return(config)
end

include_examples "CWM::PushButton"

describe "#init" do
context "when an element is selected" do
it "does not disable the widget" do
expect(subject).to_not receive(:disable)
subject.init
end
end

context "when no element is selected" do
let(:selected) { nil }

it "disables the widget" do
expect(subject).to receive(:disable)
subject.init
end
end
end

describe "#handle" do
context "interface does not have connection config" do
let(:eth1) { Y2Network::Interface.new("eth1") }
let(:interfaces) { Y2Network::InterfacesCollection.new([eth0, br0, eth1]) }
let(:interface_to_delete) { "eth1" }
let(:selected) { "eth1" }

it "do nothing" do
expect(config).to_not receive(:delete_interface)
Expand Down
18 changes: 18 additions & 0 deletions test/y2network/widgets/edit_interface_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,24 @@

include_examples "CWM::PushButton"

describe "#init" do
context "when an element is selected" do
it "does not disable the widget" do
expect(subject).to_not receive(:disable)
subject.init
end
end

context "when no element is selected" do
let(:selected) { nil }

it "disables the widget" do
expect(subject).to receive(:disable)
subject.init
end
end
end

describe "#handle" do
it "runs the interface edition sequence" do
expect(sequence).to receive(:edit) do |builder|
Expand Down
24 changes: 24 additions & 0 deletions test/y2network/widgets/wireless_essid_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,30 @@
allow(essid).to receive(:update_essid_list)
end

describe "#init" do
before do
allow(builder).to receive(:newly_added?).and_return(newly_added?)
end

context "when the interface exists" do
let(:newly_added?) { false }

it "does not disable the button" do
expect(subject).to_not receive(:disable)
subject.init
end
end

context "when the interface does not exist" do
let(:newly_added?) { true }

it "disables the button" do
expect(subject).to receive(:disable)
subject.init
end
end
end

describe "#handle" do
context "when the package for scanning wireless networks is not installed" do
let(:installed) { false }
Expand Down

0 comments on commit 12e4859

Please sign in to comment.