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, - "

#{addon.friendly_name}

#{addon.description}" + "

#{addon.friendly_name}

#{addon.description}", + # the item will be enabled if the addon is selected, auto-selected or available + addon.selected? || addon.auto_selected? || addon.available? ) end @@ -244,6 +246,17 @@ def item_id_for(addon) "#{addon.identifier}-#{addon.version}-#{addon.arch}" end + # Build the Item label based on the addon availability + # + # @return [String] the addon label with the "not available" suffix when proceed + def item_label_for(addon) + if addon.available? + addon.label + else + _("%s (not available)") % addon.label + end + end + # Pre-selects recommended addons if there is none selected/registered yet def preselect_recommended if Addon.selected.empty? && Addon.registered.empty? diff --git a/src/lib/registration/widgets/checkbox_item.rb b/src/lib/registration/widgets/checkbox_item.rb index ec90ca274..2f9bcf67e 100644 --- a/src/lib/registration/widgets/checkbox_item.rb +++ b/src/lib/registration/widgets/checkbox_item.rb @@ -23,8 +23,6 @@ module Registration module Widgets # A plain Ruby object in charge to build an item "checkbox" representation to be used by # {MasterDetailSelector} widget in a RichText widget. - # - # FIXME: give support for disabled items; see #icon class CheckboxItem extend Yast::I18n @@ -41,8 +39,8 @@ class CheckboxItem IMAGES = { "inst:[a]:enabled" => "auto-selected.svg", "inst:[x]:enabled" => "inst_checkbox-on.svg", + "inst:[x]:disabled" => "inst_checkbox-on-disabled.svg", "inst:[ ]:enabled" => "inst_checkbox-off.svg", - "inst:[x]disabled" => "inst_checkbox-on-disabled.svg", "inst:[ ]:disabled" => "inst_checkbox-off-disabled.svg", "normal:[a]:enabled" => "auto-selected.svg", "normal:[x]:enabled" => "checkbox-on.svg", @@ -93,10 +91,12 @@ def self.icon_for(status) # @param id [String, Integer] the representing the item # @param text [String] the text to be displayed # @param status [String, Symbol] the item status - def initialize(id, text, status) + # @param enabled [Boolean] if the item should be enabled or not + def initialize(id, text, status, enabled = true) @id = id @text = text @status = status + @enabled = enabled end # Returns the checkbox representation for the item @@ -116,7 +116,7 @@ def icon value else # an image key looks like "inst:[a]:enabled" - image_key = [mode, value, "enabled"].join(":") + image_key = [mode, value, state].join(":") "" end @@ -124,20 +124,28 @@ def icon private - attr_reader :id, :text, :status + attr_reader :id, :text, :status, :enabled # Builds the checkbox input representation # # @return [String] def checkbox - "#{icon}" + if enabled + "#{icon}" + else + "#{icon}" + end end # Builds the checkbox label representation # # @return [String] def label - "#{text}" + if enabled + "#{text}" + else + "#{text}" + end end # Returns the status string representation @@ -156,13 +164,6 @@ def value end end - # Returns style rules for the text - # - # @return [String] the status text representation - def text_style - "text-decoration: none; color: #{color}" - end - # Returns the current mode # # @return [String] "normal" in a running system; "inst" during the installation @@ -170,11 +171,30 @@ def mode installation? ? "inst" : "normal" end + # Returns the current input state + # + # @return [String] "enabled" when item must be enabled; "disabled" otherwise + def state + enabled ? "enabled" : "disabled" + end + + # Returns style rules for the text + # + # @return [String] the status text representation + def text_style + "text-decoration: none; color: #{color}" + end + # Determines the color for the text # - # @return [String] "black" in a running system; "white" during the isntallation + # @return [String] "grey" for a disabled item; + # "white" when enabled and running in installation mode; + # "black" otherwise def color - installation? ? "white" : "black" + return "grey" unless enabled + return "white" if installation? + + "black" end # Determines whether running in installation mode diff --git a/src/lib/registration/widgets/master_detail_selector.rb b/src/lib/registration/widgets/master_detail_selector.rb index eefe84533..b02803edc 100644 --- a/src/lib/registration/widgets/master_detail_selector.rb +++ b/src/lib/registration/widgets/master_detail_selector.rb @@ -164,7 +164,7 @@ def checkbox_list_items separator = Yast::UI.TextMode ? "
" : "" checkboxes = controller.items.map do |item| - item = CheckboxItem.new(item.id, item.label, item.status) + item = CheckboxItem.new(item.id, item.label, item.status, item.enabled) item = "

#{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 }