Skip to content

Commit

Permalink
Add the given value to the items list when a ComboBox is editable
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Sep 25, 2020
1 parent 460af45 commit c264622
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
8 changes: 8 additions & 0 deletions library/cwm/src/lib/cwm/common_widgets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,14 @@ class ComboBox < AbstractWidget
include ValueBasedWidget
include ItemsSelection
abstract_method :label

alias_method :orig_value=, :value=
def value=(val)
if opt.include?(:editable) && !items.map(&:first).include?(val)
change_items([[val, val]] + items)
end
self.orig_value = val
end
end

# Widget representing selection box to select value.
Expand Down
27 changes: 27 additions & 0 deletions library/cwm/test/common_widgets_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,30 @@ def hspacing
end
end
end

describe CWM::ComboBox do
class MountPointSelector < CWM::ComboBox
def label
""
end

def opt
[:editable]
end

def items
[["/", "/ (root)"]]
end
end

subject { MountPointSelector.new }

describe "#value=" do
describe "when the widget is editable" do
it "adds the given value to the list of items" do
expect(subject).to receive(:change_items).with([["/srv", "/srv"], ["/", "/ (root)"]])
subject.value = "/srv"
end
end
end
end

0 comments on commit c264622

Please sign in to comment.