debian-mirror-gitlab/spec/features/projects/wiki/markdown_preview_spec.rb

168 lines
7.1 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2016-08-24 12:49:21 +05:30
require 'spec_helper'
2018-11-08 19:23:39 +05:30
describe 'Projects > Wiki > User previews markdown changes', :js do
2020-04-08 14:13:33 +05:30
let_it_be(:user) { create(:user) }
2018-10-15 14:42:47 +05:30
let(:project) { create(:project, :wiki_repo, namespace: user.namespace) }
2020-05-24 23:13:21 +05:30
let(:wiki_page) { create(:wiki_page, wiki: project.wiki, title: 'home', content: '[some link](other-page)') }
2016-08-24 12:49:21 +05:30
let(:wiki_content) do
<<-HEREDOC
[regular link](regular)
[relative link 1](../relative)
[relative link 2](./relative)
[relative link 3](./e/f/relative)
2018-11-08 19:23:39 +05:30
[spaced link](title with spaces)
2016-08-24 12:49:21 +05:30
HEREDOC
end
2018-11-08 19:23:39 +05:30
before do
2018-11-18 11:00:15 +05:30
project.add_maintainer(user)
2017-09-10 17:25:29 +05:30
sign_in(user)
2016-08-24 12:49:21 +05:30
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
2019-12-04 20:38:33 +05:30
create_wiki_page('a/b/c/d', content: wiki_content)
2016-08-24 12:49:21 +05:30
expect(page).to have_content("regular link")
2020-01-01 13:55:28 +05:30
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>")
2016-08-24 12:49:21 +05:30
end
end
context "when there are spaces in the page name" do
it "rewrites relative links as expected" do
2019-12-04 20:38:33 +05:30
create_wiki_page('a page/b page/c page/d page', content: wiki_content)
2016-08-24 12:49:21 +05:30
expect(page).to have_content("regular link")
2020-01-01 13:55:28 +05:30
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>")
2016-08-24 12:49:21 +05:30
end
end
context "when there are hyphens in the page name" do
it "rewrites relative links as expected" do
2019-12-04 20:38:33 +05:30
create_wiki_page('a-page/b-page/c-page/d-page', content: wiki_content)
2016-08-24 12:49:21 +05:30
expect(page).to have_content("regular link")
2020-01-01 13:55:28 +05:30
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>")
2016-08-24 12:49:21 +05:30
end
end
end
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
2019-12-04 20:38:33 +05:30
create_wiki_page('a/b/c/d')
2016-08-24 12:49:21 +05:30
click_link 'Edit'
fill_in :wiki_content, with: wiki_content
click_on "Preview"
expect(page).to have_content("regular link")
2020-01-01 13:55:28 +05:30
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>")
2016-08-24 12:49:21 +05:30
end
end
context "when there are spaces in the page name" do
it "rewrites relative links as expected" do
2019-12-04 20:38:33 +05:30
create_wiki_page('a page/b page/c page/d page')
2016-08-24 12:49:21 +05:30
click_link 'Edit'
fill_in :wiki_content, with: wiki_content
click_on "Preview"
expect(page).to have_content("regular link")
2020-01-01 13:55:28 +05:30
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>")
2016-08-24 12:49:21 +05:30
end
end
context "when there are hyphens in the page name" do
it "rewrites relative links as expected" do
2019-12-04 20:38:33 +05:30
create_wiki_page('a-page/b-page/c-page/d-page')
2016-08-24 12:49:21 +05:30
click_link 'Edit'
fill_in :wiki_content, with: wiki_content
click_on "Preview"
expect(page).to have_content("regular link")
2020-01-01 13:55:28 +05:30
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>")
2016-08-24 12:49:21 +05:30
end
end
2018-11-20 20:47:30 +05:30
context 'when rendering the preview' do
it 'renders content with CommonMark' do
2019-12-04 20:38:33 +05:30
create_wiki_page('a-page/b-page/c-page/common-mark')
2018-11-20 20:47:30 +05:30
click_link 'Edit'
fill_in :wiki_content, with: "1. one\n - sublist\n"
click_on "Preview"
2019-07-07 11:18:12 +05:30
# the above generates two separate lists (not embedded) in CommonMark
2018-11-20 20:47:30 +05:30
expect(page).to have_content("sublist")
expect(page).not_to have_xpath("//ol//li//ul")
end
end
2016-08-24 12:49:21 +05:30
end
2018-11-08 19:23:39 +05:30
it "does not linkify double brackets inside code blocks as expected" do
2019-12-04 20:38:33 +05:30
wiki_content = <<-HEREDOC
`[[do_not_linkify]]`
```
[[also_do_not_linkify]]
```
HEREDOC
2018-11-08 19:23:39 +05:30
2019-12-04 20:38:33 +05:30
create_wiki_page('linkify_test', wiki_content)
2018-11-08 19:23:39 +05:30
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
2019-12-04 20:38:33 +05:30
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
2016-08-24 12:49:21 +05:30
end