Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-11-01 00:06:28 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-11-01 00:06:28 +0300
commit8f210aebe1d740e8ee194f171f1f33a6e1fba313 (patch)
treef43c545801bb96fd0737f18493fb30ab92972627 /spec/features/projects/wiki
parent996f700997805b3590da8d8afdd19d193989078a (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/features/projects/wiki')
-rw-r--r--spec/features/projects/wiki/markdown_preview_spec.rb170
-rw-r--r--spec/features/projects/wiki/user_creates_wiki_page_spec.rb219
-rw-r--r--spec/features/projects/wiki/user_deletes_wiki_page_spec.rb2
-rw-r--r--spec/features/projects/wiki/user_updates_wiki_page_spec.rb77
-rw-r--r--spec/features/projects/wiki/user_views_wiki_page_spec.rb31
-rw-r--r--spec/features/projects/wiki/user_views_wiki_pages_spec.rb172
6 files changed, 346 insertions, 325 deletions
diff --git a/spec/features/projects/wiki/markdown_preview_spec.rb b/spec/features/projects/wiki/markdown_preview_spec.rb
index a56b3e4955a..5c6b04a7141 100644
--- a/spec/features/projects/wiki/markdown_preview_spec.rb
+++ b/spec/features/projects/wiki/markdown_preview_spec.rb
@@ -4,54 +4,164 @@ require 'spec_helper'
describe 'Projects > Wiki > User previews markdown changes', :js do
set(:user) { create(:user) }
- set(:project) { create(:project, :wiki_repo, namespace: user.namespace) }
- let(:project_wiki) { ProjectWiki.new(project, user) }
+ let(:project) { create(:project, :wiki_repo, namespace: user.namespace) }
+ let(:wiki_page) { create(:wiki_page, wiki: project.wiki, attrs: { title: 'home', content: '[some link](other-page)' }) }
+ let(:wiki_content) do
+ <<-HEREDOC
+[regular link](regular)
+[relative link 1](../relative)
+[relative link 2](./relative)
+[relative link 3](./e/f/relative)
+[spaced link](title with spaces)
+ HEREDOC
+ end
before do
project.add_maintainer(user)
+
sign_in(user)
- init_home!
end
- def init_home!
- create(:wiki_page, wiki: project.wiki, attrs: { title: 'home', content: '[some link](other-page)' })
- end
+ context "while creating a new wiki page" do
+ context "when there are no spaces or hyphens in the page name" do
+ it "rewrites relative links as expected" do
+ create_wiki_page('a/b/c/d', content: wiki_content)
- def fill_in_content!
- page.within '.wiki-form' do
- fill_in :wiki_page_content, with: wiki_content
+ expect(page).to have_content("regular link")
+
+ expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/regular\">regular link</a>")
+ expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a/b/relative\">relative link 1</a>")
+ expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a/b/c/relative\">relative link 2</a>")
+ expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a/b/c/e/f/relative\">relative link 3</a>")
+ expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/title%20with%20spaces\">spaced link</a>")
+ end
end
- end
- def show_preview!
- page.within '.wiki-form' do
- click_on 'Preview'
+ context "when there are spaces in the page name" do
+ it "rewrites relative links as expected" do
+ create_wiki_page('a page/b page/c page/d page', content: wiki_content)
+
+ expect(page).to have_content("regular link")
+
+ expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/regular\">regular link</a>")
+ expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/relative\">relative link 1</a>")
+ expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/c-page/relative\">relative link 2</a>")
+ expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/c-page/e/f/relative\">relative link 3</a>")
+ expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/title%20with%20spaces\">spaced link</a>")
+ end
end
- end
- context 'when writing a new page' do
- let(:new_wiki_path) { 'a/b/c/d' }
- let(:wiki_content) { 'Some [awesome wiki](content)' }
+ context "when there are hyphens in the page name" do
+ it "rewrites relative links as expected" do
+ create_wiki_page('a-page/b-page/c-page/d-page', content: wiki_content)
- it 'can show a preview of markdown content' do
- visit project_wiki_pages_new_path(project, id: new_wiki_path)
- fill_in_content!
- show_preview!
+ expect(page).to have_content("regular link")
- expect(page).to have_link('awesome wiki')
+ expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/regular\">regular link</a>")
+ expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/relative\">relative link 1</a>")
+ expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/c-page/relative\">relative link 2</a>")
+ expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/c-page/e/f/relative\">relative link 3</a>")
+ expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/title%20with%20spaces\">spaced link</a>")
+ end
end
end
- context 'when editing an existing page' do
- let(:wiki_content) { 'Some [bemusing](content)' }
- let(:wiki_page) { create(:wiki_page, wiki: project_wiki) }
+ context "while editing a wiki page" do
+ context "when there are no spaces or hyphens in the page name" do
+ it "rewrites relative links as expected" do
+ create_wiki_page('a/b/c/d')
+ click_link 'Edit'
+
+ fill_in :wiki_content, with: wiki_content
+ click_on "Preview"
+
+ expect(page).to have_content("regular link")
+
+ expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/regular\">regular link</a>")
+ expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a/b/relative\">relative link 1</a>")
+ expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a/b/c/relative\">relative link 2</a>")
+ expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a/b/c/e/f/relative\">relative link 3</a>")
+ expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/title%20with%20spaces\">spaced link</a>")
+ end
+ end
+
+ context "when there are spaces in the page name" do
+ it "rewrites relative links as expected" do
+ create_wiki_page('a page/b page/c page/d page')
+ click_link 'Edit'
+
+ fill_in :wiki_content, with: wiki_content
+ click_on "Preview"
+
+ expect(page).to have_content("regular link")
+
+ expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/regular\">regular link</a>")
+ expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/relative\">relative link 1</a>")
+ expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/c-page/relative\">relative link 2</a>")
+ expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/c-page/e/f/relative\">relative link 3</a>")
+ expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/title%20with%20spaces\">spaced link</a>")
+ end
+ end
+
+ context "when there are hyphens in the page name" do
+ it "rewrites relative links as expected" do
+ create_wiki_page('a-page/b-page/c-page/d-page')
+ click_link 'Edit'
+
+ fill_in :wiki_content, with: wiki_content
+ click_on "Preview"
- it 'can show a preview of markdown content, when writing' do
- visit project_wiki_edit_path(project, wiki_page)
- fill_in_content!
- show_preview!
+ expect(page).to have_content("regular link")
- expect(page).to have_link('bemusing')
+ expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/regular\">regular link</a>")
+ expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/relative\">relative link 1</a>")
+ expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/c-page/relative\">relative link 2</a>")
+ expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/c-page/e/f/relative\">relative link 3</a>")
+ expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/title%20with%20spaces\">spaced link</a>")
+ end
end
+
+ context 'when rendering the preview' do
+ it 'renders content with CommonMark' do
+ create_wiki_page('a-page/b-page/c-page/common-mark')
+ click_link 'Edit'
+
+ fill_in :wiki_content, with: "1. one\n - sublist\n"
+ click_on "Preview"
+
+ # the above generates two separate lists (not embedded) in CommonMark
+ expect(page).to have_content("sublist")
+ expect(page).not_to have_xpath("//ol//li//ul")
+ end
+ end
+ end
+
+ it "does not linkify double brackets inside code blocks as expected" do
+ wiki_content = <<-HEREDOC
+ `[[do_not_linkify]]`
+ ```
+ [[also_do_not_linkify]]
+ ```
+ HEREDOC
+
+ create_wiki_page('linkify_test', wiki_content)
+
+ expect(page).to have_content("do_not_linkify")
+
+ expect(page.html).to include('[[do_not_linkify]]')
+ expect(page.html).to include('[[also_do_not_linkify]]')
+ end
+
+ private
+
+ def create_wiki_page(path, content = 'content')
+ visit project_wiki_path(project, wiki_page)
+
+ click_link 'New page'
+
+ fill_in :wiki_title, with: path
+ fill_in :wiki_content, with: content
+
+ click_button 'Create page'
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 6b651ccb67a..56d0518015d 100644
--- a/spec/features/projects/wiki/user_creates_wiki_page_spec.rb
+++ b/spec/features/projects/wiki/user_creates_wiki_page_spec.rb
@@ -3,15 +3,9 @@
require "spec_helper"
describe "User creates wiki page" do
- include CapybaraHelpers
- include WikiHelpers
-
- set(:user) { create(:user) }
-
- let(:project) { create(:project) }
+ let(:user) { create(:user) }
let(:wiki) { ProjectWiki.new(project, user) }
- let(:new_page) { WikiPage.new(wiki) }
- let(:message_field) { form_field_name(new_page, :message) }
+ let(:project) { create(:project) }
before do
project.add_maintainer(user)
@@ -19,76 +13,36 @@ describe "User creates wiki page" do
sign_in(user)
end
- def start_writing(page_path)
- click_link("New page")
- fill_in(:wiki_page_title, with: page_path)
- end
-
- def create_page(attrs = {})
- page.within(".wiki-form") do
- attrs.each do |k, v|
- fill_in("wiki_page_#{k}".to_sym, with: v)
- end
- end
- click_on("Create page")
- end
-
- shared_examples 'updates commit message' do
- describe 'commit message', :js do
- it "has `Create home` as a commit message" do
- wait_for_requests
-
- expect(page).to have_field(message_field, with: "Create home")
- end
- end
- end
-
context "when wiki is empty" do
before do
visit(project_wikis_path(project))
click_link "Create your first page"
- find('.wiki-form')
end
context "in a user namespace" do
let(:project) { create(:project, :wiki_repo, namespace: user.namespace) }
- let(:wiki_page_content) { '' }
it "shows validation error message" do
- create_page
-
- expect(page)
- .to have_content("The form contains the following error:")
- .and have_content("Content can't be blank")
- .and have_css('.wiki-form')
- .and have_css('.qa-create-page-button')
- end
-
- it 'offers to create pages that do not yet exist' do
- create_page(content: "[link test](test)")
+ page.within(".wiki-form") do
+ fill_in(:wiki_content, with: "")
- expect(page)
- .to have_content("Home")
- .and have_content("link test")
+ click_on("Create page")
+ end
- click_link("link test")
+ expect(page).to have_content("The form contains the following error:").and have_content("Content can't be blank")
- expect(page).to have_content("Create New Page")
- end
+ page.within(".wiki-form") do
+ fill_in(:wiki_content, with: "[link test](test)")
- it "has a link to the parent directory in the pages sidebar" do
- wiki_full_path = "one/two/three-test"
- create_page(title: wiki_full_path, content: 'wiki content')
+ click_on("Create page")
+ end
- wiki_page = wiki.find_page(wiki_full_path)
- expect(wiki_page).to be_present
- dir = wiki.find_dir(wiki_page.directory)
- expect(dir).to be_present
+ expect(page).to have_content("Home").and have_content("link test")
- expect(current_path).to include(wiki_full_path)
+ click_link("link test")
- expect(page).to have_link(dir.slug, href: project_wiki_dir_path(project, dir))
+ expect(page).to have_content("Create New Page")
end
it "shows non-escaped link in the pages list", :quarantine do
@@ -104,17 +58,19 @@ describe "User creates wiki page" do
expect(page).to have_xpath("//a[@href='/#{project.full_path}/wikis/one/two/three-test']")
end
- it_behaves_like 'updates commit message'
+ it "has `Create home` as a commit message", :js do
+ wait_for_requests
+
+ expect(page).to have_field("wiki[message]", with: "Create home")
+ end
it "creates a page from the home page" do
- page_content = <<~WIKI_CONTENT
- [test](test)
- [GitLab API doc](api)
- [Rake tasks](raketasks)
- # Wiki header
- WIKI_CONTENT
+ fill_in(:wiki_content, with: "[test](test)\n[GitLab API doc](api)\n[Rake tasks](raketasks)\n# Wiki header\n")
+ fill_in(:wiki_message, with: "Adding links to wiki")
- create_page(content: page_content, message: "Adding links to wiki")
+ page.within(".wiki-form") do
+ click_button("Create page")
+ end
expect(current_path).to eq(project_wiki_path(project, "home"))
expect(page).to have_content("test GitLab API doc Rake tasks Wiki header")
@@ -155,7 +111,7 @@ describe "User creates wiki page" do
end
end
- it "creates ASCIIdoc wiki with LaTeX blocks", :js do
+ it "creates ASCII wiki with LaTeX blocks", :js do
stub_application_setting(plantuml_url: "http://localhost", plantuml_enabled: true)
ascii_content = <<~MD
@@ -176,25 +132,37 @@ describe "User creates wiki page" do
stem:[2+2] is 4
MD
- find("#wiki_page_format option[value=asciidoc]").select_option
+ find("#wiki_format option[value=asciidoc]").select_option
+
+ fill_in(:wiki_content, with: ascii_content)
- create_page(content: ascii_content)
+ page.within(".wiki-form") do
+ click_button("Create page")
+ end
page.within ".md" do
expect(page).to have_selector(".katex", count: 3).and have_content("2+2 is 4")
end
end
- it_behaves_like 'wiki file attachments'
+ it_behaves_like 'wiki file attachments', :quarantine
end
- context "in a group namespace" do
+ context "in a group namespace", :js do
let(:project) { create(:project, :wiki_repo, namespace: create(:group, :public)) }
- it_behaves_like 'updates commit message'
+ it "has `Create home` as a commit message" do
+ wait_for_requests
- it "creates a page from the home page" do
- create_page(content: "My awesome wiki!")
+ expect(page).to have_field("wiki[message]", with: "Create home")
+ end
+
+ it "creates a page from the home page", :quarantine 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")
.and have_content("Last edited by #{user.name}")
@@ -210,37 +178,76 @@ describe "User creates wiki page" do
visit(project_wikis_path(project))
end
- shared_examples 'creates page by slug' do |slug, unslug|
- it "creates #{slug}" do
- start_writing(slug)
+ context "in a user namespace" do
+ let(:project) { create(:project, :wiki_repo, namespace: user.namespace) }
- # Commit message field should have correct value.
- expect(page).to have_field(message_field, with: "Create #{unslug}")
+ context "via the `new wiki page` page" do
+ it "creates a page with a single word" do
+ click_link("New page")
- create_page(content: "My awesome wiki!")
+ page.within(".wiki-form") do
+ fill_in(:wiki_title, with: "foo")
+ fill_in(:wiki_content, with: "My awesome wiki!")
+ end
- expect(page).to have_content(unslug)
- .and have_content("Last edited by #{user.name}")
- .and have_content("My awesome wiki!")
- end
- end
+ # Commit message field should have correct value.
+ expect(page).to have_field("wiki[message]", with: "Create foo")
- context "in a user namespace" do
- let(:project) { create(:project, :wiki_repo, namespace: user.namespace) }
+ click_button("Create page")
- context "via the `new wiki page` page" do
- include_examples 'creates page by slug', 'foo', 'foo'
- include_examples 'creates page by slug', 'Spaces in the name', 'Spaces in the name'
- include_examples 'creates page by slug', 'Hyphens-in-the-name', 'Hyphens in the name'
+ expect(page).to have_content("foo")
+ .and have_content("Last edited by #{user.name}")
+ .and have_content("My awesome wiki!")
+ end
+
+ it "creates a page with spaces in the name" do
+ click_link("New page")
+
+ page.within(".wiki-form") do
+ fill_in(:wiki_title, with: "Spaces in the name")
+ fill_in(:wiki_content, with: "My awesome wiki!")
+ end
+
+ # Commit message field should have correct value.
+ expect(page).to have_field("wiki[message]", with: "Create Spaces in the name")
+
+ click_button("Create page")
+
+ expect(page).to have_content("Spaces in the name")
+ .and have_content("Last edited by #{user.name}")
+ .and have_content("My awesome wiki!")
+ end
+
+ it "creates a page with hyphens in the name" do
+ click_link("New page")
+
+ page.within(".wiki-form") do
+ fill_in(:wiki_title, with: "hyphens-in-the-name")
+ fill_in(:wiki_content, with: "My awesome wiki!")
+ 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")
+ end
+
+ expect(page).to have_content("hyphens in the name")
+ .and have_content("Last edited by #{user.name}")
+ .and have_content("My awesome wiki!")
+ end
end
it "shows the emoji autocompletion dropdown" do
- start_writing('text-autocomplete')
+ click_link("New page")
page.within(".wiki-form") do
- find("#wiki_page_content").native.send_keys("")
+ find("#wiki_content").native.send_keys("")
- fill_in(:wiki_page_content, with: ":")
+ fill_in(:wiki_content, with: ":")
end
expect(page).to have_selector(".atwho-view")
@@ -251,9 +258,23 @@ describe "User creates wiki page" do
let(:project) { create(:project, :wiki_repo, namespace: create(:group, :public)) }
context "via the `new wiki page` page" do
- include_examples 'creates page by slug', 'foo', 'foo'
- include_examples 'creates page by slug', 'Spaces in the name', 'Spaces in the name'
- include_examples 'creates page by slug', 'Hyphens-in-the-name', 'Hyphens in the name'
+ it "creates a page" do
+ click_link("New page")
+
+ page.within(".wiki-form") do
+ fill_in(:wiki_title, with: "foo")
+ fill_in(:wiki_content, with: "My awesome wiki!")
+ end
+
+ # Commit message field should have correct value.
+ expect(page).to have_field("wiki[message]", with: "Create foo")
+
+ click_button("Create page")
+
+ expect(page).to have_content("foo")
+ .and have_content("Last edited by #{user.name}")
+ .and have_content("My awesome wiki!")
+ end
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
index 9b9d3100bf5..38e5e292064 100644
--- a/spec/features/projects/wiki/user_deletes_wiki_page_spec.rb
+++ b/spec/features/projects/wiki/user_deletes_wiki_page_spec.rb
@@ -6,7 +6,6 @@ describe 'User deletes wiki page', :js do
let(:user) { create(:user) }
let(:project) { create(:project, :wiki_repo, namespace: user.namespace) }
let(:wiki_page) { create(:wiki_page, wiki: project.wiki) }
- let(:project_wiki) { ProjectWiki.new(project, user) }
before do
sign_in(user)
@@ -19,6 +18,5 @@ describe 'User deletes wiki page', :js do
find('.modal-footer .btn-danger').click
expect(page).to have_content('Page was successfully deleted')
- expect(project_wiki.find_page(wiki_page.slug)).to be nil
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 5ab44e83f73..3f3711f9eb8 100644
--- a/spec/features/projects/wiki/user_updates_wiki_page_spec.rb
+++ b/spec/features/projects/wiki/user_updates_wiki_page_spec.rb
@@ -10,13 +10,6 @@ describe 'User updates wiki page' do
sign_in(user)
end
- def create_page(attrs = {})
- page.within('.wiki-form') do
- attrs.each { |k, v| fill_in("wiki_page_#{k}".to_sym, with: v) }
- click_on('Create page')
- end
- end
-
context 'when wiki is empty' do
before do
visit(project_wikis_path(project))
@@ -35,7 +28,12 @@ describe 'User updates wiki page' do
end
it 'updates a page that has a path', :js do
- create_page(title: 'one/two/three-test', content: 'wiki content')
+ fill_in(:wiki_title, with: 'one/two/three-test')
+
+ 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')
@@ -74,9 +72,9 @@ describe 'User updates wiki page' do
it 'updates a page', :js do
# Commit message field should have correct value.
- expect(page).to have_field('wiki_page[message]', with: 'Update home')
+ expect(page).to have_field('wiki[message]', with: 'Update home')
- fill_in(:wiki_page_content, with: 'My awesome wiki!')
+ fill_in(:wiki_content, with: 'My awesome wiki!')
click_button('Save changes')
expect(page).to have_content('Home')
@@ -85,31 +83,31 @@ describe 'User updates wiki page' do
end
it 'updates the commit message as the title is changed', :js do
- fill_in(:wiki_page_title, with: 'Wiki title')
+ fill_in(:wiki_title, with: 'Wiki title')
- expect(page).to have_field('wiki_page[message]', with: 'Update Wiki title')
+ expect(page).to have_field('wiki[message]', with: 'Update Wiki title')
end
it 'does not allow XSS', :js do
- fill_in(:wiki_page_title, with: '<script>')
+ fill_in(:wiki_title, with: '<script>')
- expect(page).to have_field('wiki_page[message]', with: 'Update &lt;script&gt;')
+ expect(page).to have_field('wiki[message]', with: 'Update &lt;script&gt;')
end
it 'shows a validation error message' do
- fill_in(:wiki_page_content, with: '')
+ 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_page_content').value).to eq('')
+ expect(find('textarea#wiki_content').value).to eq('')
end
it 'shows the emoji autocompletion dropdown', :js do
- find('#wiki_page_content').native.send_keys('')
- fill_in(:wiki_page_content, with: ':')
+ find('#wiki_content').native.send_keys('')
+ fill_in(:wiki_content, with: ':')
expect(page).to have_selector('.atwho-view')
end
@@ -145,9 +143,9 @@ describe 'User updates wiki page' do
it 'updates a page', :js do
# Commit message field should have correct value.
- expect(page).to have_field('wiki_page[message]', with: 'Update home')
+ expect(page).to have_field('wiki[message]', with: 'Update home')
- fill_in(:wiki_page_content, with: 'My awesome wiki!')
+ fill_in(:wiki_content, with: 'My awesome wiki!')
click_button('Save changes')
@@ -171,43 +169,50 @@ describe 'User updates wiki page' do
visit(project_wiki_edit_path(project, wiki_page))
end
- def edit_title!(title)
- fill_in(:wiki_page_title, with: title)
+ it 'moves the page to the root folder' do
+ fill_in(:wiki_title, with: "/#{page_name}")
click_button('Save changes')
- end
-
- it 'moves the page to the root folder' do
- edit_title!("/#{page_name}")
expect(current_path).to eq(project_wiki_path(project, page_name))
end
it 'moves the page to other dir' do
- new_page_path = "baz/quux/#{page_name}"
- edit_title!(new_page_path)
+ new_page_dir = "foo1/bar1/#{page_name}"
+
+ fill_in(:wiki_title, with: new_page_dir)
+
+ click_button('Save changes')
- expect(current_path).to eq(project_wiki_path(project, new_page_path))
+ expect(current_path).to eq(project_wiki_path(project, new_page_dir))
end
it 'remains in the same place if title has not changed' do
original_path = project_wiki_path(project, wiki_page)
- edit_title!(page_name)
+
+ fill_in(:wiki_title, with: page_name)
+
+ click_button('Save changes')
expect(current_path).to eq(original_path)
end
it 'can be moved to a different dir with a different name' do
- new_page_path = "quux/baz/new_page_name"
- edit_title!(new_page_path)
+ new_page_dir = "foo1/bar1/new_page_name"
+
+ fill_in(:wiki_title, with: new_page_dir)
- expect(current_path).to eq(project_wiki_path(project, new_page_path))
+ click_button('Save changes')
+
+ expect(current_path).to eq(project_wiki_path(project, new_page_dir))
end
it 'can be renamed and moved to the root folder' do
new_name = 'new_page_name'
- edit_title!("/#{new_name}")
+ fill_in(:wiki_title, with: "/#{new_name}")
+
+ click_button('Save changes')
expect(current_path).to eq(project_wiki_path(project, new_name))
end
@@ -215,7 +220,9 @@ describe 'User updates wiki page' do
it 'squishes the title before creating the page' do
new_page_dir = " foo1 / bar1 / #{page_name} "
- edit_title!(new_page_dir)
+ fill_in(:wiki_title, with: new_page_dir)
+
+ click_button('Save changes')
expect(current_path).to eq(project_wiki_path(project, "foo1/bar1/#{page_name}"))
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 af8f86106d9..77e725e7f11 100644
--- a/spec/features/projects/wiki/user_views_wiki_page_spec.rb
+++ b/spec/features/projects/wiki/user_views_wiki_page_spec.rb
@@ -8,11 +8,10 @@ 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_content) { "Look at this [image](#{path})\n\n ![alt text](#{path})" }
let(:wiki_page) do
create(:wiki_page,
wiki: project.wiki,
- attrs: { title: 'home', content: wiki_content })
+ attrs: { title: 'home', content: "Look at this [image](#{path})\n\n ![alt text](#{path})" })
end
before do
@@ -20,18 +19,17 @@ describe 'User views a wiki page' do
sign_in(user)
end
- def create_page(attrs = {})
- page.within('.wiki-form') do
- attrs.each { |k, v| fill_in("wiki_page_#{k}".to_sym, with: v) }
- click_on('Create page')
- end
- end
-
context 'when wiki is empty' do
before do
visit(project_wikis_path(project))
click_link "Create your first page"
- create_page(title: 'one/two/three-test', content: 'wiki content')
+
+ fill_in(:wiki_title, with: 'one/two/three-test')
+
+ 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
@@ -85,27 +83,24 @@ describe 'User views a wiki page' do
context 'shows a file stored in a page' do
let(:path) { upload_file_to_wiki(project, user, 'dk.png') }
- let(:image_path) { project_wiki_path(project, path) }
it do
- expect(page).to have_xpath("//img[@data-src='#{image_path}']")
- expect(page).to have_link('image', href: "#{image_path}")
+ 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}")
click_on('image')
- expect(current_path).to match(path)
+ expect(current_path).to match("wikis/#{path}")
expect(page).not_to have_xpath('/html') # Page should render the image which means there is no html involved
end
end
it 'shows the creation page if file does not exist' do
- href = project_wiki_path(project, path)
-
- expect(page).to have_link('image', href: href)
+ expect(page).to have_link('image', href: "#{project.wiki.wiki_base_path}/#{path}")
click_on('image')
- expect(current_path).to match(href)
+ expect(current_path).to match("wikis/#{path}")
expect(page).to have_content('Create New Page')
end
end
diff --git a/spec/features/projects/wiki/user_views_wiki_pages_spec.rb b/spec/features/projects/wiki/user_views_wiki_pages_spec.rb
index adb59c891c6..6740df1d4ed 100644
--- a/spec/features/projects/wiki/user_views_wiki_pages_spec.rb
+++ b/spec/features/projects/wiki/user_views_wiki_pages_spec.rb
@@ -7,7 +7,6 @@ describe 'User views wiki pages' do
let(:user) { create(:user) }
let(:project) { create(:project, :wiki_repo, namespace: user.namespace) }
- let(:project_wiki) { ProjectWiki.new(project, user) }
let!(:wiki_page1) do
create(:wiki_page, wiki: project.wiki, attrs: { title: '3 home', content: '3' })
@@ -18,182 +17,73 @@ describe 'User views wiki pages' do
let!(:wiki_page3) do
create(:wiki_page, wiki: project.wiki, attrs: { title: '2 home', content: '2' })
end
- let!(:wiki_page4) do
- create(:wiki_page, wiki: project.wiki, attrs: { title: 'sub-folder/0', content: 'a' })
- end
- let!(:wiki_page5) do
- create(:wiki_page, wiki: project.wiki, attrs: { title: 'sub-folder/b', content: 'b' })
- end
-
- let(:page_link_selector) { 'a' }
let(:pages) do
- page.all(".wiki-pages-list li #{page_link_selector}")
+ page.find('.wiki-pages-list').all('li').map { |li| li.find('a') }
end
- let(:wikis_allow_change_nesting) { false }
before do
- stub_feature_flags(wikis_allow_change_nesting: wikis_allow_change_nesting)
project.add_maintainer(user)
sign_in(user)
visit(project_wikis_pages_path(project))
end
- def sort_desc!
- page.within('.wiki-sort-dropdown') do
- page.find('.qa-reverse-sort').click
- end
- end
-
- def sort_by_created_at!
- page.within('.wiki-sort-dropdown') do
- click_button('Title')
- click_link('Created date')
- end
- end
-
- shared_examples 'correctly_sorted_pages' do
- it 'has pages displayed in correct order' do
- displayed_texts = pages.map(&:text)
- expect(displayed_texts).to eq expected_sequence.map(&:title)
- end
- end
-
context 'ordered by title' do
- let(:sub_folder) { project_wiki.find_dir('sub-folder') }
+ let(:pages_ordered_by_title) { [wiki_page2, wiki_page3, wiki_page1] }
- context 'default display settings' do
- context 'asc' do
- let(:expected_sequence) { [wiki_page2, wiki_page3, wiki_page1, sub_folder] }
-
- it_behaves_like 'correctly_sorted_pages'
- end
-
- context 'desc' do
- before do
- sort_desc!
+ context 'asc' do
+ it 'pages are displayed in direct order' do
+ pages.each.with_index do |page_title, index|
+ expect(page_title.text).to eq(pages_ordered_by_title[index].title)
end
-
- let(:expected_sequence) { [sub_folder, wiki_page1, wiki_page3, wiki_page2] }
-
- it_behaves_like 'correctly_sorted_pages'
- end
- end
-
- context 'changing nesting is disabled' do
- let(:wikis_allow_change_nesting) { false }
-
- it 'does not display a nesting controller' do
- expect(page).not_to have_css('.wiki-nesting-dropdown')
end
end
- context 'changing nesting is enabled' do
- let(:wikis_allow_change_nesting) { true }
-
- it 'displays a nesting controller' do
- expect(page).to have_css('.wiki-nesting-dropdown')
- end
-
- context 'tree' do
- before do
- page.within('.wiki-nesting-dropdown') do
- click_link 'Show folder contents'
- end
- end
-
- context 'asc' do
- let(:expected_sequence) { [wiki_page2, wiki_page3, wiki_page1, sub_folder, wiki_page4, wiki_page5] }
-
- it_behaves_like 'correctly_sorted_pages'
- end
-
- context 'desc' do
- before do
- sort_desc!
- end
-
- let(:expected_sequence) { [sub_folder, wiki_page5, wiki_page4, wiki_page1, wiki_page3, wiki_page2] }
-
- it_behaves_like 'correctly_sorted_pages'
- end
- end
-
- context 'nested' do
- before do
- page.within('.wiki-nesting-dropdown') do
- click_link 'Hide folder contents'
- end
- end
-
- context 'asc' do
- let(:expected_sequence) { [wiki_page2, wiki_page3, wiki_page1, sub_folder] }
-
- it_behaves_like 'correctly_sorted_pages'
- end
-
- context 'desc' do
- before do
- sort_desc!
- end
-
- let(:expected_sequence) { [sub_folder, wiki_page1, wiki_page3, wiki_page2] }
-
- it_behaves_like 'correctly_sorted_pages'
+ context 'desc' do
+ before do
+ page.within('.wiki-sort-dropdown') do
+ page.find('.rspec-reverse-sort').click
end
end
- context 'flat' do
- before do
- page.within('.wiki-nesting-dropdown') do
- click_link 'Show files separately'
- end
- end
-
- let(:page_link_selector) { 'a.wiki-page-title' }
-
- context 'asc' do
- let(:expected_sequence) { [wiki_page2, wiki_page3, wiki_page1, wiki_page4, wiki_page5] }
-
- it_behaves_like 'correctly_sorted_pages'
- end
-
- context 'desc' do
- before do
- sort_desc!
- end
-
- let(:expected_sequence) { [wiki_page5, wiki_page4, wiki_page1, wiki_page3, wiki_page2] }
-
- it_behaves_like 'correctly_sorted_pages'
+ it 'pages are displayed in reversed order' do
+ pages.reverse_each.with_index do |page_title, index|
+ expect(page_title.text).to eq(pages_ordered_by_title[index].title)
end
end
end
end
context 'ordered by created_at' do
- let(:pages_ordered_by_created_at) { [wiki_page1, wiki_page2, wiki_page3, wiki_page4, wiki_page5] }
+ let(:pages_ordered_by_created_at) { [wiki_page1, wiki_page2, wiki_page3] }
before do
- sort_by_created_at!
+ page.within('.wiki-sort-dropdown') do
+ click_button('Title')
+ click_link('Created date')
+ end
end
- let(:page_link_selector) { 'a.wiki-page-title' }
-
context 'asc' do
- let(:expected_sequence) { [wiki_page1, wiki_page2, wiki_page3, wiki_page4, wiki_page5] }
-
- it_behaves_like 'correctly_sorted_pages'
+ it 'pages are displayed in direct order' do
+ pages.each.with_index do |page_title, index|
+ expect(page_title.text).to eq(pages_ordered_by_created_at[index].title)
+ end
+ end
end
context 'desc' do
before do
- sort_desc!
+ page.within('.wiki-sort-dropdown') do
+ page.find('.rspec-reverse-sort').click
+ end
end
- let(:expected_sequence) { [wiki_page5, wiki_page4, wiki_page3, wiki_page2, wiki_page1] }
-
- it_behaves_like 'correctly_sorted_pages'
+ it 'pages are displayed in reversed order' do
+ pages.reverse_each.with_index do |page_title, index|
+ expect(page_title.text).to eq(pages_ordered_by_created_at[index].title)
+ end
+ end
end
end
end