debian-mirror-gitlab/spec/support/shared_examples/features/wiki/user_views_asciidoc_page_with_includes_shared_examples.rb

78 lines
2.6 KiB
Ruby
Raw Normal View History

2020-03-13 15:44:24 +05:30
# frozen_string_literal: true
2021-01-03 14:25:43 +05:30
RSpec.shared_examples 'User views AsciiDoc page with includes' do
2021-10-27 15:23:28 +05:30
let_it_be(:wiki_content_selector) { '[data-qa-selector=wiki_page_content]' } # rubocop:disable QA/SelectorUsage
2020-03-13 15:44:24 +05:30
let!(:included_wiki_page) { create_wiki_page('included_page', content: 'Content from the included page')}
let!(:wiki_page) { create_wiki_page('home', content: "Content from the main page.\ninclude::included_page.asciidoc[]") }
def create_wiki_page(title, content:)
attrs = {
title: title,
content: content,
format: :asciidoc
}
2021-01-03 14:25:43 +05:30
create(:wiki_page, wiki: wiki, **attrs)
2020-03-13 15:44:24 +05:30
end
before do
sign_in(user)
end
2021-01-03 14:25:43 +05:30
context 'when the file being included exists', :js do
2020-03-13 15:44:24 +05:30
it 'includes the file contents' do
2021-01-03 14:25:43 +05:30
visit(wiki_page_path(wiki, wiki_page))
2020-03-13 15:44:24 +05:30
page.within(:css, wiki_content_selector) do
expect(page).to have_content('Content from the main page. Content from the included page')
end
end
context 'when there are multiple versions of the wiki pages' do
before do
2021-01-03 14:25:43 +05:30
# rubocop:disable Rails/SaveBang
2020-03-13 15:44:24 +05:30
included_wiki_page.update(message: 'updated included file', content: 'Updated content from the included page')
wiki_page.update(message: 'updated wiki page', content: "Updated content from the main page.\ninclude::included_page.asciidoc[]")
2021-01-03 14:25:43 +05:30
# rubocop:enable Rails/SaveBang
2020-03-13 15:44:24 +05:30
end
let(:latest_version_id) { wiki_page.versions.first.id }
let(:oldest_version_id) { wiki_page.versions.last.id }
context 'viewing the latest version' do
it 'includes the latest content' do
2021-01-03 14:25:43 +05:30
visit(wiki_page_path(wiki, wiki_page, version_id: latest_version_id))
2020-03-13 15:44:24 +05:30
page.within(:css, wiki_content_selector) do
expect(page).to have_content('Updated content from the main page. Updated content from the included page')
end
end
end
context 'viewing the original version' do
it 'includes the content from the original version' do
2021-01-03 14:25:43 +05:30
visit(wiki_page_path(wiki, wiki_page, version_id: oldest_version_id))
2020-03-13 15:44:24 +05:30
page.within(:css, wiki_content_selector) do
expect(page).to have_content('Content from the main page. Content from the included page')
end
end
end
end
end
2021-01-03 14:25:43 +05:30
context 'when the file being included does not exist', :js do
2020-03-13 15:44:24 +05:30
before do
included_wiki_page.delete
end
it 'outputs an error' do
2021-01-03 14:25:43 +05:30
visit(wiki_page_path(wiki, wiki_page))
2020-03-13 15:44:24 +05:30
page.within(:css, wiki_content_selector) do
expect(page).to have_content('Content from the main page. [ERROR: include::included_page.asciidoc[] - unresolved directive]')
end
end
end
end