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

160 lines
6.3 KiB
Ruby
Raw Normal View History

2016-08-24 12:49:21 +05:30
require 'spec_helper'
2017-09-10 17:25:29 +05:30
feature 'Projects > Wiki > User previews markdown changes', js: true do
2016-08-24 12:49:21 +05:30
let(:user) { create(:user) }
let(:project) { create(:project, namespace: user.namespace) }
let(:wiki_content) do
<<-HEREDOC
[regular link](regular)
[relative link 1](../relative)
[relative link 2](./relative)
[relative link 3](./e/f/relative)
HEREDOC
end
background do
project.team << [user, :master]
WikiPages::CreateService.new(project, user, title: 'home', content: 'Home page').execute
2017-09-10 17:25:29 +05:30
sign_in(user)
visit project_path(project)
find('.shortcuts-wiki').trigger('click')
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
2017-09-10 17:25:29 +05:30
find('.add-new-wiki').trigger('click')
2017-08-17 22:00:37 +05:30
page.within '#modal-new-wiki' do
fill_in :new_wiki_path, with: 'a/b/c/d'
click_button 'Create page'
end
2016-08-24 12:49:21 +05:30
2017-08-17 22:00:37 +05:30
page.within '.wiki-form' do
fill_in :wiki_content, with: wiki_content
click_on "Preview"
end
2016-08-24 12:49:21 +05:30
expect(page).to have_content("regular link")
2017-09-10 17:25:29 +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>")
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
2017-08-17 22:00:37 +05:30
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-08-24 12:49:21 +05:30
2017-08-17 22:00:37 +05:30
page.within '.wiki-form' do
fill_in :wiki_content, with: wiki_content
click_on "Preview"
end
2016-08-24 12:49:21 +05:30
expect(page).to have_content("regular link")
2017-09-10 17:25:29 +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>")
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
2017-08-17 22:00:37 +05:30
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-09-10 17:25:29 +05:30
2017-08-17 22:00:37 +05:30
page.within '.wiki-form' do
fill_in :wiki_content, with: wiki_content
click_on "Preview"
end
2016-08-24 12:49:21 +05:30
expect(page).to have_content("regular link")
2017-09-10 17:25:29 +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>")
2016-08-24 12:49:21 +05:30
end
end
end
context "while editing a wiki page" do
def create_wiki_page(path)
2017-09-10 17:25:29 +05:30
find('.add-new-wiki').trigger('click')
2017-08-17 22:00:37 +05:30
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-08-24 12:49:21 +05:30
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-09-10 17:25:29 +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>")
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
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-09-10 17:25:29 +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>")
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
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-09-10 17:25:29 +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>")
2016-08-24 12:49:21 +05:30
end
end
end
end