user_views_wiki_page_spec.rb 4.64 KB
Newer Older
1 2
require 'spec_helper'

3 4 5 6 7 8 9 10 11
describe 'User views a wiki page' do
  shared_examples 'wiki page user view' do
    let(:user) { create(:user) }
    let(:project) { create(:project, namespace: user.namespace) }
    let(:wiki_page) do
      create(:wiki_page,
        wiki: project.wiki,
        attrs: { title: 'home', content: 'Look at this [image](image.jpg)\n\n ![alt text](image.jpg)' })
    end
12 13

    before do
14 15 16
      project.add_master(user)
      sign_in(user)
    end
17

18 19 20
    context 'when wiki is empty' do
      before do
        visit(project_wikis_path(project))
21

22
        click_on('New page')
23

24 25 26 27 28 29 30 31 32
        page.within('#modal-new-wiki') do
          fill_in(:new_wiki_path, with: 'one/two/three-test')
          click_on('Create page')
        end

        page.within('.wiki-form') do
          fill_in(:wiki_content, with: 'wiki content')
          click_on('Create page')
        end
33 34
      end

35 36
      it 'shows the history of a page that has a path', :js do
        expect(current_path).to include('one/two/three-test')
37

38 39
        first(:link, text: 'Three').click
        click_on('Page history')
40

41
        expect(current_path).to include('one/two/three-test')
42

43 44 45
        page.within(:css, '.nav-text') do
          expect(page).to have_content('History')
        end
46 47
      end

48 49 50
      it 'shows an old version of a page', :js do
        expect(current_path).to include('one/two/three-test')
        expect(find('.wiki-pages')).to have_content('Three')
51

52
        first(:link, text: 'Three').click
53

54
        expect(find('.nav-text')).to have_content('Three')
55

56
        click_on('Edit')
57

58 59
        expect(current_path).to include('one/two/three-test')
        expect(page).to have_content('Edit Page')
60

61
        fill_in('Content', with: 'Updated Wiki Content')
62

63 64
        click_on('Save changes')
        click_on('Page history')
65

66 67 68
        page.within(:css, '.nav-text') do
          expect(page).to have_content('History')
        end
69

70 71
        find('a[href*="?version_id"]')
      end
72 73
    end

74 75 76 77
    context 'when a page does not have history' do
      before do
        visit(project_wiki_path(project, wiki_page))
      end
78

79 80 81 82
      it 'shows all the pages' do
        expect(page).to have_content(user.name)
        expect(find('.wiki-pages')).to have_content(wiki_page.title.capitalize)
      end
83

84 85 86 87 88 89 90
      it 'shows a file stored in a page' do
        gollum_file_double = double('Gollum::File',
                                    mime_type: 'image/jpeg',
                                    name: 'images/image.jpg',
                                    path: 'images/image.jpg',
                                    raw_data: '')
        wiki_file = Gitlab::Git::WikiFile.new(gollum_file_double)
91

92 93
        allow(wiki_file).to receive(:mime_type).and_return('image/jpeg')
        allow_any_instance_of(ProjectWiki).to receive(:find_file).with('image.jpg', nil).and_return(wiki_file)
94

95 96
        expect(page).to have_xpath('//img[@data-src="image.jpg"]')
        expect(page).to have_link('image', href: "#{project.wiki.wiki_base_path}/image.jpg")
97

98
        click_on('image')
99

100 101 102
        expect(current_path).to match('wikis/image.jpg')
        expect(page).not_to have_xpath('/html') # Page should render the image which means there is no html involved
      end
103

104 105
      it 'shows the creation page if file does not exist' do
        expect(page).to have_link('image', href: "#{project.wiki.wiki_base_path}/image.jpg")
106

107
        click_on('image')
108

109 110 111 112
        expect(current_path).to match('wikis/image.jpg')
        expect(page).to have_content('New Wiki Page')
        expect(page).to have_content('Create page')
      end
113 114
    end

115 116 117 118
    context 'when a page has history' do
      before do
        wiki_page.update(message: 'updated home', content: 'updated [some link](other-page)')
      end
119

120 121
      it 'shows the page history' do
        visit(project_wiki_path(project, wiki_page))
122

123
        expect(page).to have_selector('a.btn', text: 'Edit')
124

125
        click_on('Page history')
126

127 128 129 130 131 132 133 134 135 136
        expect(page).to have_content(user.name)
        expect(page).to have_content("#{user.username} created page: home")
        expect(page).to have_content('updated home')
      end

      it 'does not show the "Edit" button' do
        visit(project_wiki_path(project, wiki_page, version_id: wiki_page.versions.last.id))

        expect(page).not_to have_selector('a.btn', text: 'Edit')
      end
137 138
    end

139 140
    it 'opens a default wiki page', :js do
      visit(project_path(project))
141

142 143 144
      find('.shortcuts-wiki').click

      expect(page).to have_content('Home · Create Page')
145 146 147
    end
  end

148 149 150
  context 'when Gitaly is enabled' do
    it_behaves_like 'wiki page user view'
  end
151

152 153
  context 'when Gitaly is disabled', :skip_gitaly_mock do
    it_behaves_like 'wiki page user view'
154 155
  end
end