Commit 29f8f21a authored by nicolasdular's avatar nicolasdular

Enable placeholders for broadcast notifications

This removes the feature flag for broadcast placeholders and only
enables placeholders for notifications. This feature flag changes
the logic intentionally. During initial development it came
apparent that placeholders only make sense for notifications, but
this was then not reflected in the final MR.

This MR fixes this, removes the feature flag, adds a test for the
new code path and cleans up the specs.
parent 6ea0c852
...@@ -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
create(:broadcast_message, broadcast_type: 'notification', message: 'Hi {{name}}')
user = create(:user) it 'replaces placeholders' do
sign_in(user) create(:broadcast_message, :notification, message: 'Hi {{name}}')
visit root_path sign_in(user)
expect(page).to have_content "Hi #{user.name}" visit root_path
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).to have_content "Hi #{user.name}"
expect(page.body).to include(expected_html) end
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