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
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Broadcast Messages', feature_category: :onboarding do
include Spec::Support::Helpers::ModalHelpers
let_it_be(:user) { create(:user) }
let(:path) { explore_projects_path }
shared_examples 'a Broadcast Messages' do |type|
it 'shows broadcast message' do
visit path
expect(page).to have_content 'SampleMessage'
end
it 'renders styled links' do
create(:broadcast_message, type, message: "<a href='gitlab.com' style='color: purple'>click me</a>")
visit path
expected_html = "<p><a href=\"gitlab.com\" style=\"color: purple\">click me</a></p>"
expect(page.body).to include(expected_html)
end
end
shared_examples 'a dismissible Broadcast Messages' do
it 'hides broadcast message after dismiss', :js do
visit path
expect_to_be_on_explore_projects_page
find('body.page-initialised .js-dismiss-current-broadcast-notification').click
expect_message_dismissed
end
it 'broadcast message is still hidden after refresh', :js do
visit path
expect_to_be_on_explore_projects_page
find('body.page-initialised .js-dismiss-current-broadcast-notification').click
expect_message_dismissed
visit path
expect_message_dismissed
end
end
describe 'banner type' do
let_it_be(:broadcast_message) { create(:broadcast_message, message: 'SampleMessage') }
it_behaves_like 'a Broadcast Messages'
it 'is not dismissible' do
visit path
expect(page).not_to have_selector('.js-dismiss-current-broadcast-notification')
end
it 'does not replace placeholders' do
create(:broadcast_message, message: 'Hi {{name}}')
gitlab_sign_in(user)
visit path
expect(page).to have_content 'Hi {{name}}'
end
end
describe 'dismissible banner type' do
let_it_be(:broadcast_message) { create(:broadcast_message, dismissable: true, message: 'SampleMessage') }
it_behaves_like 'a Broadcast Messages'
it_behaves_like 'a dismissible Broadcast Messages'
end
describe 'notification type' do
let_it_be(:broadcast_message) { create(:broadcast_message, :notification, message: 'SampleMessage') }
it_behaves_like 'a Broadcast Messages', :notification
it_behaves_like 'a dismissible Broadcast Messages'
it 'replaces placeholders' do
create(:broadcast_message, :notification, message: 'Hi {{name}}')
gitlab_sign_in(user)
visit path
expect(page).to have_content "Hi #{user.name}"
end
end
context 'with GitLab revision changes', :js, :use_clean_rails_redis_caching do
it 'properly shows effects of delete from any revision' do
text = 'my_broadcast_message'
message = create(:broadcast_message, broadcast_type: :banner, message: text)
new_strategy_value = { revision: 'abc123', version: '_version_' }
visit path
expect_broadcast_message(text)
# seed the other cache
original_strategy_value = Gitlab::Cache::JsonCache::STRATEGY_KEY_COMPONENTS
stub_const('Gitlab::Cache::JsonCaches::JsonKeyed::STRATEGY_KEY_COMPONENTS', new_strategy_value)
page.refresh
expect_broadcast_message(text)
# delete on original cache
stub_const('Gitlab::Cache::JsonCaches::JsonKeyed::STRATEGY_KEY_COMPONENTS', original_strategy_value)
admin = create(:admin)
sign_in(admin)
gitlab_enable_admin_mode_sign_in(admin)
visit admin_broadcast_messages_path
page.within('[data-testid="message-row"]', match: :first) do
find("[data-testid='delete-message-#{message.id}']").click
end
accept_gl_confirm(button_text: 'Delete message')
visit path
expect_no_broadcast_message
# other revision of GitLab does gets cache destroyed
stub_const('Gitlab::Cache::JsonCaches::JsonKeyed::STRATEGY_KEY_COMPONENTS', new_strategy_value)
page.refresh
expect_no_broadcast_message
end
end
def expect_broadcast_message(text)
page.within('[data-testid="banner-broadcast-message"]') do
expect(page).to have_content text
end
end
def expect_no_broadcast_message
expect_to_be_on_explore_projects_page
expect(page).not_to have_selector('[data-testid="banner-broadcast-message"]')
end
def expect_to_be_on_explore_projects_page
page.within('[data-testid="explore-projects-title"]') do
expect(page).to have_content 'Explore projects'
end
end
def expect_message_dismissed
expect(page).not_to have_content 'SampleMessage'
end
end
|