diff options
Diffstat (limited to 'spec/features/projects')
-rw-r--r-- | spec/features/projects/blobs/blob_show_spec.rb | 50 | ||||
-rw-r--r-- | spec/features/projects/blobs/edit_spec.rb | 34 | ||||
-rw-r--r-- | spec/features/projects/wiki/markdown_preview_spec.rb | 28 |
3 files changed, 108 insertions, 4 deletions
diff --git a/spec/features/projects/blobs/blob_show_spec.rb b/spec/features/projects/blobs/blob_show_spec.rb index 1064f72c271..2ba4d4918ff 100644 --- a/spec/features/projects/blobs/blob_show_spec.rb +++ b/spec/features/projects/blobs/blob_show_spec.rb @@ -5,8 +5,8 @@ describe 'File blob', :js do let(:project) { create(:project, :public, :repository) } - def visit_blob(path, anchor: nil, ref: 'master') - visit project_blob_path(project, File.join(ref, path), anchor: anchor) + def visit_blob(path, anchor: nil, ref: 'master', legacy_render: nil) + visit project_blob_path(project, File.join(ref, path), anchor: anchor, legacy_render: legacy_render) wait_for_requests end @@ -142,6 +142,52 @@ describe 'File blob', :js do end end + context 'Markdown rendering' do + before do + project.add_maintainer(project.creator) + + Files::CreateService.new( + project, + project.creator, + start_branch: 'master', + branch_name: 'master', + commit_message: "Add RedCarpet and CommonMark Markdown ", + file_path: 'files/commonmark/file.md', + file_content: "1. one\n - sublist\n" + ).execute + end + + context 'when rendering default markdown' do + before do + visit_blob('files/commonmark/file.md') + + wait_for_requests + end + + it 'renders using CommonMark' do + aggregate_failures do + expect(page).to have_content("sublist") + expect(page).not_to have_xpath("//ol//li//ul") + end + end + end + + context 'when rendering legacy markdown' do + before do + visit_blob('files/commonmark/file.md', legacy_render: 1) + + wait_for_requests + end + + it 'renders using RedCarpet' do + aggregate_failures do + expect(page).to have_content("sublist") + expect(page).to have_xpath("//ol//li//ul") + end + end + end + end + context 'Markdown file (stored in LFS)' do before do project.add_maintainer(project.creator) diff --git a/spec/features/projects/blobs/edit_spec.rb b/spec/features/projects/blobs/edit_spec.rb index 0e036b4ea68..d5b20605860 100644 --- a/spec/features/projects/blobs/edit_spec.rb +++ b/spec/features/projects/blobs/edit_spec.rb @@ -7,6 +7,7 @@ describe 'Editing file blob', :js do let(:merge_request) { create(:merge_request, source_project: project, source_branch: 'feature', target_branch: 'master') } let(:branch) { 'master' } let(:file_path) { project.repository.ls_files(project.repository.root_ref)[1] } + let(:readme_file_path) { 'README.md' } context 'as a developer' do let(:user) { create(:user) } @@ -20,14 +21,19 @@ describe 'Editing file blob', :js do def edit_and_commit(commit_changes: true) wait_for_requests find('.js-edit-blob').click - find('#editor') - execute_script('ace.edit("editor").setValue("class NextFeature\nend\n")') + fill_editor(content: "class NextFeature\\nend\\n") if commit_changes click_button 'Commit changes' end end + def fill_editor(content: "class NextFeature\\nend\\n") + wait_for_requests + find('#editor') + execute_script("ace.edit('editor').setValue('#{content}')") + end + context 'from MR diff' do before do visit diffs_project_merge_request_path(project, merge_request) @@ -63,6 +69,30 @@ describe 'Editing file blob', :js do expect(new_line_count).to be > 0 end end + + context 'when rendering the preview' do + it 'renders content with CommonMark' do + visit project_edit_blob_path(project, tree_join(branch, readme_file_path)) + fill_editor(content: "1. one\\n - sublist\\n") + click_link 'Preview' + wait_for_requests + + # 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 + visit project_edit_blob_path(project, tree_join(branch, readme_file_path), legacy_render: 1) + fill_editor(content: "1. one\\n - sublist\\n") + click_link 'Preview' + wait_for_requests + + # the above generates a sublist list in RedCarpet + expect(page).to have_content("sublist") + expect(page).to have_xpath("//ol//li//ul") + end + end end context 'visit blob edit' do diff --git a/spec/features/projects/wiki/markdown_preview_spec.rb b/spec/features/projects/wiki/markdown_preview_spec.rb index ed5f8105487..f505023d1d0 100644 --- a/spec/features/projects/wiki/markdown_preview_spec.rb +++ b/spec/features/projects/wiki/markdown_preview_spec.rb @@ -162,6 +162,34 @@ describe 'Projects > Wiki > User previews markdown changes', :js do 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 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 end it "does not linkify double brackets inside code blocks as expected" do |