diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
commit | a09983ae35713f5a2bbb100981116d31ce99826e (patch) | |
tree | 2ee2af7bd104d57086db360a7e6d8c9d5d43667a /spec/features/projects/wiki | |
parent | 18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff) |
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'spec/features/projects/wiki')
-rw-r--r-- | spec/features/projects/wiki/user_views_wiki_empty_spec.rb | 42 | ||||
-rw-r--r-- | spec/features/projects/wiki/user_views_wiki_page_spec.rb | 84 |
2 files changed, 109 insertions, 17 deletions
diff --git a/spec/features/projects/wiki/user_views_wiki_empty_spec.rb b/spec/features/projects/wiki/user_views_wiki_empty_spec.rb index d9f79162c19..0af40a2d760 100644 --- a/spec/features/projects/wiki/user_views_wiki_empty_spec.rb +++ b/spec/features/projects/wiki/user_views_wiki_empty_spec.rb @@ -4,18 +4,19 @@ 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)) - element = page.find('.row.empty-state') - 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 @@ -23,11 +24,10 @@ RSpec.describe 'User views empty wiki' do it 'does not show "issue tracker" message' do visit(project_wikis_path(project)) - element = page.find('.row.empty-state') - 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 @@ -60,16 +60,15 @@ RSpec.describe 'User views empty wiki' do end context 'when user is logged in and a member' do - let(:project) { create(:project, :public, :wiki_repo) } + let(:project) { create(:project, :public) } before do sign_in(user) project.add_developer(user) end - it 'show "create first page" message' do + it 'shows "create first page" message' do visit(project_wikis_path(project)) - element = page.find('.row.empty-state') expect(element).to have_content('your project', count: 2) @@ -77,5 +76,34 @@ RSpec.describe 'User views empty wiki' do 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 diff --git a/spec/features/projects/wiki/user_views_wiki_page_spec.rb b/spec/features/projects/wiki/user_views_wiki_page_spec.rb index 59ccb83a9bb..e93689af0aa 100644 --- a/spec/features/projects/wiki/user_views_wiki_page_spec.rb +++ b/spec/features/projects/wiki/user_views_wiki_page_spec.rb @@ -8,9 +8,10 @@ RSpec.describe 'User views a wiki page' do let(:user) { create(:user) } let(:project) { create(:project, :wiki_repo, namespace: user.namespace) } let(:path) { 'image.png' } + let(:wiki) { project.wiki } let(:wiki_page) do create(:wiki_page, - wiki: project.wiki, + wiki: wiki, title: 'home', content: "Look at this [image](#{path})\n\n ![alt text](#{path})") end @@ -70,11 +71,13 @@ RSpec.describe 'User views a wiki page' do click_on('Page history') - page.within(:css, '.nav-text') do + within('.nav-text') do expect(page).to have_content('History') end - find('a[href*="?version_id"]') + within('.wiki-history') do + expect(page).to have_css('a[href*="?version_id"]', count: 4) + end end end @@ -92,8 +95,8 @@ RSpec.describe 'User views a wiki page' do let(:path) { upload_file_to_wiki(project, user, 'dk.png') } it do - expect(page).to have_xpath("//img[@data-src='#{project.wiki.wiki_base_path}/#{path}']") - expect(page).to have_link('image', href: "#{project.wiki.wiki_base_path}/#{path}") + expect(page).to have_xpath("//img[@data-src='#{wiki.wiki_base_path}/#{path}']") + expect(page).to have_link('image', href: "#{wiki.wiki_base_path}/#{path}") click_on('image') @@ -103,7 +106,7 @@ RSpec.describe 'User views a wiki page' do end it 'shows the creation page if file does not exist' do - expect(page).to have_link('image', href: "#{project.wiki.wiki_base_path}/#{path}") + expect(page).to have_link('image', href: "#{wiki.wiki_base_path}/#{path}") click_on('image') @@ -114,7 +117,7 @@ RSpec.describe 'User views a wiki page' do context 'when a page has history' do before do - wiki_page.update(message: 'updated home', content: 'updated [some link](other-page)') + wiki_page.update(message: 'updated home', content: 'updated [some link](other-page)') # rubocop:disable Rails/SaveBang end it 'shows the page history' do @@ -134,13 +137,74 @@ RSpec.describe 'User views a wiki page' do expect(page).not_to have_selector('a.btn', text: 'Edit') end + + context 'show the diff' do + def expect_diff_links(commit) + diff_path = wiki_page_path(wiki, wiki_page, version_id: commit, action: :diff) + + expect(page).to have_link('Hide whitespace changes', href: "#{diff_path}&w=1") + expect(page).to have_link('Inline', href: "#{diff_path}&view=inline") + expect(page).to have_link('Side-by-side', href: "#{diff_path}&view=parallel") + expect(page).to have_link("View page @ #{commit.short_id}", href: wiki_page_path(wiki, wiki_page, version_id: commit)) + expect(page).to have_css('.diff-file[data-blob-diff-path="%s"]' % diff_path) + end + + it 'links to the correct diffs' do + visit project_wiki_history_path(project, wiki_page) + + commit1 = wiki.commit('HEAD^') + commit2 = wiki.commit + + expect(page).to have_link('created page: home', href: wiki_page_path(wiki, wiki_page, version_id: commit1, action: :diff)) + expect(page).to have_link('updated home', href: wiki_page_path(wiki, wiki_page, version_id: commit2, action: :diff)) + end + + it 'between the current and the previous version of a page' do + commit = wiki.commit + visit wiki_page_path(wiki, wiki_page, version_id: commit, action: :diff) + + expect(page).to have_content('by John Doe') + expect(page).to have_content('updated home') + expect(page).to have_content('Showing 1 changed file with 1 addition and 3 deletions') + expect(page).to have_content('some link') + + expect_diff_links(commit) + end + + it 'between two old versions of a page' do + wiki_page.update(message: 'latest home change', content: 'updated [another link](other-page)') # rubocop:disable Rails/SaveBang: + commit = wiki.commit('HEAD^') + visit wiki_page_path(wiki, wiki_page, version_id: commit, action: :diff) + + expect(page).to have_content('by John Doe') + expect(page).to have_content('updated home') + expect(page).to have_content('Showing 1 changed file with 1 addition and 3 deletions') + expect(page).to have_content('some link') + expect(page).not_to have_content('latest home change') + expect(page).not_to have_content('another link') + + expect_diff_links(commit) + end + + it 'for the oldest version of a page' do + commit = wiki.commit('HEAD^') + visit wiki_page_path(wiki, wiki_page, version_id: commit, action: :diff) + + expect(page).to have_content('by John Doe') + expect(page).to have_content('created page: home') + expect(page).to have_content('Showing 1 changed file with 4 additions and 0 deletions') + expect(page).to have_content('Look at this') + + expect_diff_links(commit) + end + end end context 'when a page has special characters in its title' do let(:title) { '<foo> !@#$%^&*()[]{}=_+\'"\\|<>? <bar>' } before do - wiki_page.update(title: title ) + wiki_page.update(title: title ) # rubocop:disable Rails/SaveBang end it 'preserves the special characters' do @@ -155,7 +219,7 @@ RSpec.describe 'User views a wiki page' do let(:title) { '<script>alert("title")<script>' } before do - wiki_page.update(title: title, content: 'foo <script>alert("content")</script> bar') + wiki_page.update(title: title, content: 'foo <script>alert("content")</script> bar') # rubocop:disable Rails/SaveBang end it 'safely displays the page' do @@ -168,7 +232,7 @@ RSpec.describe 'User views a wiki page' do context 'when a page has XSS in its message' do before do - wiki_page.update(message: '<script>alert(true)<script>', content: 'XSS update') + wiki_page.update(message: '<script>alert(true)<script>', content: 'XSS update') # rubocop:disable Rails/SaveBang end it 'safely displays the message' do |