debian-mirror-gitlab/spec/features/broadcast_messages_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

92 lines
2.3 KiB
Ruby
Raw Normal View History

2020-03-13 15:44:24 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-06-23 00:09:42 +05:30
RSpec.describe 'Broadcast Messages' do
2020-04-22 19:07:51 +05:30
let_it_be(:user) { create(:user) }
shared_examples 'a Broadcast Messages' do |type|
2020-04-08 14:13:33 +05:30
it 'shows broadcast message' do
visit root_path
2020-03-13 15:44:24 +05:30
2020-04-08 14:13:33 +05:30
expect(page).to have_content 'SampleMessage'
end
2020-04-22 19:07:51 +05:30
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-04-08 14:13:33 +05:30
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
2020-03-13 15:44:24 +05:30
2020-04-08 14:13:33 +05:30
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
2020-03-13 15:44:24 +05:30
end
2020-04-08 14:13:33 +05:30
describe 'banner type' do
let!(:broadcast_message) { create(:broadcast_message, message: 'SampleMessage') }
2020-03-13 15:44:24 +05:30
2020-04-08 14:13:33 +05:30
it_behaves_like 'a Broadcast Messages'
2020-03-13 15:44:24 +05:30
2020-04-22 19:07:51 +05:30
it 'is not dismissable' do
2020-04-08 14:13:33 +05:30
visit root_path
expect(page).not_to have_selector('.js-dismiss-current-broadcast-notification')
end
2020-04-22 19:07:51 +05:30
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-03-13 15:44:24 +05:30
end
2020-04-08 14:13:33 +05:30
describe 'dismissable banner type' do
let!(:broadcast_message) { create(:broadcast_message, dismissable: true, message: 'SampleMessage') }
it_behaves_like 'a Broadcast Messages'
it_behaves_like 'a dismissable Broadcast Messages'
end
describe 'notification type' do
2020-04-22 19:07:51 +05:30
let!(:broadcast_message) { create(:broadcast_message, :notification, message: 'SampleMessage') }
2020-04-08 14:13:33 +05:30
2020-04-22 19:07:51 +05:30
it_behaves_like 'a Broadcast Messages', :notification
2020-04-08 14:13:33 +05:30
it_behaves_like 'a dismissable Broadcast Messages'
2020-04-22 19:07:51 +05:30
it 'replaces placeholders' do
create(:broadcast_message, :notification, message: 'Hi {{name}}')
2020-04-08 14:13:33 +05:30
2020-04-22 19:07:51 +05:30
sign_in(user)
2020-03-13 15:44:24 +05:30
2020-04-22 19:07:51 +05:30
visit root_path
2020-03-13 15:44:24 +05:30
2020-04-22 19:07:51 +05:30
expect(page).to have_content "Hi #{user.name}"
end
2020-03-13 15:44:24 +05:30
end
end