summaryrefslogtreecommitdiff
path: root/spec/views/shared/_label_row.html.haml_spec.rb
blob: 6fe74b6633bf97ce9b5f8077b50cfae6f3d960a3 (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# frozen_string_literal: true
require 'spec_helper'

RSpec.describe 'shared/_label_row.html.haml' do
  let_it_be(:group) { create(:group) }

  let(:label) { build_stubbed(:group_label, group: group).present(issuable_subject: group) }

  before do
    allow(view).to receive(:label) { label }
  end

  context 'with a project context' do
    let_it_be(:project) { create(:project, group: group) }

    let(:label) { build_stubbed(:label, project: project).present(issuable_subject: project) }

    before do
      assign(:project, label.project)

      render
    end

    it 'has label title' do
      expect(rendered).to have_text(label.title)
    end

    it 'has a non-linked label title' do
      expect(rendered).not_to have_link(label.title)
    end

    it 'has Issues link' do
      expect(rendered).to have_link('Issues')
    end

    it 'has Merge request link' do
      expect(rendered).to have_link('Merge requests')
    end

    it 'shows the path from where the label was created' do
      expect(rendered).to have_css('.label-badge', text: project.full_name)
    end
  end

  context 'with a subgroup context' do
    let_it_be(:subgroup) { create(:group, parent: group) }

    let(:label) { build_stubbed(:group_label, group: subgroup).present(issuable_subject: subgroup) }

    before do
      assign(:group, label.group)

      render
    end

    it 'has label title' do
      expect(rendered).to have_text(label.title)
    end

    it 'has a non-linked label title' do
      expect(rendered).not_to have_link(label.title)
    end

    it 'has Issues link' do
      expect(rendered).to have_link('Issues')
    end

    it 'has Merge request link' do
      expect(rendered).to have_link('Merge requests')
    end

    it 'shows the path from where the label was created' do
      expect(rendered).to have_css('.label-badge', text: subgroup.full_name)
    end
  end

  context 'with a group context' do
    before do
      assign(:group, label.group)

      render
    end

    it 'has label title' do
      expect(rendered).to have_text(label.title)
    end

    it 'has a non-linked label title' do
      expect(rendered).not_to have_link(label.title)
    end

    it 'has Issues link' do
      expect(rendered).to have_link('Issues')
    end

    it 'has Merge request link' do
      expect(rendered).to have_link('Merge requests')
    end

    it 'does not show a path from where the label was created' do
      expect(rendered).not_to have_css('.label-badge')
    end
  end

  context 'with an admin context' do
    before do
      render
    end

    it 'has label title' do
      expect(rendered).to have_text(label.title)
    end

    it 'has a non-linked label title' do
      expect(rendered).not_to have_link(label.title)
    end

    it 'does not show Issues link' do
      expect(rendered).not_to have_link('Issues')
    end

    it 'does not show Merge request link' do
      expect(rendered).not_to have_link('Merge requests')
    end

    it 'does not show a path from where the label was created' do
      expect(rendered).not_to have_css('.label-badge')
    end
  end
end