Skip to content

Commit

Permalink
Merge pull request #1031 from yast/improve_multi_status_selector
Browse files Browse the repository at this point in the history
[CWM] Minor improvements for the MultiStatusSelector widget
  • Loading branch information
dgdavid committed Mar 13, 2020
2 parents 3fde5fc + d13886d commit 7c58df8
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 8 deletions.
24 changes: 17 additions & 7 deletions library/cwm/src/lib/cwm/multi_status_selector.rb
Expand Up @@ -121,6 +121,21 @@ def contents
HBox(content)
end

# Updates the content based on items list
def refresh
new_value = items.map do |item|
item_content = item.to_richtext

if Yast::UI.TextMode
"#{item_content}<br>"
else
"<p>#{item_content}</p>"
end
end

content.value = new_value.join
end

# @macro seeAbstractWidget
def handle(event)
if event["ID"].to_s.include?(Item.event_id)
Expand Down Expand Up @@ -173,11 +188,6 @@ def find_item(needle)
items.find { |i| i.id.to_s == needle.to_s }
end

# Updates the content based on items list
def refresh
content.value = items.map(&:to_richtext).join("<br>")
end

# Convenience widget to keep the content updated
#
# @return [ContentArea]
Expand Down Expand Up @@ -210,6 +220,8 @@ def keep_scroll?
class Item
extend Yast::I18n

textdomain "base"

# Map to icons used in GUI to represent all the known statuses in both scenarios, during
# installation (`inst` mode) and in a running system (`normal` mode).
#
Expand Down Expand Up @@ -261,8 +273,6 @@ class Item
LABEL_EVENT_ID = "#{EVENT_ID}label".freeze
private_constant :LABEL_EVENT_ID

textdomain "cwm"

# @!method id
# The item id
# @return [#to_s]
Expand Down
39 changes: 39 additions & 0 deletions library/cwm/test/multi_status_selector_test.rb
Expand Up @@ -62,9 +62,48 @@ def initialize(id, status, enabled)
let(:first_item) { { id: 1, status: :selected, enabled: false } }
let(:second_item) { { id: 2, status: :unselected, enabled: true } }
let(:items) { [first_item, second_item] }
let(:content) { subject.contents.nested_find { |i| i.is_a?(CWM::RichText) } }

include_examples "CWM::CustomWidget"

describe "#refresh" do
before do
allow(Yast::UI).to receive(:TextMode).and_return(text_mode)
end

context "when running in text mode" do
let(:text_mode) { true }

it "includes <br> tags" do
expect(content).to receive(:value=).with(/<br>/)

subject.refresh
end

it "does not include <p> tags" do
expect(content).to_not receive(:value=).with(/<p>/)

subject.refresh
end
end

context "when not running in text mode" do
let(:text_mode) { false }

it "includes <p> tags" do
expect(content).to receive(:value=).with(/<p>/)

subject.refresh
end

it "does not include <br> tags" do
expect(content).to_not receive(:value=).with(/<br>/)

subject.refresh
end
end
end

describe "#init" do
it "renders all items" do
expect(subject.items).to all(receive(:to_richtext))
Expand Down
7 changes: 7 additions & 0 deletions package/yast2.changes
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Fri Mar 13 01:54:58 UTC 2020 - David Diaz <dgonzalez@suse.com>

- CWM::MultiStatusSelector minor improvements (related to
bsc#1157780).
- 4.2.73

-------------------------------------------------------------------
Thu Mar 12 09:14:16 UTC 2020 - David Diaz <dgonzalez@suse.com>

Expand Down
2 changes: 1 addition & 1 deletion package/yast2.spec
Expand Up @@ -17,7 +17,7 @@


Name: yast2
Version: 4.2.72
Version: 4.2.73
Release: 0
Summary: YaST2 Main Package
License: GPL-2.0-only
Expand Down

0 comments on commit 7c58df8

Please sign in to comment.