Welcome to mirror list, hosted at ThFree Co, Russian Federation.

user_creates_wiki_page_spec.rb « wiki « projects « features « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6b651ccb67ada9f0ecdcdce88057c5d29869232d (plain)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# frozen_string_literal: true

require "spec_helper"

describe "User creates wiki page" do
  include CapybaraHelpers
  include WikiHelpers

  set(:user) { create(:user) }

  let(:project) { create(:project) }
  let(:wiki) { ProjectWiki.new(project, user) }
  let(:new_page) { WikiPage.new(wiki) }
  let(:message_field) { form_field_name(new_page, :message) }

  before do
    project.add_maintainer(user)

    sign_in(user)
  end

  def start_writing(page_path)
    click_link("New page")
    fill_in(:wiki_page_title, with: page_path)
  end

  def create_page(attrs = {})
    page.within(".wiki-form") do
      attrs.each do |k, v|
        fill_in("wiki_page_#{k}".to_sym, with: v)
      end
    end
    click_on("Create page")
  end

  shared_examples 'updates commit message' do
    describe 'commit message', :js do
      it "has `Create home` as a commit message" do
        wait_for_requests

        expect(page).to have_field(message_field, with: "Create home")
      end
    end
  end

  context "when wiki is empty" do
    before do
      visit(project_wikis_path(project))

      click_link "Create your first page"
      find('.wiki-form')
    end

    context "in a user namespace" do
      let(:project) { create(:project, :wiki_repo, namespace: user.namespace) }
      let(:wiki_page_content) { '' }

      it "shows validation error message" do
        create_page

        expect(page)
          .to have_content("The form contains the following error:")
          .and have_content("Content can't be blank")
          .and have_css('.wiki-form')
          .and have_css('.qa-create-page-button')
      end

      it 'offers to create pages that do not yet exist' do
        create_page(content: "[link test](test)")

        expect(page)
          .to have_content("Home")
          .and have_content("link test")

        click_link("link test")

        expect(page).to have_content("Create New Page")
      end

      it "has a link to the parent directory in the pages sidebar" do
        wiki_full_path = "one/two/three-test"
        create_page(title: wiki_full_path, content: 'wiki content')

        wiki_page = wiki.find_page(wiki_full_path)
        expect(wiki_page).to be_present
        dir = wiki.find_dir(wiki_page.directory)
        expect(dir).to be_present

        expect(current_path).to include(wiki_full_path)

        expect(page).to have_link(dir.slug, href: project_wiki_dir_path(project, dir))
      end

      it "shows non-escaped link in the pages list", :quarantine do
        fill_in(:wiki_title, with: "one/two/three-test")

        page.within(".wiki-form") do
          fill_in(:wiki_content, with: "wiki content")

          click_on("Create page")
        end

        expect(current_path).to include("one/two/three-test")
        expect(page).to have_xpath("//a[@href='/#{project.full_path}/wikis/one/two/three-test']")
      end

      it_behaves_like 'updates commit message'

      it "creates a page from the home page" do
        page_content = <<~WIKI_CONTENT
          [test](test)
          [GitLab API doc](api)
          [Rake tasks](raketasks)
          # Wiki header
        WIKI_CONTENT

        create_page(content: page_content, message: "Adding links to wiki")

        expect(current_path).to eq(project_wiki_path(project, "home"))
        expect(page).to have_content("test GitLab API doc Rake tasks Wiki header")
                   .and have_content("Home")
                   .and have_content("Last edited by #{user.name}")
                   .and have_header_with_correct_id_and_link(1, "Wiki header", "wiki-header")

        click_link("test")

        expect(current_path).to eq(project_wiki_path(project, "test"))

        page.within(:css, ".nav-text") do
          expect(page).to have_content("Create New Page")
        end

        click_link("Home")

        expect(current_path).to eq(project_wiki_path(project, "home"))

        click_link("GitLab API")

        expect(current_path).to eq(project_wiki_path(project, "api"))

        page.within(:css, ".nav-text") do
          expect(page).to have_content("Create")
        end

        click_link("Home")

        expect(current_path).to eq(project_wiki_path(project, "home"))

        click_link("Rake tasks")

        expect(current_path).to eq(project_wiki_path(project, "raketasks"))

        page.within(:css, ".nav-text") do
          expect(page).to have_content("Create")
        end
      end

      it "creates ASCIIdoc wiki with LaTeX blocks", :js do
        stub_application_setting(plantuml_url: "http://localhost", plantuml_enabled: true)

        ascii_content = <<~MD
          :stem: latexmath

          [stem]
          ++++
          \\sqrt{4} = 2
          ++++

          another part

          [latexmath]
          ++++
          \\beta_x \\gamma
          ++++

          stem:[2+2] is 4
        MD

        find("#wiki_page_format option[value=asciidoc]").select_option

        create_page(content: ascii_content)

        page.within ".md" do
          expect(page).to have_selector(".katex", count: 3).and have_content("2+2 is 4")
        end
      end

      it_behaves_like 'wiki file attachments'
    end

    context "in a group namespace" do
      let(:project) { create(:project, :wiki_repo, namespace: create(:group, :public)) }

      it_behaves_like 'updates commit message'

      it "creates a page from the home page" do
        create_page(content: "My awesome wiki!")

        expect(page).to have_content("Home")
                   .and have_content("Last edited by #{user.name}")
                   .and have_content("My awesome wiki!")
      end
    end
  end

  context "when wiki is not empty", :js do
    before do
      create(:wiki_page, wiki: wiki, attrs: { title: 'home', content: 'Home page' })

      visit(project_wikis_path(project))
    end

    shared_examples 'creates page by slug' do |slug, unslug|
      it "creates #{slug}" do
        start_writing(slug)

        # Commit message field should have correct value.
        expect(page).to have_field(message_field, with: "Create #{unslug}")

        create_page(content: "My awesome wiki!")

        expect(page).to have_content(unslug)
                   .and have_content("Last edited by #{user.name}")
                   .and have_content("My awesome wiki!")
      end
    end

    context "in a user namespace" do
      let(:project) { create(:project, :wiki_repo, namespace: user.namespace) }

      context "via the `new wiki page` page" do
        include_examples 'creates page by slug', 'foo', 'foo'
        include_examples 'creates page by slug', 'Spaces in the name', 'Spaces in the name'
        include_examples 'creates page by slug', 'Hyphens-in-the-name', 'Hyphens in the name'
      end

      it "shows the emoji autocompletion dropdown" do
        start_writing('text-autocomplete')

        page.within(".wiki-form") do
          find("#wiki_page_content").native.send_keys("")

          fill_in(:wiki_page_content, with: ":")
        end

        expect(page).to have_selector(".atwho-view")
      end
    end

    context "in a group namespace" do
      let(:project) { create(:project, :wiki_repo, namespace: create(:group, :public)) }

      context "via the `new wiki page` page" do
        include_examples 'creates page by slug', 'foo', 'foo'
        include_examples 'creates page by slug', 'Spaces in the name', 'Spaces in the name'
        include_examples 'creates page by slug', 'Hyphens-in-the-name', 'Hyphens in the name'
      end
    end
  end

  describe 'sidebar feature' do
    context 'when there are some existing pages' do
      before do
        create(:wiki_page, wiki: wiki, attrs: { title: 'home', content: 'home' })
        create(:wiki_page, wiki: wiki, attrs: { title: 'another', content: 'another' })
      end

      it 'renders a default sidebar when there is no customized sidebar' do
        visit(project_wikis_path(project))

        expect(page).to have_content('another')
        expect(page).to have_content('More Pages')
      end

      context 'when there is a customized sidebar' do
        before do
          create(:wiki_page, wiki: wiki, attrs: { title: '_sidebar', content: 'My customized sidebar' })
        end

        it 'renders my customized sidebar instead of the default one' do
          visit(project_wikis_path(project))

          expect(page).to have_content('My customized sidebar')
          expect(page).to have_content('More Pages')
          expect(page).not_to have_content('Another')
        end
      end
    end
  end
end