diff options
author | Vitaliy @blackst0ne Klachkov <blackst0ne.ru@gmail.com> | 2017-09-11 12:48:32 +0300 |
---|---|---|
committer | Vitaliy @blackst0ne Klachkov <blackst0ne.ru@gmail.com> | 2017-09-11 12:48:32 +0300 |
commit | 8cbefe9d67e79f548390b929054cc333e9d7b408 (patch) | |
tree | 8dcdd39a4741b449a5938457f2d6086f27e1eb65 /spec/features/projects/wiki | |
parent | 5d952f756bcf0355fc5d86d819dfc6913c0ae351 (diff) |
Replace 'project/wiki.feature' spinach test with an rspec analog
Diffstat (limited to 'spec/features/projects/wiki')
5 files changed, 408 insertions, 174 deletions
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 |