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

238 lines
6.7 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2016-06-02 11:05:42 +05:30
require 'spec_helper'
2018-03-17 18:26:18 +05:30
describe 'User updates wiki page' do
2020-04-08 14:13:33 +05:30
include WikiHelpers
2019-02-15 15:39:39 +05:30
let(:user) { create(:user) }
2018-11-20 20:47:30 +05:30
2019-02-15 15:39:39 +05:30
before do
project.add_maintainer(user)
sign_in(user)
end
context 'when wiki is empty' do
2020-04-08 14:13:33 +05:30
before do |example|
2019-02-15 15:39:39 +05:30
visit(project_wikis_path(project))
2020-04-08 14:13:33 +05:30
wait_for_svg_to_be_loaded(example)
2019-02-15 15:39:39 +05:30
click_link "Create your first page"
2018-03-17 18:26:18 +05:30
end
2019-02-15 15:39:39 +05:30
context 'in a user namespace' do
let(:project) { create(:project, :wiki_repo) }
2016-06-02 11:05:42 +05:30
2019-02-15 15:39:39 +05:30
it 'redirects back to the home edit page' do
page.within(:css, '.wiki-form .form-actions') do
click_on('Cancel')
2018-03-17 18:26:18 +05:30
end
2019-02-15 15:39:39 +05:30
expect(current_path).to eq project_wiki_path(project, :home)
end
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
it 'updates a page that has a path', :js do
2019-07-07 11:18:12 +05:30
fill_in(:wiki_title, with: 'one/two/three-test')
2016-06-02 11:05:42 +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')
end
2016-06-02 11:05:42 +05:30
2019-02-15 15:39:39 +05:30
expect(current_path).to include('one/two/three-test')
expect(find('.wiki-pages')).to have_content('three')
2016-06-02 11:05:42 +05:30
2019-02-15 15:39:39 +05:30
first(:link, text: 'three').click
2016-06-02 11:05:42 +05:30
2019-02-15 15:39:39 +05:30
expect(find('.nav-text')).to have_content('three')
2017-08-17 22:00:37 +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')
click_on('Save changes')
2018-11-20 20:47:30 +05:30
2019-02-15 15:39:39 +05:30
expect(page).to have_content('Updated Wiki Content')
2018-03-17 18:26:18 +05:30
end
2019-02-15 15:39:39 +05:30
it_behaves_like 'wiki file attachments'
end
end
2018-11-20 20:47:30 +05:30
2019-02-15 15:39:39 +05:30
context 'when wiki is not empty' do
let(:project_wiki) { create(:project_wiki, project: project, user: project.creator) }
2020-05-24 23:13:21 +05:30
let!(:wiki_page) { create(:wiki_page, wiki: project_wiki, title: 'home', content: 'Home page') }
2017-08-17 22:00:37 +05:30
2019-02-15 15:39:39 +05:30
before do
visit(project_wikis_path(project))
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
click_link('Edit')
end
2017-08-17 22:00:37 +05:30
2019-02-15 15:39:39 +05:30
context 'in a user namespace' do
let(:project) { create(:project, :wiki_repo) }
2017-08-17 22:00:37 +05:30
2019-12-04 20:38:33 +05:30
it 'updates a page', :js do
2019-02-15 15:39:39 +05:30
# Commit message field should have correct value.
expect(page).to have_field('wiki[message]', with: 'Update home')
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
fill_in(:wiki_content, with: 'My awesome wiki!')
click_button('Save changes')
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
expect(page).to have_content('Home')
expect(page).to have_content("Last edited by #{user.name}")
expect(page).to have_content('My awesome wiki!')
end
2018-03-17 18:26:18 +05:30
2019-12-04 20:38:33 +05:30
it 'updates the commit message as the title is changed', :js do
2020-03-13 15:44:24 +05:30
fill_in(:wiki_title, with: '& < > \ \ { } &')
2019-12-04 20:38:33 +05:30
2020-03-13 15:44:24 +05:30
expect(page).to have_field('wiki[message]', with: 'Update & < > \ \ { } &')
2019-12-04 20:38:33 +05:30
end
2020-03-13 15:44:24 +05:30
it 'correctly escapes the commit message entities', :js do
fill_in(:wiki_title, with: 'Wiki title')
2019-12-04 20:38:33 +05:30
2020-03-13 15:44:24 +05:30
expect(page).to have_field('wiki[message]', with: 'Update Wiki title')
2019-12-04 20:38:33 +05:30
end
2019-02-15 15:39:39 +05:30
it 'shows a validation error message' do
fill_in(:wiki_content, with: '')
click_button('Save changes')
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
expect(page).to have_selector('.wiki-form')
expect(page).to have_content('Edit Page')
expect(page).to have_content('The form contains the following error:')
expect(page).to have_content("Content can't be blank")
expect(find('textarea#wiki_content').value).to eq('')
end
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
it 'shows the emoji autocompletion dropdown', :js do
find('#wiki_content').native.send_keys('')
fill_in(:wiki_content, with: ':')
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
expect(page).to have_selector('.atwho-view')
end
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
it 'shows the error message' do
wiki_page.update(content: 'Update')
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
click_button('Save changes')
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
expect(page).to have_content('Someone edited the page the same time you did.')
end
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
it 'updates a page' do
fill_in('Content', with: 'Updated Wiki Content')
click_on('Save changes')
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
expect(page).to have_content('Updated Wiki Content')
end
2019-01-03 12:48:30 +05:30
2019-02-15 15:39:39 +05:30
it 'cancels editing of a page' do
page.within(:css, '.wiki-form .form-actions') do
click_on('Cancel')
2018-03-17 18:26:18 +05:30
end
2018-11-20 20:47:30 +05:30
2019-02-15 15:39:39 +05:30
expect(current_path).to eq(project_wiki_path(project, wiki_page))
2017-08-17 22:00:37 +05:30
end
2017-09-10 17:25:29 +05:30
2019-02-15 15:39:39 +05:30
it_behaves_like 'wiki file attachments'
end
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
context 'in a group namespace' do
let(:project) { create(:project, :wiki_repo, namespace: create(:group, :public)) }
2017-09-10 17:25:29 +05:30
2019-12-04 20:38:33 +05:30
it 'updates a page', :js do
2019-02-15 15:39:39 +05:30
# Commit message field should have correct value.
expect(page).to have_field('wiki[message]', with: 'Update home')
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
fill_in(:wiki_content, with: 'My awesome wiki!')
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
click_button('Save changes')
2018-11-20 20:47:30 +05:30
2019-02-15 15:39:39 +05:30
expect(page).to have_content('Home')
expect(page).to have_content("Last edited by #{user.name}")
expect(page).to have_content('My awesome wiki!')
2017-09-10 17:25:29 +05:30
end
2019-02-15 15:39:39 +05:30
it_behaves_like 'wiki file attachments'
end
end
2017-09-10 17:25:29 +05:30
2019-02-15 15:39:39 +05:30
context 'when the page is in a subdir' do
let!(:project) { create(:project, :wiki_repo) }
let(:project_wiki) { create(:project_wiki, project: project, user: project.creator) }
let(:page_name) { 'page_name' }
let(:page_dir) { "foo/bar/#{page_name}" }
2020-05-24 23:13:21 +05:30
let!(:wiki_page) { create(:wiki_page, wiki: project_wiki, title: page_dir, content: 'Home page') }
2017-09-10 17:25:29 +05:30
2019-02-15 15:39:39 +05:30
before do
visit(project_wiki_edit_path(project, wiki_page))
end
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
it 'moves the page to the root folder' do
fill_in(:wiki_title, with: "/#{page_name}")
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
click_button('Save changes')
2016-06-02 11:05:42 +05:30
2019-02-15 15:39:39 +05:30
expect(current_path).to eq(project_wiki_path(project, page_name))
end
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
it 'moves the page to other dir' do
new_page_dir = "foo1/bar1/#{page_name}"
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
fill_in(:wiki_title, with: new_page_dir)
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
click_button('Save changes')
2019-01-03 12:48:30 +05:30
2019-02-15 15:39:39 +05:30
expect(current_path).to eq(project_wiki_path(project, new_page_dir))
end
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
it 'remains in the same place if title has not changed' do
original_path = project_wiki_path(project, wiki_page)
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
fill_in(:wiki_title, with: page_name)
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
click_button('Save changes')
2016-06-02 11:05:42 +05:30
2019-02-15 15:39:39 +05:30
expect(current_path).to eq(original_path)
end
2016-06-02 11:05:42 +05:30
2019-02-15 15:39:39 +05:30
it 'can be moved to a different dir with a different name' do
new_page_dir = "foo1/bar1/new_page_name"
2017-08-17 22:00:37 +05:30
2019-02-15 15:39:39 +05:30
fill_in(:wiki_title, with: new_page_dir)
2016-06-02 11:05:42 +05:30
2019-02-15 15:39:39 +05:30
click_button('Save changes')
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
expect(current_path).to eq(project_wiki_path(project, new_page_dir))
end
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
it 'can be renamed and moved to the root folder' do
new_name = 'new_page_name'
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
fill_in(:wiki_title, with: "/#{new_name}")
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
click_button('Save changes')
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
expect(current_path).to eq(project_wiki_path(project, new_name))
end
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
it 'squishes the title before creating the page' do
new_page_dir = " foo1 / bar1 / #{page_name} "
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
fill_in(:wiki_title, with: new_page_dir)
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
click_button('Save changes')
2018-11-20 20:47:30 +05:30
2019-02-15 15:39:39 +05:30
expect(current_path).to eq(project_wiki_path(project, "foo1/bar1/#{page_name}"))
2016-06-02 11:05:42 +05:30
end
2018-03-17 18:26:18 +05:30
2019-02-15 15:39:39 +05:30
it_behaves_like 'wiki file attachments'
2018-03-17 18:26:18 +05:30
end
2016-06-02 11:05:42 +05:30
end