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/markdown_preview_spec.rb
parent996f700997805b3590da8d8afdd19d193989078a (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/features/projects/wiki/markdown_preview_spec.rb')
-rw-r--r--spec/features/projects/wiki/markdown_preview_spec.rb170
1 files changed, 140 insertions, 30 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