summaryrefslogtreecommitdiff
path: root/spec/views/shared/_global_alert.html.haml_spec.rb
blob: 7eec068645a7cc86f958aa2c5c86791bdaa38203 (plain)
1
2
3
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# frozen_string_literal: true
require 'spec_helper'

RSpec.describe 'shared/_global_alert.html.haml' do
  before do
    allow(view).to receive(:sprite_icon).and_return('<span class="icon"></span>'.html_safe)
  end

  it 'renders the title' do
    title = "The alert's title"
    render partial: 'shared/global_alert', locals: { title: title }

    expect(rendered).to have_text(title)
  end

  context 'variants' do
    it 'renders an info alert by default' do
      render

      expect(rendered).to have_selector(".gl-alert-info")
    end

    %w[warning success danger tip].each do |variant|
      it "renders a #{variant} variant" do
        allow(view).to receive(:variant).and_return(variant)
        render partial: 'shared/global_alert', locals: { variant: variant }

        expect(rendered).to have_selector(".gl-alert-#{variant}")
      end
    end
  end

  context 'dismissible option' do
    it 'shows the dismiss button by default' do
      render

      expect(rendered).to have_selector('.gl-dismiss-btn')
    end

    it 'does not show the dismiss button when dismissible is false' do
      render partial: 'shared/global_alert', locals: { dismissible: false }

      expect(rendered).not_to have_selector('.gl-dismiss-btn')
    end
  end

  context 'fixed layout' do
    before do
      allow(view).to receive(:fluid_layout).and_return(false)
    end

    it 'does not add layout limited class' do
      render

      expect(rendered).not_to have_selector('.gl-alert-layout-limited')
    end

    it 'adds container classes' do
      render

      expect(rendered).to have_selector('.container-fluid.container-limited')
    end

    it 'does not add container classes if is_contained is true' do
      render partial: 'shared/global_alert', locals: { is_contained: true }

      expect(rendered).not_to have_selector('.container-fluid.container-limited')
    end
  end

  context 'fluid layout' do
    before do
      allow(view).to receive(:fluid_layout).and_return(true)
      render
    end

    it 'adds layout limited class' do
      expect(rendered).to have_selector('.gl-alert-layout-limited')
    end

    it 'does not add container classes' do
      expect(rendered).not_to have_selector('.container-fluid.container-limited')
    end
  end
end