2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
RSpec.describe 'Mermaid rendering', :js do
|
2021-08-04 16:29:09 +05:30
|
|
|
let_it_be(:project) { create(:project, :public) }
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it 'renders Mermaid diagrams correctly' do
|
|
|
|
description = <<~MERMAID
|
|
|
|
```mermaid
|
|
|
|
graph TD;
|
|
|
|
A-->B;
|
|
|
|
A-->C;
|
|
|
|
B-->D;
|
|
|
|
C-->D;
|
|
|
|
```
|
|
|
|
MERMAID
|
|
|
|
|
|
|
|
issue = create(:issue, project: project, description: description)
|
|
|
|
|
|
|
|
visit project_issue_path(project, issue)
|
|
|
|
|
2020-12-08 15:28:05 +05:30
|
|
|
wait_for_requests
|
|
|
|
wait_for_mermaid
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
%w[A B C D].each do |label|
|
2018-11-29 20:51:05 +05:30
|
|
|
expect(page).to have_selector('svg text', text: label)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
2019-09-30 21:07:59 +05:30
|
|
|
|
|
|
|
it 'renders linebreaks in Mermaid diagrams' do
|
|
|
|
description = <<~MERMAID
|
|
|
|
```mermaid
|
|
|
|
graph TD;
|
|
|
|
A(Line 1<br>Line 2)-->B(Line 1<br/>Line 2);
|
|
|
|
C(Line 1<br />Line 2)-->D(Line 1<br />Line 2);
|
|
|
|
```
|
|
|
|
MERMAID
|
|
|
|
|
|
|
|
issue = create(:issue, project: project, description: description)
|
|
|
|
|
|
|
|
visit project_issue_path(project, issue)
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
wait_for_requests
|
2020-12-08 15:28:05 +05:30
|
|
|
wait_for_mermaid
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
# From https://github.com/mermaid-js/mermaid/blob/d3f8f03a7d03a052e1fe0251d5a6d8d1f48d67ee/src/dagre-wrapper/createLabel.js#L79-L82
|
|
|
|
expected = %(<div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;">Line 1<br>Line 2</div>)
|
2019-09-30 21:07:59 +05:30
|
|
|
expect(page.html.scan(expected).count).to be(4)
|
|
|
|
end
|
2019-09-30 23:59:55 +05:30
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
it 'does not allow XSS in HTML labels' do
|
|
|
|
description = <<~MERMAID
|
|
|
|
```mermaid
|
|
|
|
graph LR;
|
|
|
|
A-->CLICK_HERE_AND_GET_BONUS;
|
|
|
|
click A alert "aaa"
|
|
|
|
click CLICK_HERE_AND_GET_BONUS "javascript:alert%28%64%6f%63%75%6d%65%6e%74%2e%64%6f%6d%61%69%6e%29" "Here is the XSS"
|
|
|
|
```
|
|
|
|
MERMAID
|
|
|
|
|
|
|
|
issue = create(:issue, project: project, description: description)
|
|
|
|
|
|
|
|
visit project_issue_path(project, issue)
|
|
|
|
|
|
|
|
wait_for_requests
|
|
|
|
wait_for_mermaid
|
|
|
|
|
|
|
|
# From https://github.com/mermaid-js/mermaid/blob/d3f8f03a7d03a052e1fe0251d5a6d8d1f48d67ee/src/dagre-wrapper/createLabel.js#L79-L82
|
|
|
|
expected = %(<div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;">CLICK_HERE_AND_GET_BONUS</div>)
|
|
|
|
expect(page.html).to include(expected)
|
|
|
|
end
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
it 'renders only 2 Mermaid blocks and', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/234081' do
|
2019-09-30 23:59:55 +05:30
|
|
|
description = <<~MERMAID
|
|
|
|
```mermaid
|
|
|
|
graph LR
|
|
|
|
A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A
|
|
|
|
```
|
|
|
|
```mermaid
|
|
|
|
graph LR
|
|
|
|
A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A
|
|
|
|
```
|
|
|
|
```mermaid
|
|
|
|
graph LR
|
|
|
|
A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A;A-->B;B-->A
|
|
|
|
```
|
|
|
|
MERMAID
|
|
|
|
|
|
|
|
issue = create(:issue, project: project, description: description)
|
|
|
|
|
|
|
|
visit project_issue_path(project, issue)
|
|
|
|
|
2020-12-08 15:28:05 +05:30
|
|
|
wait_for_requests
|
|
|
|
wait_for_mermaid
|
|
|
|
|
2019-09-30 23:59:55 +05:30
|
|
|
page.within('.description') do
|
|
|
|
expect(page).to have_selector('svg')
|
|
|
|
expect(page).to have_selector('pre.mermaid')
|
|
|
|
end
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
it 'correctly sizes mermaid diagram inside <details> block' do
|
2020-03-13 15:44:24 +05:30
|
|
|
description = <<~MERMAID
|
|
|
|
<details>
|
|
|
|
<summary>Click to show diagram</summary>
|
|
|
|
|
|
|
|
```mermaid
|
|
|
|
graph TD;
|
|
|
|
A-->B;
|
|
|
|
A-->C;
|
|
|
|
B-->D;
|
|
|
|
C-->D;
|
|
|
|
```
|
|
|
|
|
|
|
|
</details>
|
|
|
|
MERMAID
|
|
|
|
|
|
|
|
issue = create(:issue, project: project, description: description)
|
|
|
|
|
|
|
|
visit project_issue_path(project, issue)
|
|
|
|
|
2020-12-08 15:28:05 +05:30
|
|
|
wait_for_requests
|
|
|
|
wait_for_mermaid
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
page.within('.description') do
|
|
|
|
page.find('summary').click
|
|
|
|
svg = page.find('svg.mermaid')
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(svg[:style]).to match(/max-width/)
|
|
|
|
expect(svg[:width].to_i).to eq(100)
|
2021-09-04 01:27:46 +05:30
|
|
|
expect(svg[:height].to_i).to be_within(5).of(236)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders V2 state diagrams' do
|
|
|
|
description = <<~MERMAID
|
|
|
|
```mermaid
|
|
|
|
stateDiagram-v2
|
|
|
|
[*] --> Idle
|
|
|
|
Idle --> Active : CONTINUE
|
|
|
|
state Active {
|
|
|
|
[*] --> Run
|
|
|
|
Run--> Stop: CONTINUE
|
|
|
|
Stop--> Run: CONTINUE
|
|
|
|
|
|
|
|
Run: Run
|
|
|
|
Run: entry/start
|
|
|
|
Run: check
|
|
|
|
}
|
|
|
|
```
|
|
|
|
MERMAID
|
|
|
|
|
|
|
|
issue = create(:issue, project: project, description: description)
|
|
|
|
|
|
|
|
visit project_issue_path(project, issue)
|
|
|
|
|
|
|
|
wait_for_requests
|
|
|
|
wait_for_mermaid
|
|
|
|
|
|
|
|
page.within('.description') do
|
|
|
|
expect(page).to have_selector('svg')
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
it 'correctly sizes mermaid diagram block' do
|
2020-04-08 14:13:33 +05:30
|
|
|
description = <<~MERMAID
|
|
|
|
```mermaid
|
|
|
|
graph TD;
|
|
|
|
A-->B;
|
|
|
|
A-->C;
|
|
|
|
B-->D;
|
|
|
|
C-->D;
|
|
|
|
```
|
|
|
|
MERMAID
|
|
|
|
|
|
|
|
issue = create(:issue, project: project, description: description)
|
|
|
|
|
|
|
|
visit project_issue_path(project, issue)
|
|
|
|
|
2020-12-08 15:28:05 +05:30
|
|
|
wait_for_requests
|
|
|
|
wait_for_mermaid
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(page).to have_css('svg.mermaid[style*="max-width"][width="100%"]')
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
it 'display button when diagram exceeds length', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/287806' do
|
2020-04-08 14:13:33 +05:30
|
|
|
graph_edges = "A-->B;B-->A;" * 420
|
|
|
|
|
|
|
|
description = <<~MERMAID
|
|
|
|
```mermaid
|
|
|
|
graph LR
|
|
|
|
#{graph_edges}
|
|
|
|
```
|
|
|
|
MERMAID
|
|
|
|
|
|
|
|
issue = create(:issue, project: project, description: description)
|
|
|
|
|
|
|
|
visit project_issue_path(project, issue)
|
|
|
|
|
|
|
|
page.within('.description') do
|
|
|
|
expect(page).not_to have_selector('svg')
|
|
|
|
|
|
|
|
expect(page).to have_selector('pre.mermaid')
|
|
|
|
|
|
|
|
expect(page).to have_selector('.lazy-alert-shown')
|
|
|
|
|
|
|
|
expect(page).to have_selector('.js-lazy-render-mermaid-container')
|
|
|
|
end
|
|
|
|
|
|
|
|
wait_for_requests
|
2020-12-08 15:28:05 +05:30
|
|
|
wait_for_mermaid
|
2020-04-08 14:13:33 +05:30
|
|
|
|
|
|
|
find('.js-lazy-render-mermaid').click
|
|
|
|
|
|
|
|
page.within('.description') do
|
|
|
|
expect(page).to have_selector('svg')
|
|
|
|
|
|
|
|
expect(page).not_to have_selector('.js-lazy-render-mermaid-container')
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
end
|
2020-12-08 15:28:05 +05:30
|
|
|
|
|
|
|
it 'does not render more than 50 mermaid blocks', :js, quarantine: { issue: 'https://gitlab.com/gitlab-org/gitlab/-/issues/234081' } do
|
|
|
|
graph_edges = "A-->B;B-->A;"
|
|
|
|
|
|
|
|
description = <<~MERMAID
|
|
|
|
```mermaid
|
|
|
|
graph LR
|
|
|
|
#{graph_edges}
|
|
|
|
```
|
|
|
|
MERMAID
|
|
|
|
|
|
|
|
description *= 51
|
|
|
|
|
|
|
|
issue = create(:issue, project: project, description: description)
|
|
|
|
|
|
|
|
visit project_issue_path(project, issue)
|
|
|
|
|
|
|
|
wait_for_requests
|
|
|
|
wait_for_mermaid
|
|
|
|
|
|
|
|
page.within('.description') do
|
|
|
|
expect(page).to have_selector('svg')
|
|
|
|
|
|
|
|
expect(page).to have_selector('.lazy-alert-shown')
|
|
|
|
|
|
|
|
expect(page).to have_selector('.js-lazy-render-mermaid-container')
|
2021-09-04 01:27:46 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders without any limits on wiki page', :js do
|
|
|
|
graph_edges = "A-->B;B-->A;"
|
|
|
|
|
|
|
|
description = <<~MERMAID
|
|
|
|
```mermaid
|
|
|
|
graph LR
|
|
|
|
#{graph_edges}
|
|
|
|
```
|
|
|
|
MERMAID
|
|
|
|
|
|
|
|
description *= 51
|
|
|
|
|
|
|
|
wiki_page = build(:wiki_page, { container: project, content: description })
|
|
|
|
wiki_page.create message: 'mermaid test commit' # rubocop:disable Rails/SaveBang
|
|
|
|
wiki_page = project.wiki.find_page(wiki_page.slug)
|
|
|
|
|
|
|
|
visit project_wiki_path(project, wiki_page)
|
|
|
|
|
|
|
|
wait_for_requests
|
|
|
|
wait_for_mermaid
|
|
|
|
|
|
|
|
page.within('.js-wiki-page-content') do
|
|
|
|
expect(page).not_to have_selector('.lazy-alert-shown')
|
|
|
|
|
|
|
|
expect(page).not_to have_selector('.js-lazy-render-mermaid-container')
|
2020-12-08 15:28:05 +05:30
|
|
|
end
|
|
|
|
end
|
2021-08-04 16:29:09 +05:30
|
|
|
|
|
|
|
it 'does not allow HTML injection' do
|
|
|
|
description = <<~MERMAID
|
|
|
|
```mermaid
|
|
|
|
%%{init: {"flowchart": {"htmlLabels": "false"}} }%%
|
|
|
|
flowchart
|
|
|
|
A["<iframe></iframe>"]
|
|
|
|
```
|
|
|
|
MERMAID
|
|
|
|
|
|
|
|
issue = create(:issue, project: project, description: description)
|
|
|
|
|
|
|
|
visit project_issue_path(project, issue)
|
|
|
|
|
|
|
|
wait_for_requests
|
|
|
|
wait_for_mermaid
|
|
|
|
|
|
|
|
page.within('.description') do
|
|
|
|
expect(page).not_to have_xpath("//iframe")
|
|
|
|
end
|
|
|
|
end
|
2020-12-08 15:28:05 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def wait_for_mermaid
|
|
|
|
run_idle_callback = <<~RUN_IDLE_CALLBACK
|
|
|
|
window.requestIdleCallback(() => {
|
|
|
|
window.__CAPYBARA_IDLE_CALLBACK_EXEC__ = 1;
|
|
|
|
})
|
|
|
|
RUN_IDLE_CALLBACK
|
|
|
|
|
|
|
|
page.evaluate_script(run_idle_callback)
|
|
|
|
|
|
|
|
Timeout.timeout(Capybara.default_max_wait_time) do
|
|
|
|
loop until finished_rendering?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def finished_rendering?
|
|
|
|
check_idle_callback = <<~CHECK_IDLE_CALLBACK
|
|
|
|
window.__CAPYBARA_IDLE_CALLBACK_EXEC__
|
|
|
|
CHECK_IDLE_CALLBACK
|
|
|
|
page.evaluate_script(check_idle_callback) == 1
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|