2019-09-30 08:06:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-12-09 00:34:51 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 05:08:32 -04:00
|
|
|
RSpec.describe BroadcastMessagesHelper do
|
2020-01-28 13:08:35 -05:00
|
|
|
describe 'current_broadcast_notification_message' do
|
|
|
|
subject { helper.current_broadcast_notification_message }
|
|
|
|
|
|
|
|
context 'with available broadcast notification messages' do
|
|
|
|
let!(:broadcast_message_1) { create(:broadcast_message, broadcast_type: 'notification', starts_at: Time.now - 1.day) }
|
|
|
|
let!(:broadcast_message_2) { create(:broadcast_message, broadcast_type: 'notification', starts_at: Time.now) }
|
|
|
|
|
|
|
|
it { is_expected.to eq broadcast_message_2 }
|
|
|
|
|
|
|
|
context 'when last broadcast message is hidden' do
|
|
|
|
before do
|
2020-03-04 19:07:49 -05:00
|
|
|
helper.request.cookies["hide_broadcast_message_#{broadcast_message_2.id}"] = 'true'
|
2020-01-28 13:08:35 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to eq broadcast_message_1 }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without broadcast notification messages' do
|
|
|
|
it { is_expected.to be_nil }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-12-31 16:42:56 -05:00
|
|
|
describe 'broadcast_message' do
|
2020-03-17 20:09:16 -04:00
|
|
|
let_it_be(:user) { create(:user) }
|
2021-04-19 14:09:09 -04:00
|
|
|
|
2020-01-09 19:07:56 -05:00
|
|
|
let(:current_broadcast_message) { BroadcastMessage.new(message: 'Current Message') }
|
|
|
|
|
2020-03-04 19:07:49 -05:00
|
|
|
before do
|
2020-03-17 20:09:16 -04:00
|
|
|
allow(helper).to receive(:current_user).and_return(user)
|
2020-03-04 19:07:49 -05:00
|
|
|
end
|
|
|
|
|
2015-12-31 16:42:56 -05:00
|
|
|
it 'returns nil when no current message' do
|
|
|
|
expect(helper.broadcast_message(nil)).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'includes the current message' do
|
|
|
|
allow(helper).to receive(:broadcast_message_style).and_return(nil)
|
|
|
|
|
2020-01-09 19:07:56 -05:00
|
|
|
expect(helper.broadcast_message(current_broadcast_message)).to include 'Current Message'
|
2015-12-31 16:42:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'includes custom style' do
|
|
|
|
allow(helper).to receive(:broadcast_message_style).and_return('foo')
|
|
|
|
|
2020-01-09 19:07:56 -05:00
|
|
|
expect(helper.broadcast_message(current_broadcast_message)).to include 'style="foo"'
|
2015-12-31 16:42:56 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'broadcast_message_style' do
|
|
|
|
it 'defaults to no style' do
|
|
|
|
broadcast_message = spy
|
2013-12-09 00:34:51 -05:00
|
|
|
|
2015-12-31 16:42:56 -05:00
|
|
|
expect(helper.broadcast_message_style(broadcast_message)).to eq ''
|
2013-12-09 00:34:51 -05:00
|
|
|
end
|
|
|
|
|
2020-01-09 19:07:56 -05:00
|
|
|
it 'allows custom style for banner messages' do
|
|
|
|
broadcast_message = BroadcastMessage.new(color: '#f2dede', font: '#b94a48', broadcast_type: "banner")
|
2013-12-09 00:34:51 -05:00
|
|
|
|
2017-06-21 09:48:12 -04:00
|
|
|
expect(helper.broadcast_message_style(broadcast_message))
|
|
|
|
.to match('background-color: #f2dede; color: #b94a48')
|
2013-12-09 00:34:51 -05:00
|
|
|
end
|
2020-01-09 19:07:56 -05:00
|
|
|
|
|
|
|
it 'does not add style for notification messages' do
|
|
|
|
broadcast_message = BroadcastMessage.new(color: '#f2dede', broadcast_type: "notification")
|
|
|
|
|
|
|
|
expect(helper.broadcast_message_style(broadcast_message)).to eq ''
|
|
|
|
end
|
2013-12-09 00:34:51 -05:00
|
|
|
end
|
2016-01-13 11:46:32 -05:00
|
|
|
|
|
|
|
describe 'broadcast_message_status' do
|
|
|
|
it 'returns Active' do
|
|
|
|
message = build(:broadcast_message)
|
|
|
|
|
|
|
|
expect(helper.broadcast_message_status(message)).to eq 'Active'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns Expired' do
|
|
|
|
message = build(:broadcast_message, :expired)
|
|
|
|
|
|
|
|
expect(helper.broadcast_message_status(message)).to eq 'Expired'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns Pending' do
|
|
|
|
message = build(:broadcast_message, :future)
|
|
|
|
|
|
|
|
expect(helper.broadcast_message_status(message)).to eq 'Pending'
|
|
|
|
end
|
|
|
|
end
|
2013-12-09 00:34:51 -05:00
|
|
|
end
|