summaryrefslogtreecommitdiff
path: root/spec/features/projects/wiki/user_views_wiki_empty_spec.rb
blob: 0af40a2d760cec188993890d096b28761f458527 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'User views empty wiki' do
  let(:user) { create(:user) }
  let(:confluence_link) { 'Enable the Confluence Wiki integration' }
  let(:element) { page.find('.row.empty-state') }

  shared_examples 'empty wiki and accessible issues' do
    it 'show "issue tracker" message' do
      visit(project_wikis_path(project))

      expect(element).to have_content('This project has no wiki pages')
      expect(element).to have_content('You must be a project member')
      expect(element).to have_content('improve the wiki for this project')
      expect(element).to have_link("issue tracker", href: project_issues_path(project))
      expect(element).to have_link("Suggest wiki improvement", href: new_project_issue_path(project))
      expect(element).to have_no_link(confluence_link)
    end
  end

  shared_examples 'empty wiki and non-accessible issues' do
    it 'does not show "issue tracker" message' do
      visit(project_wikis_path(project))

      expect(element).to have_content('This project has no wiki pages')
      expect(element).to have_content('You must be a project member')
      expect(element).to have_no_link('Suggest wiki improvement')
      expect(element).to have_no_link(confluence_link)
    end
  end

  context 'when user is logged out and issue tracker is public' do
    let(:project) { create(:project, :public, :wiki_repo) }

    it_behaves_like 'empty wiki and accessible issues'
  end

  context 'when user is logged in and not a member' do
    let(:project) { create(:project, :public, :wiki_repo) }

    before do
      sign_in(user)
    end

    it_behaves_like 'empty wiki and accessible issues'
  end

  context 'when issue tracker is private' do
    let(:project) { create(:project, :public, :wiki_repo, :issues_private) }

    it_behaves_like 'empty wiki and non-accessible issues'
  end

  context 'when issue tracker is disabled' do
    let(:project) { create(:project, :public, :wiki_repo, :issues_disabled) }

    it_behaves_like 'empty wiki and non-accessible issues'
  end

  context 'when user is logged in and a member' do
    let(:project) { create(:project, :public) }

    before do
      sign_in(user)
      project.add_developer(user)
    end

    it 'shows "create first page" message' do
      visit(project_wikis_path(project))

      expect(element).to have_content('your project', count: 2)

      element.click_link 'Create your first page'

      expect(page).to have_button('Create page')
    end

    it 'does not show the "enable confluence" button' do
      visit(project_wikis_path(project))

      expect(element).to have_no_link(confluence_link)
    end
  end

  context 'when user is logged in and an admin' do
    let(:project) { create(:project, :public, :wiki_repo) }

    before do
      sign_in(user)
      project.add_maintainer(user)
    end

    it 'shows the "enable confluence" button' do
      visit(project_wikis_path(project))

      expect(element).to have_link(confluence_link)
    end

    it 'does not show "enable confluence" button if confluence is already enabled' do
      create(:confluence_service, project: project)

      visit(project_wikis_path(project))

      expect(element).to have_no_link(confluence_link)
    end
  end
end