-
Notifications
You must be signed in to change notification settings - Fork 19
/
checkbox_item_test.rb
151 lines (119 loc) · 4.1 KB
/
checkbox_item_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# Copyright (c) [2020] SUSE LLC
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.
require_relative "../../spec_helper"
require "registration/widgets/checkbox_item"
describe Registration::Widgets::CheckboxItem do
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,
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
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 the item label" do
expect(subject.to_s).to include(item.label)
end
end
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
before { allow(Yast::UI).to receive(:TextMode).and_return(true) }
context "and the item is selected" do
let(:status) { :selected }
it "displays `[x]` as icon" do
expect(subject.to_s).to include("[x]")
end
end
context "and the item is auto registered" do
let(:status) { :registered }
it "displays `[x]` as icon" do
expect(subject.to_s).to include("[x]")
end
end
context "and the item is auto selected" do
let(:status) { :auto_selected }
it "displays `[a]` as icon" do
expect(subject.to_s).to include("[a]")
end
end
context "and the item is not selected or registered yet" do
let(:status) { :unknown }
it "displays `[ ]` as icon" do
expect(subject.to_s).to include("[ ]")
end
end
end
context "when NOT running in text mode" do
before { allow(Yast::UI).to receive(:TextMode).and_return(false) }
context "and the item is selected" do
let(:status) { :selected }
it "displays the proper icon" do
expect(subject.to_s).to include("checkbox-on.svg")
end
end
context "and the item is auto registered" do
let(:status) { :registered }
it "displays the proper icon" do
expect(subject.to_s).to include("checkbox-on.svg")
end
end
context "and the item is auto selected" do
let(:status) { :auto_selected }
it "displays the proper icon" do
expect(subject.to_s).to include("auto-selected.svg")
end
end
context "and the item is not selected or registered yet" do
let(:status) { :unknown }
it "displays the proper icon" do
expect(subject.to_s).to include("checkbox-off.svg")
end
end
end
end
end