Commit 8c761a64 authored by Nick Thomas's avatar Nick Thomas

Merge branch 'nicolasdular/broadcast-placeholders-ff' into 'master'

Enable placeholders for broadcast notifications

See merge request gitlab-org/gitlab!27932
parents 963ebeb6 29f8f21a
......@@ -47,7 +47,7 @@ module BroadcastMessagesHelper
end
def render_broadcast_message(broadcast_message)
if Feature.enabled?(:broadcast_message_placeholders)
if broadcast_message.notification?
Banzai.render_field_and_post_process(broadcast_message, :message, {
current_user: current_user,
skip_project_check: true,
......
---
title: Add placeholders to broadcast message notifications
merge_request:
author:
type: added
......@@ -3,12 +3,23 @@
require 'spec_helper'
describe 'Broadcast Messages' do
shared_examples 'a Broadcast Messages' do
let_it_be(:user) { create(:user) }
shared_examples 'a Broadcast Messages' do |type|
it 'shows broadcast message' do
visit root_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 root_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 dismissable Broadcast Messages' do
......@@ -35,11 +46,21 @@ describe 'Broadcast Messages' do
it_behaves_like 'a Broadcast Messages'
it 'shows broadcast message' do
it 'is not dismissable' do
visit root_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}}')
sign_in(user)
visit root_path
expect(page).to have_content 'Hi {{name}}'
end
end
describe 'dismissable banner type' do
......@@ -51,33 +72,20 @@ describe 'Broadcast Messages' do
end
describe 'notification type' do
let!(:broadcast_message) { create(:broadcast_message, broadcast_type: 'notification', message: 'SampleMessage') }
let!(:broadcast_message) { create(:broadcast_message, :notification, message: 'SampleMessage') }
it_behaves_like 'a Broadcast Messages'
it_behaves_like 'a Broadcast Messages', :notification
it_behaves_like 'a dismissable Broadcast Messages'
end
it 'renders broadcast message with placeholders' do
create(:broadcast_message, broadcast_type: 'notification', message: 'Hi {{name}}')
user = create(:user)
sign_in(user)
it 'replaces placeholders' do
create(:broadcast_message, :notification, message: 'Hi {{name}}')
visit root_path
sign_in(user)
expect(page).to have_content "Hi #{user.name}"
end
it 'renders broadcast message with placeholders and styled links' do
create(:broadcast_message, broadcast_type: 'notification', message: "Hi {{name}} <a href='gitlab.com' style='color: purple'>click</a>")
user = create(:user)
sign_in(user)
visit root_path
visit root_path
expected_html = "<p>Hi #{user.name} <a href=\"gitlab.com\" style=\"color: purple\">click</a></p>"
expect(page.body).to include(expected_html)
expect(page).to have_content "Hi #{user.name}"
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment