2020-01-28 13:08:35 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-16 14:09:01 -04:00
|
|
|
RSpec.describe 'Broadcast Messages' do
|
2020-03-25 17:08:06 -04:00
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
|
|
|
|
shared_examples 'a Broadcast Messages' do |type|
|
2020-03-04 19:07:49 -05:00
|
|
|
it 'shows broadcast message' do
|
|
|
|
visit root_path
|
2020-01-28 13:08:35 -05:00
|
|
|
|
2020-03-04 19:07:49 -05:00
|
|
|
expect(page).to have_content 'SampleMessage'
|
|
|
|
end
|
2020-03-25 17:08:06 -04:00
|
|
|
|
|
|
|
it 'renders styled links' do
|
|
|
|
create(:broadcast_message, type, message: "<a href='gitlab.com' style='color: purple'>click me</a>")
|
|
|
|
|
|
|
|
visit root_path
|
|
|
|
|
|
|
|
expected_html = "<p><a href=\"gitlab.com\" style=\"color: purple\">click me</a></p>"
|
|
|
|
expect(page.body).to include(expected_html)
|
|
|
|
end
|
2020-03-04 19:07:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'a dismissable Broadcast Messages' do
|
|
|
|
it 'hides broadcast message after dismiss', :js do
|
|
|
|
visit root_path
|
|
|
|
|
|
|
|
find('.js-dismiss-current-broadcast-notification').click
|
|
|
|
|
|
|
|
expect(page).not_to have_content 'SampleMessage'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'broadcast message is still hidden after refresh', :js do
|
|
|
|
visit root_path
|
|
|
|
|
|
|
|
find('.js-dismiss-current-broadcast-notification').click
|
|
|
|
visit root_path
|
|
|
|
|
|
|
|
expect(page).not_to have_content 'SampleMessage'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'banner type' do
|
|
|
|
let!(:broadcast_message) { create(:broadcast_message, message: 'SampleMessage') }
|
|
|
|
|
|
|
|
it_behaves_like 'a Broadcast Messages'
|
|
|
|
|
2020-03-25 17:08:06 -04:00
|
|
|
it 'is not dismissable' do
|
2020-03-04 19:07:49 -05:00
|
|
|
visit root_path
|
2020-01-28 13:08:35 -05:00
|
|
|
|
2020-03-04 19:07:49 -05:00
|
|
|
expect(page).not_to have_selector('.js-dismiss-current-broadcast-notification')
|
|
|
|
end
|
2020-03-25 17:08:06 -04:00
|
|
|
|
|
|
|
it 'does not replace placeholders' do
|
|
|
|
create(:broadcast_message, message: 'Hi {{name}}')
|
|
|
|
|
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
visit root_path
|
|
|
|
|
|
|
|
expect(page).to have_content 'Hi {{name}}'
|
|
|
|
end
|
2020-01-28 13:08:35 -05:00
|
|
|
end
|
|
|
|
|
2020-03-04 19:07:49 -05:00
|
|
|
describe 'dismissable banner type' do
|
|
|
|
let!(:broadcast_message) { create(:broadcast_message, dismissable: true, message: 'SampleMessage') }
|
2020-01-28 13:08:35 -05:00
|
|
|
|
2020-03-04 19:07:49 -05:00
|
|
|
it_behaves_like 'a Broadcast Messages'
|
2020-01-28 13:08:35 -05:00
|
|
|
|
2020-03-04 19:07:49 -05:00
|
|
|
it_behaves_like 'a dismissable Broadcast Messages'
|
2020-01-28 13:08:35 -05:00
|
|
|
end
|
|
|
|
|
2020-03-04 19:07:49 -05:00
|
|
|
describe 'notification type' do
|
2020-03-25 17:08:06 -04:00
|
|
|
let!(:broadcast_message) { create(:broadcast_message, :notification, message: 'SampleMessage') }
|
2020-01-28 13:08:35 -05:00
|
|
|
|
2020-03-25 17:08:06 -04:00
|
|
|
it_behaves_like 'a Broadcast Messages', :notification
|
2020-01-28 13:08:35 -05:00
|
|
|
|
2020-03-04 19:07:49 -05:00
|
|
|
it_behaves_like 'a dismissable Broadcast Messages'
|
2020-03-17 20:09:16 -04:00
|
|
|
|
2020-03-25 17:08:06 -04:00
|
|
|
it 'replaces placeholders' do
|
|
|
|
create(:broadcast_message, :notification, message: 'Hi {{name}}')
|
2020-03-17 20:09:16 -04:00
|
|
|
|
2020-03-25 17:08:06 -04:00
|
|
|
sign_in(user)
|
2020-03-17 20:09:16 -04:00
|
|
|
|
2020-03-25 17:08:06 -04:00
|
|
|
visit root_path
|
2020-03-24 11:08:44 -04:00
|
|
|
|
2020-03-25 17:08:06 -04:00
|
|
|
expect(page).to have_content "Hi #{user.name}"
|
|
|
|
end
|
2020-03-24 11:08:44 -04:00
|
|
|
end
|
2020-01-28 13:08:35 -05:00
|
|
|
end
|