Replace 'project/wiki.feature' spinach test with an rspec analog

parent 5d952f75
---
title: Replace 'project/wiki.feature' spinach test with an rspec analog
merge_request: 13856
author: Vitaliy @blackst0ne Klachkov
type: other
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
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
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
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
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 '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"
visit project_wikis_path(project)
let(:project) { create(:project, namespace: user.namespace) }
let!(:wiki_page) { create(:wiki_page, wiki: project.wiki, attrs: { title: 'home', content: 'Home page' }) }
before do
visit(project_wikis_path(project))
end
context 'in the user namespace' do
context 'in a user namespace' do
let(:project) { create(:project, namespace: user.namespace) }
context 'the home page' do
scenario 'success when the wiki content is not empty' 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')
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')
click_button 'Save changes'
click_button('Save changes')
expect(page).to have_content 'Someone edited the page the same time you did.'
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
it 'cancels edititng of a page' do
click_on('Edit')
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
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')
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
end
end
end
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
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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment