diff --git a/src/lib/registration/controllers/addons_selection.rb b/src/lib/registration/controllers/addons_selection.rb index 39db91a55..91db2ab55 100644 --- a/src/lib/registration/controllers/addons_selection.rb +++ b/src/lib/registration/controllers/addons_selection.rb @@ -35,7 +35,7 @@ class << self end # A checkbox item representation, see {Widgets::CheckboxItem} - Item = Struct.new(:id, :label, :status, :description) + Item = Struct.new(:id, :label, :status, :description, :enabled) # Constructor # @@ -199,9 +199,11 @@ def supported_addon_count? def item_for(addon) Item.new( item_id_for(addon), - addon.label, + item_label_for(addon), addon.status, - "
#{item}
" unless Yast::UI.TextMode item end diff --git a/test/registration/controllers/addons_selection_test.rb b/test/registration/controllers/addons_selection_test.rb index 9b233657b..0af428973 100644 --- a/test/registration/controllers/addons_selection_test.rb +++ b/test/registration/controllers/addons_selection_test.rb @@ -128,6 +128,55 @@ end end + describe "#item_for" do + let(:addon) { Registration::Addon.new(addon_generator) } + let(:item) { subject.send(:item_for, addon) } + + before do + allow(addon).to receive(:available?).and_return(available) + allow(addon).to receive(:selected?).and_return(selected) + allow(addon).to receive(:auto_selected?).and_return(auto_selected) + end + + let(:available) { false } + let(:selected) { false } + let(:auto_selected) { false } + + context "when an available addon is given" do + let(:available) { true } + + it "returns an enabled item" do + expect(item.enabled).to eq(true) + end + end + + context "when a not available addon is given" do + it "returns a not enabled item" do + expect(item.enabled).to eq(false) + end + + it "includes the 'not available' suffix in the label" do + expect(item.label).to match(/not available/) + end + + context "but it is selected" do + let(:selected) { true } + + it "returns an enabled item" do + expect(item.enabled).to eq(true) + end + end + + context "but it is auto-selected" do + let(:auto_selected) { true } + + it "returns an enabled item" do + expect(item.enabled).to eq(true) + end + end + end + end + describe "#find_item" do let(:item) { subject.items.first } diff --git a/test/registration/widgets/checkbox_item_test.rb b/test/registration/widgets/checkbox_item_test.rb index 12e932157..30b0e3025 100644 --- a/test/registration/widgets/checkbox_item_test.rb +++ b/test/registration/widgets/checkbox_item_test.rb @@ -22,34 +22,58 @@ require "registration/widgets/checkbox_item" describe Registration::Widgets::CheckboxItem do - subject { described_class.new(item.id, item.label, item.status) } + subject { described_class.new(item.id, item.label, item.status, item.enabled) } let(:item) do double( "Item", - id: "whatever", - label: "Text uses as label", - status: status + id: "whatever", + label: "Text uses as label", + status: status, + enabled: enabled ) end let(:status) { :selected } + let(:enabled) { true } describe "#to_s" do it "returns a string" do expect(subject.to_s).to be_a(String) end - it "includes a link for the input" do - expect(subject.to_s).to match(/.*href="whatever#checkbox#input".*/) - end + context "when the item is enabled" do + it "includes a link for the input" do + expect(subject.to_s).to match(/.*href="whatever#checkbox#input".*/) + end + + it "includes a link for the label" do + expect(subject.to_s).to match(/.*href="whatever#checkbox#label".*/) + end - it "includes a link for the label" do - expect(subject.to_s).to match(/.*href="whatever#checkbox#label".*/) + it "includes the item label" do + expect(subject.to_s).to include(item.label) + end end - it "includes the item label" do - expect(subject.to_s).to include(item.label) + context "when the item is not enabled" do + let(:enabled) { false } + + it "uses a grey color" do + expect(subject.to_s).to match(/.*color: grey.*/) + end + + it "includes the item label" do + expect(subject.to_s).to include(item.label) + end + + it "does not include a link for the input" do + expect(subject.to_s).to_not match(/.*href="whatever#checkbox#input".*/) + end + + it "does not include a link for the label" do + expect(subject.to_s).to_not match(/.*href="whatever#checkbox#label".*/) + end end context "when running in text mode" do diff --git a/test/registration/widgets/master_detail_selector_test.rb b/test/registration/widgets/master_detail_selector_test.rb index 4f583e448..c15a7cda6 100644 --- a/test/registration/widgets/master_detail_selector_test.rb +++ b/test/registration/widgets/master_detail_selector_test.rb @@ -40,7 +40,13 @@ end let(:item) do - double(id: 1, label: "Fake item", status: :whatever, description: "Fake addon item") + double( + id: 1, + label: "Fake item", + status: :whatever, + description: "Fake addon item", + enabled: true + ) end let(:include_filter) { true }