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 ...@@ -47,7 +47,7 @@ module BroadcastMessagesHelper
end end
def render_broadcast_message(broadcast_message) 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, { Banzai.render_field_and_post_process(broadcast_message, :message, {
current_user: current_user, current_user: current_user,
skip_project_check: true, skip_project_check: true,
......
---
title: Add placeholders to broadcast message notifications
merge_request:
author:
type: added
...@@ -3,12 +3,23 @@ ...@@ -3,12 +3,23 @@
require 'spec_helper' require 'spec_helper'
describe 'Broadcast Messages' do 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 it 'shows broadcast message' do
visit root_path visit root_path
expect(page).to have_content 'SampleMessage' expect(page).to have_content 'SampleMessage'
end 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 end
shared_examples 'a dismissable Broadcast Messages' do shared_examples 'a dismissable Broadcast Messages' do
...@@ -35,11 +46,21 @@ describe 'Broadcast Messages' do ...@@ -35,11 +46,21 @@ describe 'Broadcast Messages' do
it_behaves_like 'a Broadcast Messages' it_behaves_like 'a Broadcast Messages'
it 'shows broadcast message' do it 'is not dismissable' do
visit root_path visit root_path
expect(page).not_to have_selector('.js-dismiss-current-broadcast-notification') expect(page).not_to have_selector('.js-dismiss-current-broadcast-notification')
end 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 end
describe 'dismissable banner type' do describe 'dismissable banner type' do
...@@ -51,33 +72,20 @@ describe 'Broadcast Messages' do ...@@ -51,33 +72,20 @@ describe 'Broadcast Messages' do
end end
describe 'notification type' do 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' it_behaves_like 'a dismissable Broadcast Messages'
end
it 'renders broadcast message with placeholders' do it 'replaces placeholders' do
create(:broadcast_message, broadcast_type: 'notification', message: 'Hi {{name}}') create(:broadcast_message, :notification, message: 'Hi {{name}}')
user = create(:user)
sign_in(user) sign_in(user)
visit root_path visit root_path
expect(page).to have_content "Hi #{user.name}" expect(page).to have_content "Hi #{user.name}"
end 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
expected_html = "<p>Hi #{user.name} <a href=\"gitlab.com\" style=\"color: purple\">click</a></p>"
expect(page.body).to include(expected_html)
end 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