markdown_preview_spec.rb 6.78 KB
Newer Older
1
2
require 'spec_helper'

3
feature 'Projects > Wiki > User previews markdown changes', :js do
4
  let(:user) { create(:user) }
Zeger-Jan van de Weg's avatar
Zeger-Jan van de Weg committed
5
  let(:project) { create(:project, :wiki_repo, namespace: user.namespace) }
6
7
8
9
10
11
12
13
14
15
  let(:wiki_content) do
    <<-HEREDOC
[regular link](regular)
[relative link 1](../relative)
[relative link 2](./relative)
[relative link 3](./e/f/relative)
    HEREDOC
  end

  background do
16
    project.add_master(user)
17

18
    sign_in(user)
19

20
    visit project_path(project)
21
    find('.shortcuts-wiki').click
22
23
24
25
26
  end

  context "while creating a new wiki page" do
    context "when there are no spaces or hyphens in the page name" do
      it "rewrites relative links as expected" do
27
        find('.add-new-wiki').click
28
29
30
31
        page.within '#modal-new-wiki' do
          fill_in :new_wiki_path, with: 'a/b/c/d'
          click_button 'Create page'
        end
32

33
34
35
36
        page.within '.wiki-form' do
          fill_in :wiki_content, with: wiki_content
          click_on "Preview"
        end
37
38
39

        expect(page).to have_content("regular link")

40
41
42
43
        expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/regular\">regular link</a>")
        expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a/b/relative\">relative link 1</a>")
        expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a/b/c/relative\">relative link 2</a>")
        expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a/b/c/e/f/relative\">relative link 3</a>")
44
45
46
47
48
      end
    end

    context "when there are spaces in the page name" do
      it "rewrites relative links as expected" do
49
50
51
52
53
        click_link 'New page'
        page.within '#modal-new-wiki' do
          fill_in :new_wiki_path, with: 'a page/b page/c page/d page'
          click_button 'Create page'
        end
54

55
56
57
58
        page.within '.wiki-form' do
          fill_in :wiki_content, with: wiki_content
          click_on "Preview"
        end
59
60
61

        expect(page).to have_content("regular link")

62
63
64
65
        expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/regular\">regular link</a>")
        expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/relative\">relative link 1</a>")
        expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/c-page/relative\">relative link 2</a>")
        expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/c-page/e/f/relative\">relative link 3</a>")
66
67
68
69
70
      end
    end

    context "when there are hyphens in the page name" do
      it "rewrites relative links as expected" do
71
72
73
74
75
        click_link 'New page'
        page.within '#modal-new-wiki' do
          fill_in :new_wiki_path, with: 'a-page/b-page/c-page/d-page'
          click_button 'Create page'
        end
Annabel Dunstone Gray's avatar
Annabel Dunstone Gray committed
76

77
78
79
80
        page.within '.wiki-form' do
          fill_in :wiki_content, with: wiki_content
          click_on "Preview"
        end
81
82
83

        expect(page).to have_content("regular link")

84
85
86
87
        expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/regular\">regular link</a>")
        expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/relative\">relative link 1</a>")
        expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/c-page/relative\">relative link 2</a>")
        expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/c-page/e/f/relative\">relative link 3</a>")
88
89
90
91
92
93
      end
    end
  end

  context "while editing a wiki page" do
    def create_wiki_page(path)
94
      find('.add-new-wiki').click
95
96
97
98
99
100
101
102
103
104

      page.within '#modal-new-wiki' do
        fill_in :new_wiki_path, with: path
        click_button 'Create page'
      end

      page.within '.wiki-form' do
        fill_in :wiki_content, with: 'content'
        click_on "Create page"
      end
105
106
107
108
109
110
111
112
113
114
115
116
    end

    context "when there are no spaces or hyphens in the page name" do
      it "rewrites relative links as expected" do
        create_wiki_page 'a/b/c/d'
        click_link 'Edit'

        fill_in :wiki_content, with: wiki_content
        click_on "Preview"

        expect(page).to have_content("regular link")

117
118
119
120
        expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/regular\">regular link</a>")
        expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a/b/relative\">relative link 1</a>")
        expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a/b/c/relative\">relative link 2</a>")
        expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a/b/c/e/f/relative\">relative link 3</a>")
121
122
123
124
125
126
127
128
129
130
131
132
133
      end
    end

    context "when there are spaces in the page name" do
      it "rewrites relative links as expected" do
        create_wiki_page 'a page/b page/c page/d page'
        click_link 'Edit'

        fill_in :wiki_content, with: wiki_content
        click_on "Preview"

        expect(page).to have_content("regular link")

134
135
136
137
        expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/regular\">regular link</a>")
        expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/relative\">relative link 1</a>")
        expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/c-page/relative\">relative link 2</a>")
        expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/c-page/e/f/relative\">relative link 3</a>")
138
139
140
141
142
143
144
145
146
147
148
149
150
      end
    end

    context "when there are hyphens in the page name" do
      it "rewrites relative links as expected" do
        create_wiki_page 'a-page/b-page/c-page/d-page'
        click_link 'Edit'

        fill_in :wiki_content, with: wiki_content
        click_on "Preview"

        expect(page).to have_content("regular link")

151
152
153
154
        expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/regular\">regular link</a>")
        expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/relative\">relative link 1</a>")
        expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/c-page/relative\">relative link 2</a>")
        expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/c-page/e/f/relative\">relative link 3</a>")
155
156
157
      end
    end
  end
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180

  it "does not linkify double brackets inside code blocks as expected" do
    click_link 'New page'
    page.within '#modal-new-wiki' do
      fill_in :new_wiki_path, with: 'linkify_test'
      click_button 'Create page'
    end

    page.within '.wiki-form' do
      fill_in :wiki_content, with: <<-HEREDOC
        `[[do_not_linkify]]`
        ```
        [[also_do_not_linkify]]
        ```
      HEREDOC
      click_on "Preview"
    end

    expect(page).to have_content("do_not_linkify")

    expect(page.html).to include('[[do_not_linkify]]')
    expect(page.html).to include('[[also_do_not_linkify]]')
  end
181
end