debian-mirror-gitlab/spec/features/markdown/math_spec.rb

166 lines
7 KiB
Ruby
Raw Permalink Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
require 'spec_helper'
2023-03-04 22:38:38 +05:30
RSpec.describe 'Math rendering', :js, feature_category: :team_planning do
2019-03-02 22:35:43 +05:30
let!(:project) { create(:project, :public) }
2019-02-02 18:00:53 +05:30
2018-03-17 18:26:18 +05:30
it 'renders inline and display math correctly' do
description = <<~MATH
This math is inline $`a^2+b^2=c^2`$.
This is on a separate line
```math
a^2+b^2=c^2
```
2021-06-08 01:23:25 +05:30
This math is aligned
```math
\\begin{align*}
a&=b+c \\\\
d+e&=f
\\end{align*}
```
2018-03-17 18:26:18 +05:30
MATH
issue = create(:issue, project: project, description: description)
visit project_issue_path(project, issue)
2021-06-08 01:23:25 +05:30
expect(page).to have_selector('.katex .mord.mathnormal', text: 'b')
expect(page).to have_selector('.katex-display .mord.mathnormal', text: 'b')
expect(page).to have_selector('.katex-display .mtable .col-align-l .mord.mathnormal', text: 'f')
2019-02-02 18:00:53 +05:30
end
it 'only renders non XSS links' do
description = <<~MATH
This link is valid $`\\href{javascript:alert('xss');}{xss}`$.
This link is valid $`\\href{https://gitlab.com}{Gitlab}`$.
MATH
issue = create(:issue, project: project, description: description)
visit project_issue_path(project, issue)
2019-09-04 21:01:54 +05:30
page.within '.description > .md' do
2021-06-08 01:23:25 +05:30
# unfortunately there is no class selector for KaTeX's "unsupported command"
# formatting so we must match the style attribute
expect(page).to have_selector('.katex-html .mord[style*="color:"][style*="#cc0000"]', text: '\href')
2019-09-04 21:01:54 +05:30
expect(page).to have_selector('.katex-html a', text: 'Gitlab')
end
2018-03-17 18:26:18 +05:30
end
2021-04-17 20:07:23 +05:30
it 'renders lazy load button' do
description = <<~MATH
```math
\Huge \sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sq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sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
```
MATH
issue = create(:issue, project: project, description: description)
visit project_issue_path(project, issue)
page.within '.description > .md' do
2023-04-23 21:23:45 +05:30
expect(page).to have_selector('.js-lazy-render-math-container', text: /math block exceeds 1000 characters/)
end
end
it 'allows many expansions', :js do
description = <<~MATH
```math
#{'\\mod e ' * 100}
```
MATH
issue = create(:issue, project: project, description: description)
visit project_issue_path(project, issue)
wait_for_requests
page.within '.description > .md' do
expect(page).not_to have_selector('.katex-error')
end
end
it 'shows error message when too many expansions', :js do
description = <<~MATH
```math
#{'\\mod e ' * 150}
```
MATH
issue = create(:issue, project: project, description: description)
visit project_issue_path(project, issue)
wait_for_requests
page.within '.description > .md' do
click_button 'Display anyway'
expect(page).to have_selector('.katex-error', text: /Too many expansions/)
end
end
it 'shows error message when other errors are generated', :js do
description = <<~MATH
```math
\\unknown
```
MATH
issue = create(:issue, project: project, description: description)
visit project_issue_path(project, issue)
wait_for_requests
page.within '.description > .md' do
expect(page).to have_selector('.katex-error',
text: /There was an error rendering this math block. KaTeX parse error/)
end
end
it 'escapes HTML in error', :js do
description = <<~MATH
```math
\\unknown <script>
```
MATH
issue = create(:issue, project: project, description: description)
visit project_issue_path(project, issue)
wait_for_requests
page.within '.description > .md' do
expect(page).to have_selector('.katex-error',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t{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
```
MATH
wiki_page = build(:wiki_page, { container: project, content: description })
wiki_page.create message: 'math 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
page.within '.js-wiki-page-content' do
expect(page).not_to have_selector('.js-lazy-render-math')
end
end
2018-03-17 18:26:18 +05:30
end