BigW Consortium Gitlab

broadcast_messages_helper_spec.rb 1.62 KB
Newer Older
1 2 3
require 'spec_helper'

describe BroadcastMessagesHelper do
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
  describe 'broadcast_message' do
    it 'returns nil when no current message' do
      expect(helper.broadcast_message(nil)).to be_nil
    end

    it 'includes the current message' do
      current = double(message: 'Current Message')

      allow(helper).to receive(:broadcast_message_style).and_return(nil)

      expect(helper.broadcast_message(current)).to include 'Current Message'
    end

    it 'includes custom style' do
      current = double(message: 'Current Message')

      allow(helper).to receive(:broadcast_message_style).and_return('foo')

      expect(helper.broadcast_message(current)).to include 'style="foo"'
    end
  end

  describe 'broadcast_message_style' do
    it 'defaults to no style' do
      broadcast_message = spy
29

30
      expect(helper.broadcast_message_style(broadcast_message)).to eq ''
31 32
    end

33 34
    it 'allows custom style' do
      broadcast_message = double(color: '#f2dede', font: '#b94a48')
35

36 37
      expect(helper.broadcast_message_style(broadcast_message)).
        to match('background-color: #f2dede; color: #b94a48')
38 39
    end
  end
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59

  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
60
end