debian-mirror-gitlab/spec/features/projects/wiki/user_views_wiki_page_spec.rb

161 lines
4.4 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
require 'spec_helper'
describe 'User views a wiki page' do
2019-02-15 15:39:39 +05:30
include WikiHelpers
let(:user) { create(:user) }
let(:project) { create(:project, :wiki_repo, namespace: user.namespace) }
let(:path) { 'image.png' }
let(:wiki_page) do
create(:wiki_page,
wiki: project.wiki,
attrs: { title: 'home', content: "Look at this [image](#{path})\n\n ![alt text](#{path})" })
end
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
before do
project.add_maintainer(user)
sign_in(user)
end
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
context 'when wiki is empty' do
before do
visit(project_wikis_path(project))
click_link "Create your first page"
2018-03-17 18:26:18 +05:30
2019-07-07 11:18:12 +05:30
fill_in(:wiki_title, with: 'one/two/three-test')
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
page.within('.wiki-form') do
fill_in(:wiki_content, with: 'wiki content')
click_on('Create page')
2018-03-17 18:26:18 +05:30
end
2019-02-15 15:39:39 +05:30
end
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
it 'shows the history of a page that has a path', :js do
expect(current_path).to include('one/two/three-test')
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
first(:link, text: 'three').click
click_on('Page history')
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
expect(current_path).to include('one/two/three-test')
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
page.within(:css, '.nav-text') do
expect(page).to have_content('History')
2018-03-17 18:26:18 +05:30
end
2019-02-15 15:39:39 +05:30
end
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
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')
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
first(:link, text: 'three').click
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
expect(find('.nav-text')).to have_content('three')
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
click_on('Edit')
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
expect(current_path).to include('one/two/three-test')
expect(page).to have_content('Edit Page')
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
fill_in('Content', with: 'Updated Wiki Content')
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
click_on('Save changes')
click_on('Page history')
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
page.within(:css, '.nav-text') do
expect(page).to have_content('History')
2019-01-03 12:48:30 +05:30
end
2019-02-15 15:39:39 +05:30
find('a[href*="?version_id"]')
end
end
2019-01-03 12:48:30 +05:30
2019-02-15 15:39:39 +05:30
context 'when a page does not have history' do
before do
visit(project_wiki_path(project, wiki_page))
end
2019-01-03 12:48:30 +05:30
2019-02-15 15:39:39 +05:30
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
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
context 'shows a file stored in a page' do
let(:path) { upload_file_to_wiki(project, user, 'dk.png') }
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
it do
expect(page).to have_xpath("//img[@data-src='#{project.wiki.wiki_base_path}/#{path}']")
2018-12-13 13:39:08 +05:30
expect(page).to have_link('image', href: "#{project.wiki.wiki_base_path}/#{path}")
2018-03-17 18:26:18 +05:30
click_on('image')
2018-12-13 13:39:08 +05:30
expect(current_path).to match("wikis/#{path}")
2019-02-15 15:39:39 +05:30
expect(page).not_to have_xpath('/html') # Page should render the image which means there is no html involved
2018-03-17 18:26:18 +05:30
end
end
2019-02-15 15:39:39 +05:30
it 'shows the creation page if file does not exist' do
expect(page).to have_link('image', href: "#{project.wiki.wiki_base_path}/#{path}")
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
click_on('image')
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
expect(current_path).to match("wikis/#{path}")
2019-12-04 20:38:33 +05:30
expect(page).to have_content('Create New Page')
2019-02-15 15:39:39 +05:30
end
end
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
context 'when a page has history' do
before do
wiki_page.update(message: 'updated home', content: 'updated [some link](other-page)')
end
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
it 'shows the page history' do
visit(project_wiki_path(project, wiki_page))
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
expect(page).to have_selector('a.btn', text: 'Edit')
2018-12-23 12:14:25 +05:30
2019-02-15 15:39:39 +05:30
click_on('Page history')
expect(page).to have_content(user.name)
expect(page).to have_content("#{user.username} created page: home")
expect(page).to have_content('updated home')
2018-03-17 18:26:18 +05:30
end
2019-02-15 15:39:39 +05:30
it 'does not show the "Edit" button' do
visit(project_wiki_path(project, wiki_page, version_id: wiki_page.versions.last.id))
2018-11-18 11:00:15 +05:30
2019-02-15 15:39:39 +05:30
expect(page).not_to have_selector('a.btn', text: 'Edit')
end
end
2018-11-18 11:00:15 +05:30
2019-02-15 15:39:39 +05:30
context 'when page has invalid content encoding' do
2019-10-12 21:52:04 +05:30
let(:content) { (+'whatever').force_encoding('ISO-8859-1') }
2018-11-18 11:00:15 +05:30
2019-02-15 15:39:39 +05:30
before do
allow(Gitlab::EncodingHelper).to receive(:encode!).and_return(content)
2018-11-18 11:00:15 +05:30
2019-02-15 15:39:39 +05:30
visit(project_wiki_path(project, wiki_page))
2018-11-18 11:00:15 +05:30
end
2019-02-15 15:39:39 +05:30
it 'does not show "Edit" button' do
expect(page).not_to have_selector('a.btn', text: 'Edit')
end
2019-01-03 12:48:30 +05:30
2019-02-15 15:39:39 +05:30
it 'shows error' do
page.within(:css, '.flash-notice') do
expect(page).to have_content('The content of this page is not encoded in UTF-8. Edits can only be made via the Git repository.')
end
2018-03-17 18:26:18 +05:30
end
end
2019-02-15 15:39:39 +05:30
it 'opens a default wiki page', :js do
visit(project_path(project))
find('.shortcuts-wiki').click
click_link "Create your first page"
2018-03-17 18:26:18 +05:30
2019-12-04 20:38:33 +05:30
expect(page).to have_content('Create New Page')
2018-03-17 18:26:18 +05:30
end
end