Skip to content

Commit

Permalink
Merge 0dfee5c into 3346718
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Sep 2, 2019
2 parents 3346718 + 0dfee5c commit 95bcd0c
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 10 deletions.
10 changes: 3 additions & 7 deletions src/lib/y2network/widgets/interfaces_table.rb
Expand Up @@ -92,16 +92,12 @@ def create_description
result << "<b>(" << _("No hardware information") << ")</b><br>"
else
result << "<b>(" << _("Not connected") << ")</b><br>" if !hwinfo.link
if !hwinfo.mac.empty?
result << "<b>MAC : </b>" << hwinfo.mac << "<br>"
end
if !hwinfo.busid.empty?
result << "<b>BusID : </b>" << hwinfo.busid << "<br>"
end
result << "<b>MAC : </b>" << hwinfo.mac << "<br>" if hwinfo.mac
result << "<b>BusID : </b>" << hwinfo.busid << "<br>" if hwinfo.busid
end
connection = Yast::Lan.yast_config.connections.by_name(value)
if connection
result << _("Device Name: %s") % ifcfg_name
result << _("Device Name: %s") % connection.name
# TODO: start mode description. Ideally in startmode class
# TODO: ip overview
else
Expand Down
96 changes: 93 additions & 3 deletions test/y2network/widgets/interfaces_table_test.rb
Expand Up @@ -25,13 +25,103 @@
Yast.import "Lan"

describe Y2Network::Widgets::InterfacesTable do
subject { described_class.new(double(:"value=" => nil)) }
subject { described_class.new(description) }

let(:description) { double(:value= => nil) }

let(:eth0) { instance_double(Y2Network::Interface, name: "eth0", hardware: hwinfo) }
let(:interfaces) { Y2Network::InterfacesCollection.new([eth0]) }
let(:hwinfo) do
instance_double(Y2Network::Hwinfo, link: link, mac: mac, busid: busid, exists?: exists?, description: "")
end
let(:mac) { "01:23:45:67:89:ab" }
let(:busid) { "0000:04:00.0" }
let(:link) { false }
let(:exists?) { true }
let(:connections) { Y2Network::ConnectionConfigsCollection.new([eth0_conn]) }
let(:eth0_conn) do
Y2Network::ConnectionConfig::Ethernet.new.tap { |c| c.name = "eth0" }
end

before do
allow(Yast::Lan).to receive(:yast_config).and_return(double(interfaces: [], connections: []))
allow(Yast::Lan).to receive(:yast_config).and_return(double(interfaces: interfaces, connections: connections))
allow(Yast::UI).to receive(:QueryWidget).and_return([])
allow(subject).to receive(:create_description).and_return("")
allow(subject).to receive(:value).and_return("eth0")
end

include_examples "CWM::Table"

describe "#handle" do

it "updates the description" do
expect(description).to receive(:value=)
subject.handle
end

it "includes the MAC address in the description" do
expect(description).to receive(:value=).with(/MAC/)
subject.handle
end

context "when there is no MAC address" do
let(:mac) { nil }

it "does not include the MAC in the description" do
expect(description).to receive(:value=) do |text|
expect(text).to_not include("MAC")
end
subject.handle
end
end

it "includes the Bus ID address in the description" do
expect(description).to receive(:value=).with(/BusID/)
subject.handle
end

context "when there is no Bus ID" do
let(:busid) { nil }

it "does not include the Bus ID in the description" do
expect(description).to receive(:value=) do |text|
expect(text).to_not include("BusID")
end
subject.handle
end
end

context "when there is no hardware information" do
let(:exists?) { false }

it "sets the description with 'no hardware information' warning" do
expect(description).to receive(:value=).with(/No hardware information/)
subject.handle
end
end

context "when there is no link" do
let(:link) { false }

it "sets includes a 'Not connected' text" do
expect(description).to receive(:value=).with(/Not connected/)
subject.handle
end
end

context "when the device is configured" do
it "includes its device name in the description" do
expect(description).to receive(:value=).with(/Device Name: eth0/)
subject.handle
end
end

context "when the device is not configured" do
let(:connections) { Y2Network::ConnectionConfigsCollection.new([]) }

it "includes a warning in the description" do
expect(description).to receive(:value=).with(/The device is not configured./)
subject.handle
end
end
end
end

0 comments on commit 95bcd0c

Please sign in to comment.