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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
# frozen_string_literal: true
require "spec_helper"
RSpec.describe Pajamas::AlertComponent, :aggregate_failures, type: :component do
context 'slots' do
let_it_be(:body) { 'Alert body' }
let_it_be(:actions) { 'Alert actions' }
before do
render_inline described_class.new do |c|
c.body { body }
c.actions { actions }
end
end
it 'renders alert body' do
expect(page).to have_content(body)
end
it 'renders actions' do
expect(page).to have_content(actions)
end
end
context 'with defaults' do
before do
render_inline described_class.new
end
it 'does not set a title' do
expect(page).not_to have_selector('.gl-alert-title')
expect(page).to have_selector('.gl-alert-icon-no-title')
end
it 'renders the default variant' do
expect(page).to have_selector('.gl-alert-info')
expect(page).to have_selector("[data-testid='information-o-icon']")
expect(page).not_to have_selector('.gl-alert-no-icon')
end
it 'renders a dismiss button' do
expect(page).to have_selector('.gl-dismiss-btn.js-close')
expect(page).to have_selector("[data-testid='close-icon']")
expect(page).not_to have_selector('.gl-alert-not-dismissible')
end
end
describe 'title' do
before do
render_inline described_class.new(title: title)
end
context 'with non-empty string' do
let(:title) { '_title_' }
it 'sets the title' do
expect(page).to have_selector('.gl-alert-title')
expect(page).to have_content(title)
expect(page).not_to have_selector('.gl-alert-icon-no-title')
end
end
context 'with nil, empty or blank string' do
where(:title) { [nil, '', ' '] }
with_them do
it 'does not set a title' do
expect(page).not_to have_selector('.gl-alert-title')
expect(page).to have_selector('.gl-alert-icon-no-title')
end
end
end
end
context 'with custom options' do
context 'with simple options' do
before do
render_inline described_class.new(
alert_options: {
class: '_alert_class_',
data: {
feature_id: '_feature_id_',
dismiss_endpoint: '_dismiss_endpoint_'
}
}
)
end
it 'sets the alert_class' do
expect(page).to have_selector('._alert_class_')
end
it 'sets the alert_data' do
expect(page).to have_selector('[data-feature-id="_feature_id_"][data-dismiss-endpoint="_dismiss_endpoint_"]')
end
end
context 'with dismissible disabled' do
before do
render_inline described_class.new(dismissible: false)
end
it 'has the "not dismissible" class' do
expect(page).to have_selector('.gl-alert-not-dismissible')
end
it 'does not render the dismiss button' do
expect(page).not_to have_selector('.gl-dismiss-btn.js-close')
expect(page).not_to have_selector("[data-testid='close-icon']")
end
end
context 'with the icon hidden' do
before do
render_inline described_class.new(show_icon: false)
end
it 'has the hidden icon class' do
expect(page).to have_selector('.gl-alert-no-icon')
end
it 'does not render the icon' do
expect(page).not_to have_selector('.gl-alert-icon')
expect(page).not_to have_selector("[data-testid='information-o-icon']")
end
end
context 'with dismissible content' do
before do
render_inline described_class.new(
close_button_options: {
class: '_close_button_class_',
data: {
testid: '_close_button_testid_'
}
}
)
end
it 'does not have "not dismissible" class' do
expect(page).not_to have_selector('.gl-alert-not-dismissible')
end
it 'renders a dismiss button and data' do
expect(page).to have_selector('.gl-dismiss-btn.js-close._close_button_class_')
expect(page).to have_selector("[data-testid='close-icon']")
expect(page).to have_selector('[data-testid="_close_button_testid_"]')
end
end
context 'with setting variant type' do
where(:variant) { [:warning, "success", :danger, "tip"] }
before do
render_inline described_class.new(variant: variant)
end
with_them do
it 'renders the variant' do
expect(page).to have_selector(".gl-alert-#{variant}")
expect(page).to have_selector("[data-testid='#{described_class::VARIANT_ICONS[variant.to_sym]}-icon']")
end
end
context "with unknown or nil variant" do
where(:variant) { [:foo, nil] }
with_them do
it "adds the default variant class" do
expect(page).to have_selector(".gl-alert-info")
expect(page).to have_selector("[data-testid='information-o-icon']")
end
end
end
end
end
end
|