diff options
author | Rรฉmy Coutable <remy@rymai.me> | 2017-09-11 18:24:14 +0300 |
---|---|---|
committer | Rรฉmy Coutable <remy@rymai.me> | 2017-09-11 18:24:14 +0300 |
commit | 73a913f2b5f2a5dd36e13e09d74264d1da218d6a (patch) | |
tree | 100dc0bf4048569e5e81b9b1323b6c6c5f9e085e | |
parent | 0b66c94bb1c806080ec573d0dd6995f130b6f883 (diff) | |
parent | 8cbefe9d67e79f548390b929054cc333e9d7b408 (diff) |
Merge branch 'replace_spinach_wiki.feature' into 'master'
Replace 'project/wiki.feature' spinach test with an rspec analog
See merge request !13856
-rw-r--r-- | changelogs/unreleased/replace_spinach_wiki-feature.yml | 5 | ||||
-rw-r--r-- | features/project/wiki.feature | 101 | ||||
-rw-r--r-- | features/steps/project/wiki.rb | 195 | ||||
-rw-r--r-- | spec/features/projects/wiki/user_creates_wiki_page_spec.rb | 227 | ||||
-rw-r--r-- | spec/features/projects/wiki/user_deletes_wiki_page_spec.rb | 19 | ||||
-rw-r--r-- | spec/features/projects/wiki/user_updates_wiki_page_spec.rb | 157 | ||||
-rw-r--r-- | spec/features/projects/wiki/user_views_project_wiki_page_spec.rb | 39 | ||||
-rw-r--r-- | spec/features/projects/wiki/user_views_wiki_page_spec.rb | 140 |
8 files changed, 413 insertions, 470 deletions
diff --git a/changelogs/unreleased/replace_spinach_wiki-feature.yml b/changelogs/unreleased/replace_spinach_wiki-feature.yml new file mode 100644 index 00000000000..a1801f1b58d --- /dev/null +++ b/changelogs/unreleased/replace_spinach_wiki-feature.yml @@ -0,0 +1,5 @@ +--- +title: Replace 'project/wiki.feature' spinach test with an rspec analog +merge_request: 13856 +author: Vitaliy @blackst0ne Klachkov +type: other diff --git a/features/project/wiki.feature b/features/project/wiki.feature deleted file mode 100644 index a04228de03b..00000000000 --- a/features/project/wiki.feature +++ /dev/null @@ -1,101 +0,0 @@ -Feature: Project Wiki - Background: - Given I sign in as a user - And I own project "Shop" - Given I visit project wiki page - - Scenario: Add new page - Given I create the Wiki Home page - Then I should see the newly created wiki page - - Scenario: Add new page with errors - Given I create the Wiki Home page with no content - Then I should see a "Content can't be blank" error message - When I create the Wiki Home page - Then I should see the newly created wiki page - - Scenario: Pressing Cancel while editing a brand new Wiki - Given I click on the Cancel button - Then I should be redirected back to the Edit Home Wiki page - - Scenario: Edit existing page - Given I have an existing Wiki page - And I browse to that Wiki page - And I click on the Edit button - And I change the content - Then I should see the updated content - - Scenario: Pressing Cancel while editing an existing Wiki page - Given I have an existing Wiki page - And I browse to that Wiki page - And I click on the Edit button - And I click on the Cancel button - Then I should be redirected back to that Wiki page - - Scenario: View page history - Given I have an existing wiki page - And That page has two revisions - And I browse to that Wiki page - And I click the History button - Then I should see both revisions - - Scenario: Destroy Wiki page - Given I have an existing wiki page - And I browse to that Wiki page - And I click on the Edit button - And I click on the "Delete this page" button - Then The page should be deleted - - Scenario: View all pages - Given I have an existing wiki page - And I browse to that Wiki page - Then I should see the existing page in the pages list - - Scenario: File exists in wiki repo - Given I have an existing Wiki page with images linked on page - And I browse to wiki page with images - And I click on existing image link - Then I should see the image from wiki repo - - Scenario: Image in wiki repo shown on the page - Given I have an existing Wiki page with images linked on page - And I browse to wiki page with images - Then Image should be shown on the page - - Scenario: File does not exist in wiki repo - Given I have an existing Wiki page with images linked on page - And I browse to wiki page with images - And I click on image link - Then I should see the new wiki page form - - @javascript - Scenario: New Wiki page that has a path - Given I create a New page with paths - Then I should see non-escaped link in the pages list - - @javascript - Scenario: Edit Wiki page that has a path - Given I create a New page with paths - And I edit the Wiki page with a path - Then I should see a non-escaped path - And I should see the Editing page - And I change the content - Then I should see the updated content - - @javascript - Scenario: View the page history of a Wiki page that has a path - Given I create a New page with paths - And I view the page history of a Wiki page that has a path - Then I should see a non-escaped path - And I should see the page history - - @javascript - Scenario: View an old page version of a Wiki page - Given I create a New page with paths - And I edit the Wiki page with a path - Then I should see a non-escaped path - And I should see the Editing page - And I change the content - Then I click on Page History - And I should see the page history - And I should see a link with a version ID diff --git a/features/steps/project/wiki.rb b/features/steps/project/wiki.rb deleted file mode 100644 index 855757e34b3..00000000000 --- a/features/steps/project/wiki.rb +++ /dev/null @@ -1,195 +0,0 @@ -class Spinach::Features::ProjectWiki < Spinach::FeatureSteps - include SharedAuthentication - include SharedProject - include SharedNote - include SharedPaths - - step 'I click on the Cancel button' do - page.within(:css, ".wiki-form .form-actions") do - click_on "Cancel" - end - end - - step 'I should be redirected back to the Edit Home Wiki page' do - expect(current_path).to eq project_wiki_path(project, :home) - end - - step 'I create the Wiki Home page' do - fill_in "wiki_content", with: '[link test](test)' - page.within '.wiki-form' do - click_on "Create page" - end - end - - step 'I create the Wiki Home page with no content' do - fill_in "wiki_content", with: '' - page.within '.wiki-form' do - click_on "Create page" - end - end - - step 'I should see the newly created wiki page' do - expect(page).to have_content "Home" - expect(page).to have_content "link test" - - click_link "link test" - expect(page).to have_content "Create page" - end - - step 'I have an existing Wiki page' do - wiki.create_page("existing", "content", :markdown, "first commit") - @page = wiki.find_page("existing") - end - - step 'I browse to that Wiki page' do - visit project_wiki_path(project, @page) - end - - step 'I click on the Edit button' do - click_on "Edit" - end - - step 'I change the content' do - fill_in "Content", with: 'Updated Wiki Content' - click_on "Save changes" - end - - step 'I should see the updated content' do - expect(page).to have_content "Updated Wiki Content" - end - - step 'I should be redirected back to that Wiki page' do - expect(current_path).to eq project_wiki_path(project, @page) - end - - step 'That page has two revisions' do - @page.update(content: "new content", message: "second commit") - end - - step 'I click the History button' do - click_on 'Page history' - end - - step 'I should see both revisions' do - expect(page).to have_content current_user.name - expect(page).to have_content "first commit" - expect(page).to have_content "second commit" - end - - step 'I click on the "Delete this page" button' do - click_on "Delete" - end - - step 'The page should be deleted' do - expect(page).to have_content "Page was successfully deleted" - end - - step 'I should see the existing page in the pages list' do - expect(page).to have_content current_user.name - expect(find('.wiki-pages')).to have_content @page.title.capitalize - end - - step 'I have an existing Wiki page with images linked on page' do - wiki.create_page("pictures", "Look at this [image](image.jpg)\n\n ![alt text](image.jpg)", :markdown, "first commit") - @wiki_page = wiki.find_page("pictures") - end - - step 'I browse to wiki page with images' do - visit project_wiki_path(project, @wiki_page) - end - - step 'I click on existing image link' do - file = Gollum::File.new(wiki.wiki) - Gollum::Wiki.any_instance.stub(:file).with("image.jpg", "master", true).and_return(file) - Gollum::File.any_instance.stub(:mime_type).and_return("image/jpeg") - expect(page).to have_link('image', href: "#{wiki.wiki_base_path}/image.jpg") - click_on "image" - end - - step 'I should see the image from wiki repo' do - 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 - Gollum::Wiki.any_instance.unstub(:file) - Gollum::File.any_instance.unstub(:mime_type) - end - - step 'Image should be shown on the page' do - expect(page).to have_xpath("//img[@data-src=\"image.jpg\"]") - end - - step 'I click on image link' do - expect(page).to have_link('image', href: "#{wiki.wiki_base_path}/image.jpg") - click_on "image" - end - - step 'I should see the new wiki page form' do - expect(current_path).to match('wikis/image.jpg') - expect(page).to have_content('New Wiki Page') - expect(page).to have_content('Create page') - end - - step 'I create a New page with paths' do - click_on 'New page' - fill_in 'Page slug', with: 'one/two/three-test' - page.within '#modal-new-wiki' do - click_on 'Create page' - end - fill_in "wiki_content", with: 'wiki content' - page.within '.wiki-form' do - click_on "Create page" - end - expect(current_path).to include 'one/two/three-test' - end - - step 'I should see non-escaped link in the pages list' do - expect(page).to have_xpath("//a[@href='/#{project.full_path}/wikis/one/two/three-test']") - end - - step 'I edit the Wiki page with a path' do - expect(find('.wiki-pages')).to have_content('Three') - click_on 'Three' - expect(find('.nav-text')).to have_content('Three') - click_on 'Edit' - end - - step 'I should see a non-escaped path' do - expect(current_path).to include 'one/two/three-test' - end - - step 'I should see the Editing page' do - expect(page).to have_content('Edit Page') - end - - step 'I view the page history of a Wiki page that has a path' do - click_on 'Three' - click_on 'Page history' - end - - step 'I click on Page History' do - click_on 'Page history' - end - - step 'I should see the page history' do - page.within(:css, ".nav-text") do - expect(page).to have_content('History') - end - end - - step 'I search for Wiki content' do - fill_in "Search", with: "wiki_content" - click_button "Search" - end - - step 'I should see a link with a version ID' do - find('a[href*="?version_id"]') - end - - step 'I should see a "Content can\'t be blank" error message' do - expect(page).to have_content('The form contains the following error:') - expect(page).to have_content('Content can\'t be blank') - end - - def wiki - @project_wiki = ProjectWiki.new(project, current_user) - end -end diff --git a/spec/features/projects/wiki/user_creates_wiki_page_spec.rb b/spec/features/projects/wiki/user_creates_wiki_page_spec.rb index 9d66f482c8d..e72b7dc0dd5 100644 --- a/spec/features/projects/wiki/user_creates_wiki_page_spec.rb +++ b/spec/features/projects/wiki/user_creates_wiki_page_spec.rb @@ -1,38 +1,75 @@ require 'spec_helper' -feature 'Projects > Wiki > User creates wiki page', :js do +describe 'User creates wiki page' do let(:user) { create(:user) } - background do - project.team << [user, :master] + before do + project.add_master(user) sign_in(user) - visit project_path(project) + visit(project_wikis_path(project)) end - context 'in the user namespace' do - let(:project) { create(:project, namespace: user.namespace) } + context 'when wiki is empty' do + context 'in a user namespace' do + let(:project) { create(:project, namespace: user.namespace) } - context 'when wiki is empty' do - before do - find('.shortcuts-wiki').trigger('click') + it 'shows validation error message' do + page.within('.wiki-form') do + fill_in(:wiki_content, with: '') + click_on('Create page') + end + + expect(page).to have_content('The form contains the following error:') + expect(page).to have_content("Content can't be blank") + + page.within('.wiki-form') do + fill_in(:wiki_content, with: '[link test](test)') + click_on('Create page') + end + + expect(page).to have_content('Home') + expect(page).to have_content('link test') + + click_link('link test') + + expect(page).to have_content('Create Page') + end + + it 'shows non-escaped link in the pages list', :js do + click_link('New page') + + 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 + + expect(current_path).to include('one/two/three-test') + expect(page).to have_xpath("//a[@href='/#{project.full_path}/wikis/one/two/three-test']") end - scenario 'commit message field has value "Create home"' do + it 'has "Create home" as a commit message' do expect(page).to have_field('wiki[message]', with: 'Create home') end - scenario 'directly from the wiki home page' do - fill_in :wiki_content, with: 'My awesome wiki!' - page.within '.wiki-form' do - click_button 'Create page' + it 'creates a page from the home page' do + fill_in(:wiki_content, with: 'My awesome wiki!') + + page.within('.wiki-form') do + click_button('Create page') end + 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 - scenario 'creates ASCII wiki with LaTeX blocks' do + it 'creates ASCII wiki with LaTeX blocks', :js do stub_application_setting(plantuml_url: 'http://localhost', plantuml_enabled: true) ascii_content = <<~MD @@ -54,10 +91,10 @@ feature 'Projects > Wiki > User creates wiki page', :js do MD find('#wiki_format option[value=asciidoc]').select_option - fill_in :wiki_content, with: ascii_content + fill_in(:wiki_content, with: ascii_content) - page.within '.wiki-form' do - click_button 'Create page' + page.within('.wiki-form') do + click_button('Create page') end page.within '.wiki' do @@ -67,27 +104,49 @@ feature 'Projects > Wiki > User creates wiki page', :js do end end - context 'when wiki is not empty' do - before do - WikiPages::CreateService.new(project, user, title: 'home', content: 'Home page').execute - find('.shortcuts-wiki').trigger('click') + context 'in a group namespace', :js do + let(:project) { create(:project, namespace: create(:group, :public)) } + + it 'has "Create home" as a commit message' do + expect(page).to have_field('wiki[message]', with: 'Create home') + end + + it 'creates a page from from the home page' do + page.within('.wiki-form') do + fill_in(:wiki_content, with: 'My awesome wiki!') + click_button('Create page') + end + + 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 + end + end + + context 'when wiki is not empty', :js do + before do + create(:wiki_page, wiki: create(:project, namespace: user.namespace).wiki, attrs: { title: 'home', content: 'Home page' }) + end + + context 'in a user namespace' do + let(:project) { create(:project, namespace: user.namespace) } context 'via the "new wiki page" page' do - scenario 'when the wiki page has a single word name' do - click_link 'New page' + it 'creates a page with a single word' do + click_link('New page') - page.within '#modal-new-wiki' do - fill_in :new_wiki_path, with: 'foo' - click_button 'Create page' + page.within('#modal-new-wiki') do + fill_in(:new_wiki_path, with: 'foo') + click_button('Create page') end # Commit message field should have correct value. expect(page).to have_field('wiki[message]', with: 'Create foo') - page.within '.wiki-form' do - fill_in :wiki_content, with: 'My awesome wiki!' - click_button 'Create page' + page.within('.wiki-form') do + fill_in(:wiki_content, with: 'My awesome wiki!') + click_button('Create page') end expect(page).to have_content('Foo') @@ -95,20 +154,20 @@ feature 'Projects > Wiki > User creates wiki page', :js do expect(page).to have_content('My awesome wiki!') end - scenario 'when the wiki page has spaces in the name' do - click_link 'New page' + it 'creates a page with spaces in the name' do + click_link('New page') - page.within '#modal-new-wiki' do - fill_in :new_wiki_path, with: 'Spaces in the name' - click_button 'Create page' + page.within('#modal-new-wiki') do + fill_in(:new_wiki_path, with: 'Spaces in the name') + click_button('Create page') end # Commit message field should have correct value. expect(page).to have_field('wiki[message]', with: 'Create spaces in the name') - page.within '.wiki-form' do - fill_in :wiki_content, with: 'My awesome wiki!' - click_button 'Create page' + page.within('.wiki-form') do + fill_in(:wiki_content, with: 'My awesome wiki!') + click_button('Create page') end expect(page).to have_content('Spaces in the name') @@ -116,20 +175,20 @@ feature 'Projects > Wiki > User creates wiki page', :js do expect(page).to have_content('My awesome wiki!') end - scenario 'when the wiki page has hyphens in the name' do - click_link 'New page' + it 'creates a page with hyphens in the name' do + click_link('New page') - page.within '#modal-new-wiki' do - fill_in :new_wiki_path, with: 'hyphens-in-the-name' - click_button 'Create page' + page.within('#modal-new-wiki') do + fill_in(:new_wiki_path, with: 'hyphens-in-the-name') + click_button('Create page') end # Commit message field should have correct value. expect(page).to have_field('wiki[message]', with: 'Create hyphens in the name') - page.within '.wiki-form' do - fill_in :wiki_content, with: 'My awesome wiki!' - click_button 'Create page' + page.within('.wiki-form') do + fill_in(:wiki_content, with: 'My awesome wiki!') + click_button('Create page') end expect(page).to have_content('Hyphens in the name') @@ -138,73 +197,47 @@ feature 'Projects > Wiki > User creates wiki page', :js do end end - scenario 'content has autocomplete' do - click_link 'New page' + it 'shows the autocompletion dropdown' do + click_link('New page') - page.within '#modal-new-wiki' do - fill_in :new_wiki_path, with: 'test-autocomplete' - click_button 'Create page' + page.within('#modal-new-wiki') do + fill_in(:new_wiki_path, with: 'test-autocomplete') + click_button('Create page') end - page.within '.wiki-form' do + page.within('.wiki-form') do find('#wiki_content').native.send_keys('') - fill_in :wiki_content, with: '@' + fill_in(:wiki_content, with: '@') end expect(page).to have_selector('.atwho-view') end end - end - - context 'in a group namespace' do - let(:project) { create(:project, namespace: create(:group, :public)) } - context 'when wiki is empty' do - before do - find('.shortcuts-wiki').trigger('click') - end - - scenario 'commit message field has value "Create home"' do - expect(page).to have_field('wiki[message]', with: 'Create home') - end + context 'in a group namespace' do + let(:project) { create(:project, namespace: create(:group, :public)) } - scenario 'directly from the wiki home page' do - fill_in :wiki_content, with: 'My awesome wiki!' - page.within '.wiki-form' do - click_button 'Create page' - end - - 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 - end - - context 'when wiki is not empty' do - before do - WikiPages::CreateService.new(project, user, title: 'home', content: 'Home page').execute - find('.shortcuts-wiki').trigger('click') - end + context 'via the "new wiki page" page' do + it 'creates a page' do + click_link('New page') - scenario 'via the "new wiki page" page' do - click_link 'New page' + page.within('#modal-new-wiki') do + fill_in(:new_wiki_path, with: 'foo') + click_button('Create page') + end - page.within '#modal-new-wiki' do - fill_in :new_wiki_path, with: 'foo' - click_button 'Create page' - end + # Commit message field should have correct value. + expect(page).to have_field('wiki[message]', with: 'Create foo') - # Commit message field should have correct value. - expect(page).to have_field('wiki[message]', with: 'Create foo') + page.within('.wiki-form') do + fill_in(:wiki_content, with: 'My awesome wiki!') + click_button('Create page') + end - page.within '.wiki-form' do - fill_in :wiki_content, with: 'My awesome wiki!' - click_button 'Create page' + expect(page).to have_content('Foo') + expect(page).to have_content("Last edited by #{user.name}") + expect(page).to have_content('My awesome wiki!') end - - expect(page).to have_content('Foo') - expect(page).to have_content("Last edited by #{user.name}") - expect(page).to have_content('My awesome wiki!') end end end diff --git a/spec/features/projects/wiki/user_deletes_wiki_page_spec.rb b/spec/features/projects/wiki/user_deletes_wiki_page_spec.rb new file mode 100644 index 00000000000..605e332196b --- /dev/null +++ b/spec/features/projects/wiki/user_deletes_wiki_page_spec.rb @@ -0,0 +1,19 @@ +require 'spec_helper' + +feature 'User deletes wiki page' do + let(:user) { create(:user) } + let(:project) { create(:project, namespace: user.namespace) } + let(:wiki_page) { create(:wiki_page, wiki: project.wiki) } + + before do + sign_in(user) + visit(project_wiki_path(project, wiki_page)) + end + + it 'deletes a page' do + click_on('Edit') + click_on('Delete') + + expect(page).to have_content('Page was successfully deleted') + end +end diff --git a/spec/features/projects/wiki/user_updates_wiki_page_spec.rb b/spec/features/projects/wiki/user_updates_wiki_page_spec.rb index 64a80aec205..cfd6f3aa71f 100644 --- a/spec/features/projects/wiki/user_updates_wiki_page_spec.rb +++ b/spec/features/projects/wiki/user_updates_wiki_page_spec.rb @@ -1,83 +1,164 @@ require 'spec_helper' -feature 'Projects > Wiki > User updates wiki page' do +describe 'User updates wiki page' do let(:user) { create(:user) } - let!(:wiki_page) { WikiPages::CreateService.new(project, user, title: 'home', content: 'Home page').execute } - background do - project.team << [user, :master] + before do + project.add_master(user) sign_in(user) + end + + context 'when wiki is empty' do + before do + visit(project_wikis_path(project)) + end + + context 'in a user namespace' do + let(:project) { create(:project, namespace: user.namespace) } + + it 'redirects back to the home edit page' do + page.within(:css, '.wiki-form .form-actions') do + click_on('Cancel') + end + + expect(current_path).to eq project_wiki_path(project, :home) + end + + it 'updates a page that has a path', :js do + click_on('New page') + + 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 - visit project_wikis_path(project) + expect(current_path).to include('one/two/three-test') + expect(find('.wiki-pages')).to have_content('Three') + + click_on('Three') + + expect(find('.nav-text')).to have_content('Three') + + click_on('Edit') + + expect(current_path).to include('one/two/three-test') + expect(page).to have_content('Edit Page') + + fill_in('Content', with: 'Updated Wiki Content') + click_on('Save changes') + + expect(page).to have_content('Updated Wiki Content') + end + end end - context 'in the user namespace' do + context 'when wiki is not empty' do + # This facory call is shorter: + # + # create(:wiki_page, wiki: create(:project, namespace: user.namespace).wiki, attrs: { title: 'home', content: 'Home page' }) + # + # But it always fails with this: + # + # Failure/Error: click_link('Edit') + # Capybara::ElementNotFound: + # Unable to find visible link "Edit" + let(:project) { create(:project, namespace: user.namespace) } + let!(:wiki_page) { create(:wiki_page, wiki: project.wiki, attrs: { title: 'home', content: 'Home page' }) } - context 'the home page' do - scenario 'success when the wiki content is not empty' do - click_link 'Edit' + before do + visit(project_wikis_path(project)) + end + + context 'in a user namespace' do + let(:project) { create(:project, namespace: user.namespace) } + + it 'updates a page' do + click_link('Edit') # Commit message field should have correct value. expect(page).to have_field('wiki[message]', with: 'Update home') - fill_in :wiki_content, with: 'My awesome wiki!' - click_button 'Save changes' + fill_in(:wiki_content, with: 'My awesome wiki!') + click_button('Save changes') 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 - scenario 'failure when the wiki content is empty' do - click_link 'Edit' + it 'shows a validation error message' do + click_link('Edit') - fill_in :wiki_content, with: '' - click_button 'Save changes' + fill_in(:wiki_content, with: '') + click_button('Save changes') 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 '' + expect(page).to have_content("Content can't be blank") + expect(find('textarea#wiki_content').value).to eq('') end - scenario 'content has autocomplete', :js do - click_link 'Edit' + it 'shows the autocompletion dropdown', :js do + click_link('Edit') find('#wiki_content').native.send_keys('') - fill_in :wiki_content, with: '@' + fill_in(:wiki_content, with: '@') expect(page).to have_selector('.atwho-view') end - end - scenario 'page has been updated since the user opened the edit page' do - click_link 'Edit' + it 'shows the error message' do + click_link('Edit') + + wiki_page.update(content: 'Update') - wiki_page.update(content: 'Update') + click_button('Save changes') + + expect(page).to have_content('Someone edited the page the same time you did.') + end + + it 'updates a page' do + click_on('Edit') + fill_in('Content', with: 'Updated Wiki Content') + click_on('Save changes') + + expect(page).to have_content('Updated Wiki Content') + end - click_button 'Save changes' + it 'cancels edititng of a page' do + click_on('Edit') - expect(page).to have_content 'Someone edited the page the same time you did.' + page.within(:css, '.wiki-form .form-actions') do + click_on('Cancel') + end + + expect(current_path).to eq(project_wiki_path(project, wiki_page)) + end end - end - context 'in a group namespace' do - let(:project) { create(:project, namespace: create(:group, :public)) } + context 'in a group namespace' do + let(:project) { create(:project, namespace: create(:group, :public)) } - scenario 'the home page' do - click_link 'Edit' + it 'updates a page' do + click_link('Edit') - # Commit message field should have correct value. - expect(page).to have_field('wiki[message]', with: 'Update home') + # Commit message field should have correct value. + expect(page).to have_field('wiki[message]', with: 'Update home') - fill_in :wiki_content, with: 'My awesome wiki!' - click_button 'Save changes' + fill_in(:wiki_content, with: 'My awesome wiki!') + click_button('Save changes') - expect(page).to have_content('Home') - expect(page).to have_content("Last edited by #{user.name}") - expect(page).to have_content('My awesome wiki!') + 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 end end end diff --git a/spec/features/projects/wiki/user_views_project_wiki_page_spec.rb b/spec/features/projects/wiki/user_views_project_wiki_page_spec.rb deleted file mode 100644 index 92e96f11219..00000000000 --- a/spec/features/projects/wiki/user_views_project_wiki_page_spec.rb +++ /dev/null @@ -1,39 +0,0 @@ -require 'spec_helper' - -feature 'Projects > Wiki > User views the wiki page' do - let(:user) { create(:user) } - let(:project) { create(:project, :public) } - let(:old_page_version_id) { wiki_page.versions.last.id } - let(:wiki_page) do - WikiPages::CreateService.new( - project, - user, - title: 'home', - content: '[some link](other-page)' - ).execute - end - - background do - project.team << [user, :master] - sign_in(user) - WikiPages::UpdateService.new( - project, - user, - message: 'updated home', - content: 'updated [some link](other-page)', - format: :markdown - ).execute(wiki_page) - end - - scenario 'Visit Wiki Page Current Commit' do - visit project_wiki_path(project, wiki_page) - - expect(page).to have_selector('a.btn', text: 'Edit') - end - - scenario 'Visit Wiki Page Historical Commit' do - visit project_wiki_path(project, wiki_page, version_id: old_page_version_id) - - expect(page).not_to have_selector('a.btn', text: 'Edit') - 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 new file mode 100644 index 00000000000..d201d4f6b98 --- /dev/null +++ b/spec/features/projects/wiki/user_views_wiki_page_spec.rb @@ -0,0 +1,140 @@ +require 'spec_helper' + +describe 'User views a wiki page' 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 + + before do + project.add_master(user) + sign_in(user) + end + + context 'when wiki is empty' do + before do + visit(project_wikis_path(project)) + + click_on('New page') + + 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 + end + + it 'shows the history of a page that has a path', :js do + expect(current_path).to include('one/two/three-test') + + click_on('Three') + click_on('Page history') + + expect(current_path).to include('one/two/three-test') + + page.within(:css, '.nav-text') do + expect(page).to have_content('History') + end + end + + 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') + + click_on('Three') + + expect(find('.nav-text')).to have_content('Three') + + click_on('Edit') + + expect(current_path).to include('one/two/three-test') + expect(page).to have_content('Edit Page') + + fill_in('Content', with: 'Updated Wiki Content') + + click_on('Save changes') + click_on('Page history') + + page.within(:css, '.nav-text') do + expect(page).to have_content('History') + end + + find('a[href*="?version_id"]') + end + end + + context 'when a page does not have history' do + before do + visit(project_wiki_path(project, wiki_page)) + end + + 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 + + it 'shows a file stored in a page' do + file = Gollum::File.new(project.wiki) + + allow_any_instance_of(Gollum::Wiki).to receive(:file).with('image.jpg', 'master', true).and_return(file) + allow_any_instance_of(Gollum::File).to receive(:mime_type).and_return('image/jpeg') + + expect(page).to have_xpath('//img[@data-src="image.jpg"]') + expect(page).to have_link('image', href: "#{project.wiki.wiki_base_path}/image.jpg") + + click_on('image') + + 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 + + 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") + + click_on('image') + + expect(current_path).to match('wikis/image.jpg') + expect(page).to have_content('New Wiki Page') + expect(page).to have_content('Create page') + end + end + + context 'when a page has history' do + before do + wiki_page.update(message: 'updated home', content: 'updated [some link](other-page)') + end + + it 'shows the page history' do + visit(project_wiki_path(project, wiki_page)) + + expect(page).to have_selector('a.btn', text: 'Edit') + + 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') + 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 + end + + it 'opens a default wiki page', :js do + visit(project_path(project)) + + find('.shortcuts-wiki').trigger('click') + + expect(page).to have_content('Home ยท Create Page') + end +end |