File: source_editor_markdown_preview_spec.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (79 lines) | stat: -rw-r--r-- 2,022 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Projects > Files > User previews file while editing in single file editor', :js, feature_category: :source_code_management do
  include Features::SourceEditorSpecHelpers

  let_it_be_with_reload(:project) { create(:project, :repository) }
  let_it_be_with_reload(:user) { create(:user) }
  let(:content_mermaid_graph) do
    <<~MERMAID
    ```mermaid
    graph TD;
      A-->B;
      A-->C;
      B-->D;
      C-->D;
    ```
    MERMAID
  end

  let(:expected_mermaid_graph) do
    src = "http://#{Capybara.current_session.server.host}:#{Capybara.current_session.server.port}/-/sandbox/mermaid"
    %(<iframe src="#{src}" sandbox="allow-scripts allow-popups" frameborder="0" scrolling="no")
  end

  before_all do
    project.add_maintainer(user)
  end

  before do
    sign_in user
    visit project_edit_blob_path(project, File.join(project.default_branch, 'README.md'))
  end

  context 'when user toggles preview' do
    it 'renders math equations correctly' do
      content = <<~MATH
      This math is inline $`a^2+b^2=c^2`$.

      This is on a separate line
      ```math
      a^2+b^2=c^2
      ```

      This math is aligned

      ```math
      \\begin{align*}
        a&=b+c \\\\
        d+e&=f
      \\end{align*}
      ```
      MATH

      fill_editor(content)
      click_link 'Preview'
      wait_for_requests
      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')
    end

    it 'renders mermaid graphs correctly' do
      fill_editor(content_mermaid_graph)
      click_link 'Preview'
      wait_for_requests

      page.within('.js-markdown-code') do
        expect(page.html).to include(expected_mermaid_graph)
      end
    end
  end

  def fill_editor(content)
    wait_for_requests
    editor_set_value(content)
  end
end