summaryrefslogtreecommitdiff
path: root/spec/views/shared/projects/_list.html.haml_spec.rb
blob: b7b4f97f2b66138aab0208c3a7e11e406f67d6c7 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'shared/projects/_list' do
  let(:group) { create(:group) }

  before do
    allow(view).to receive(:projects).and_return(projects)
    allow(view).to receive(:project_list_cache_key).and_return('fake_cache_key')
  end

  context 'with projects' do
    let(:projects) { build_stubbed_list(:project, 1) }

    it 'renders the list of projects' do
      render

      projects.each do |project|
        expect(rendered).to have_content(project.name)
      end
    end

    it "will not show elements a user shouldn't be able to see" do
      allow(view).to receive(:can_show_last_commit_in_list?).and_return(false)
      allow(view).to receive(:able_to_see_merge_requests?).and_return(false)
      allow(view).to receive(:able_to_see_issues?).and_return(false)

      render

      expect(rendered).not_to have_css('a.commit-row-message')
      expect(rendered).not_to have_css('a.issues')
      expect(rendered).not_to have_css('a.merge-requests')
    end
  end

  context 'without projects' do
    let(:projects) { [] }

    context 'when @contributed_projects is set' do
      context 'and is empty' do
        before do
          @contributed_projects = []
        end

        it 'renders a no-content message' do
          render

          expect(rendered).to have_content(s_('UserProfile|This user hasn\'t contributed to any projects'))
        end
      end
    end

    context 'when @starred_projects is set' do
      context 'and is empty' do
        before do
          @starred_projects = []
        end

        it 'renders a no-content message' do
          render

          expect(rendered).to have_content(s_('UserProfile|This user hasn\'t starred any projects'))
        end
      end
    end

    context 'and without a special instance variable' do
      context 'for an explore_page' do
        before do
          allow(view).to receive(:explore_page).and_return(true)
        end

        it 'renders a no-content message' do
          render

          expect(rendered).to have_content(s_('UserProfile|Explore public groups to find projects to contribute to.'))
        end
      end

      context 'for a non-explore page' do
        it 'renders a no-content message' do
          render

          expect(rendered).to have_content(s_('UserProfile|There are no projects available to be displayed here.'))
        end
      end
    end
  end
end