2016-07-24 23:07:46 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
describe 'Projects > Wiki > User previews markdown changes', :js do
|
2016-07-24 23:07:46 -04:00
|
|
|
let(:user) { create(:user) }
|
2018-05-04 05:45:16 -04:00
|
|
|
let(:project) { create(:project, :wiki_repo, namespace: user.namespace) }
|
2016-07-24 23:07:46 -04:00
|
|
|
let(:wiki_content) do
|
|
|
|
<<-HEREDOC
|
|
|
|
[regular link](regular)
|
|
|
|
[relative link 1](../relative)
|
|
|
|
[relative link 2](./relative)
|
|
|
|
[relative link 3](./e/f/relative)
|
2018-07-06 14:49:33 -04:00
|
|
|
[spaced link](title with spaces)
|
2016-07-24 23:07:46 -04:00
|
|
|
HEREDOC
|
|
|
|
end
|
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2017-06-09 07:12:42 -04:00
|
|
|
|
2017-06-21 19:44:10 -04:00
|
|
|
sign_in(user)
|
2016-07-24 23:07:46 -04:00
|
|
|
|
2017-07-06 12:20:50 -04:00
|
|
|
visit project_path(project)
|
2017-06-17 02:08:27 -04:00
|
|
|
find('.shortcuts-wiki').click
|
2018-05-29 03:28:49 -04:00
|
|
|
click_link "Create your first page"
|
2016-07-24 23:07:46 -04:00
|
|
|
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
|
2017-06-17 02:08:27 -04:00
|
|
|
find('.add-new-wiki').click
|
2017-04-06 09:55:11 -04:00
|
|
|
page.within '#modal-new-wiki' do
|
|
|
|
fill_in :new_wiki_path, with: 'a/b/c/d'
|
|
|
|
click_button 'Create page'
|
|
|
|
end
|
2016-07-24 23:07:46 -04:00
|
|
|
|
2017-04-06 09:55:11 -04:00
|
|
|
page.within '.wiki-form' do
|
|
|
|
fill_in :wiki_content, with: wiki_content
|
|
|
|
click_on "Preview"
|
|
|
|
end
|
2016-07-24 23:07:46 -04:00
|
|
|
|
|
|
|
expect(page).to have_content("regular link")
|
|
|
|
|
2017-07-20 05:34:09 -04:00
|
|
|
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>")
|
2018-07-06 14:49:33 -04:00
|
|
|
expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/title%20with%20spaces\">spaced link</a>")
|
2016-07-24 23:07:46 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when there are spaces in the page name" do
|
|
|
|
it "rewrites relative links as expected" do
|
2017-04-06 09:55:11 -04:00
|
|
|
click_link 'New page'
|
|
|
|
page.within '#modal-new-wiki' do
|
|
|
|
fill_in :new_wiki_path, with: 'a page/b page/c page/d page'
|
|
|
|
click_button 'Create page'
|
|
|
|
end
|
2016-07-24 23:07:46 -04:00
|
|
|
|
2017-04-06 09:55:11 -04:00
|
|
|
page.within '.wiki-form' do
|
|
|
|
fill_in :wiki_content, with: wiki_content
|
|
|
|
click_on "Preview"
|
|
|
|
end
|
2016-07-24 23:07:46 -04:00
|
|
|
|
|
|
|
expect(page).to have_content("regular link")
|
|
|
|
|
2017-07-20 05:34:09 -04:00
|
|
|
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>")
|
2018-07-06 14:49:33 -04:00
|
|
|
expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/title%20with%20spaces\">spaced link</a>")
|
2016-07-24 23:07:46 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when there are hyphens in the page name" do
|
|
|
|
it "rewrites relative links as expected" do
|
2017-04-06 09:55:11 -04:00
|
|
|
click_link 'New page'
|
|
|
|
page.within '#modal-new-wiki' do
|
|
|
|
fill_in :new_wiki_path, with: 'a-page/b-page/c-page/d-page'
|
|
|
|
click_button 'Create page'
|
|
|
|
end
|
2017-05-08 16:08:39 -04:00
|
|
|
|
2017-04-06 09:55:11 -04:00
|
|
|
page.within '.wiki-form' do
|
|
|
|
fill_in :wiki_content, with: wiki_content
|
|
|
|
click_on "Preview"
|
|
|
|
end
|
2016-07-24 23:07:46 -04:00
|
|
|
|
|
|
|
expect(page).to have_content("regular link")
|
|
|
|
|
2017-07-20 05:34:09 -04:00
|
|
|
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>")
|
2018-07-06 14:49:33 -04:00
|
|
|
expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/title%20with%20spaces\">spaced link</a>")
|
2016-07-24 23:07:46 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "while editing a wiki page" do
|
|
|
|
def create_wiki_page(path)
|
2017-06-17 02:08:27 -04:00
|
|
|
find('.add-new-wiki').click
|
2017-04-06 09:55:11 -04:00
|
|
|
|
|
|
|
page.within '#modal-new-wiki' do
|
|
|
|
fill_in :new_wiki_path, with: path
|
|
|
|
click_button 'Create page'
|
|
|
|
end
|
|
|
|
|
|
|
|
page.within '.wiki-form' do
|
|
|
|
fill_in :wiki_content, with: 'content'
|
|
|
|
click_on "Create page"
|
|
|
|
end
|
2016-07-24 23:07:46 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
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")
|
|
|
|
|
2017-07-20 05:34:09 -04:00
|
|
|
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>")
|
2018-07-06 14:49:33 -04:00
|
|
|
expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/title%20with%20spaces\">spaced link</a>")
|
2016-07-24 23:07:46 -04:00
|
|
|
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")
|
|
|
|
|
2017-07-20 05:34:09 -04:00
|
|
|
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>")
|
2018-07-06 14:49:33 -04:00
|
|
|
expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/title%20with%20spaces\">spaced link</a>")
|
2016-07-24 23:07:46 -04:00
|
|
|
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"
|
|
|
|
|
|
|
|
expect(page).to have_content("regular link")
|
|
|
|
|
2017-07-20 05:34:09 -04:00
|
|
|
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>")
|
2018-07-06 14:49:33 -04:00
|
|
|
expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/title%20with%20spaces\">spaced link</a>")
|
2016-07-24 23:07:46 -04:00
|
|
|
end
|
|
|
|
end
|
2018-09-02 11:24:27 -04:00
|
|
|
|
|
|
|
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 seperate lists (not embedded) in CommonMark
|
|
|
|
expect(page).to have_content("sublist")
|
|
|
|
expect(page).not_to have_xpath("//ol//li//ul")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders content with RedCarpet when legacy_render is set' do
|
|
|
|
wiki_page = create(:wiki_page,
|
|
|
|
wiki: project.wiki,
|
|
|
|
attrs: { title: 'home', content: "Empty content" })
|
|
|
|
visit(project_wiki_edit_path(project, wiki_page, legacy_render: 1))
|
|
|
|
|
|
|
|
fill_in :wiki_content, with: "1. one\n - sublist\n"
|
|
|
|
click_on "Preview"
|
|
|
|
|
|
|
|
# the above generates a sublist list in RedCarpet
|
|
|
|
expect(page).to have_content("sublist")
|
|
|
|
expect(page).to have_xpath("//ol//li//ul")
|
|
|
|
end
|
|
|
|
end
|
2016-07-24 23:07:46 -04:00
|
|
|
end
|
2018-05-18 16:14:31 -04:00
|
|
|
|
|
|
|
it "does not linkify double brackets inside code blocks as expected" do
|
|
|
|
click_link 'New page'
|
|
|
|
page.within '#modal-new-wiki' do
|
|
|
|
fill_in :new_wiki_path, with: 'linkify_test'
|
|
|
|
click_button 'Create page'
|
|
|
|
end
|
|
|
|
|
|
|
|
page.within '.wiki-form' do
|
|
|
|
fill_in :wiki_content, with: <<-HEREDOC
|
|
|
|
`[[do_not_linkify]]`
|
|
|
|
```
|
|
|
|
[[also_do_not_linkify]]
|
|
|
|
```
|
|
|
|
HEREDOC
|
|
|
|
click_on "Preview"
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
2016-07-24 23:07:46 -04:00
|
|
|
end
|