Skip to content

Commit

Permalink
Add a ServiceWidget#refresh method
Browse files Browse the repository at this point in the history
Useful to refresh the widget in certain scenarios, i.e. when the "Apply
changes" action is performed.#
  • Loading branch information
dgdavid committed Jul 31, 2018
1 parent 53e05f3 commit d3370cb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions library/cwm/src/lib/cwm/service_widget.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ def contents
@service_widget.content
end

def refresh
@service_widget.refresh
end

def handle(event)
log.info "handling event #{event.inspect}"
return unless event
Expand Down
6 changes: 6 additions & 0 deletions library/systemd/src/lib/yast2/service_widget.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ def content
)
end

def refresh
Yast::UI.ChangeWidget(Id(:service_widget_status), :Value, status)
Yast::UI.ChangeWidget(Id(:service_widget_action), :Items, action_items)
Yast::UI.ChangeWidget(Id(:service_widget_autostart), :Items, autostart_items)
end

# handles event to dynamically react on user configuration.
# For events that does not happen inside widget it is ignored.
# @param event_id [Object] id of UI element that cause event
Expand Down
24 changes: 24 additions & 0 deletions library/systemd/test/yast2/service_widget_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,30 @@
end
end

describe "#refresh" do
before do
allow(Yast::UI).to receive(:ChangeWidget).with(any_args)
end

it "updates the status" do
expect(Yast::UI).to receive(:ChangeWidget).with(Id(:service_widget_status), :Value, anything)

subject.refresh
end

it "updates available actions" do
expect(Yast::UI).to receive(:ChangeWidget).with(Id(:service_widget_action), :Items, anything)

subject.refresh
end

it "updates available options for start mode" do
expect(Yast::UI).to receive(:ChangeWidget).with(Id(:service_widget_autostart), :Items, anything)

subject.refresh
end
end

describe "#store" do
before do
allow(Yast::UI).to receive(:QueryWidget)
Expand Down

0 comments on commit d3370cb

Please sign in to comment.