2022-01-11 10:15:55 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe 'Sandboxed Mermaid rendering', :js do
|
2022-11-01 14:10:46 -04:00
|
|
|
let_it_be(:project) { create(:project, :public, :repository) }
|
|
|
|
let_it_be(:description) do
|
|
|
|
<<~MERMAID
|
|
|
|
```mermaid
|
|
|
|
graph TD;
|
|
|
|
A-->B;
|
|
|
|
A-->C;
|
|
|
|
B-->D;
|
|
|
|
C-->D;
|
|
|
|
```
|
2022-01-11 10:15:55 -05:00
|
|
|
MERMAID
|
2022-11-01 14:10:46 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
let_it_be(:expected) do
|
|
|
|
%(<iframe src="/-/sandbox/mermaid" sandbox="allow-scripts allow-popups" frameborder="0" scrolling="no")
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'in an issue' do
|
|
|
|
let(:issue) { create(:issue, project: project, description: description) }
|
|
|
|
|
|
|
|
it 'includes mermaid frame correctly' do
|
|
|
|
visit project_issue_path(project, issue)
|
|
|
|
|
|
|
|
wait_for_requests
|
|
|
|
|
|
|
|
expect(page.html).to include(expected)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'in a merge request' do
|
|
|
|
let(:merge_request) { create(:merge_request_with_diffs, source_project: project, description: description) }
|
|
|
|
|
|
|
|
it 'renders diffs and includes mermaid frame correctly' do
|
|
|
|
visit(diffs_project_merge_request_path(project, merge_request))
|
|
|
|
|
|
|
|
wait_for_requests
|
2022-01-11 10:15:55 -05:00
|
|
|
|
2022-11-01 14:10:46 -04:00
|
|
|
page.within('.tab-content') do
|
|
|
|
expect(page).to have_selector('.diffs')
|
|
|
|
end
|
2022-01-11 10:15:55 -05:00
|
|
|
|
2022-11-01 14:10:46 -04:00
|
|
|
visit(project_merge_request_path(project, merge_request))
|
2022-01-11 10:15:55 -05:00
|
|
|
|
2022-11-01 14:10:46 -04:00
|
|
|
wait_for_requests
|
2022-01-11 10:15:55 -05:00
|
|
|
|
2022-11-01 14:10:46 -04:00
|
|
|
page.within('.merge-request') do
|
|
|
|
expect(page.html).to include(expected)
|
|
|
|
end
|
|
|
|
end
|
2022-01-11 10:15:55 -05:00
|
|
|
end
|
|
|
|
end
|