Skip to content

Commit

Permalink
WIP 7
Browse files Browse the repository at this point in the history
  • Loading branch information
dgdavid committed Feb 21, 2020
1 parent 20c3b48 commit 112fb6a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 23 deletions.
7 changes: 6 additions & 1 deletion src/lib/registration/widgets/item_details.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ def opt
end

def update(content)
self.value = content || placeholder
self.value = content
end

def reset
self.value = placeholder
self.disable
end

private
Expand Down
5 changes: 2 additions & 3 deletions src/lib/registration/widgets/master_detail_selector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ def handle(event)
controller.filter = Yast::UI.QueryWidget(Id(:filter), :Value)

# Reset the details box
item_details_widget.disable
item_details_widget.update(nil)
item_details_widget.reset

# Refresh the list
checkbox_list_widget.update(checkbox_list_items)
Expand All @@ -73,7 +72,7 @@ def handle(event)

item = controller.find_item(id)

# FIXME: this is unexpected, but...
# FIXME: this is not expected, but...
return unless item

# Show details
Expand Down
63 changes: 44 additions & 19 deletions test/registration/widgets/item_details_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,60 @@
describe Registration::Widgets::ItemDetails do
include_examples "CWM::RichText"

describe "#update" do
context "when content is given" do
let(:details) { "Details about an item" }
describe "#init" do
context "if a placeholder has been defined" do
subject { described_class.new(placeholder: placeholder) }
let(:placeholder) { "A text used as a placeholder" }

it "displays the placeholder" do
expect(subject).to receive(:value=).with(placeholder)

subject.init
end
end

it "displays given content" do
expect(subject).to receive(:value=).with("Details about an item")
context "when a placeholder was not defined" do
it "displays nothing" do
expect(subject).to receive(:value=).with("")

subject.update(details)
subject.init
end
end
end

describe "#update" do
let(:content) { "Details about an item" }

it "displays given content" do
expect(subject).to receive(:value=).with("Details about an item")

subject.update(content)
end
end

describe "#reset" do
it "disables itself" do
expect(subject).to receive(:disable)

subject.reset
end

context "when content is not given" do
context "but a placeholder has been defined" do
subject { described_class.new(placeholder: placeholder) }
let(:placeholder) { "A text used as a placeholder" }
context "if a placeholder has been defined" do
subject { described_class.new(placeholder: placeholder) }
let(:placeholder) { "A text used as a placeholder" }

it "displays the placeholder" do
expect(subject).to receive(:value=).with(placeholder)
it "displays the placeholder" do
expect(subject).to receive(:value=).with(placeholder)

subject.update(nil)
end
subject.reset
end
end

context "and a placeholder was not defined" do
it "displays nothing" do
expect(subject).to receive(:value=).with("")
context "when a placeholder was not defined" do
it "displays nothing" do
expect(subject).to receive(:value=).with("")

subject.update(nil)
end
subject.reset
end
end
end
Expand Down

0 comments on commit 112fb6a

Please sign in to comment.