summaryrefslogtreecommitdiff
path: root/qa/qa/specs/features/browser_ui/3_create/snippet/create_project_snippet_with_multiple_files_spec.rb
blob: 77b3c4df7e1d5c0b1e0b6acd0a16f86b30e4ab38 (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
# frozen_string_literal: true

module QA
  RSpec.describe 'Create', :reliable do
    describe 'Multiple file snippet' do
      let(:snippet) do
        Resource::ProjectSnippet.fabricate_via_browser_ui! do |snippet|
          snippet.title = 'Project snippet with multiple files'
          snippet.description = 'Snippet description'
          snippet.visibility = 'Private'
          snippet.file_name = '01 file name'
          snippet.file_content = '1 file content'

          # Ten is the limit of files you can have under one snippet at the moment
          snippet.add_files do |files|
            (2..10).each do |i|
              files.append(name: file_name(i), content: file_content(i))
            end
          end
        end
      end

      before do
        Flow::Login.sign_in
      end

      after do
        snippet.remove_via_api!
      end

      it 'creates a project snippet with multiple files', testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/347725' do
        snippet

        Page::Dashboard::Snippet::Show.perform do |snippet|
          aggregate_failures 'file content verification' do
            expect(snippet).to have_snippet_title('Project snippet with multiple files')
            expect(snippet).to have_snippet_description('Snippet description')
            expect(snippet).to have_visibility_type(/private/i)

            (1..10).each do |i|
              expect(snippet).to have_file_name(file_name(i), i)
              expect(snippet).to have_file_content(file_content(i), i)
            end
          end
        end
      end

      # Currently the files are returned in alphabetical order and not in the order they are created.
      # However, it might soon change - see https://gitlab.com/gitlab-org/gitlab/-/issues/250836.
      # By using a leading "0" we make sure the test works with either implementation.
      def file_name(index)
        "#{index.to_s.rjust(2, '0')} file name"
      end

      def file_content(index)
        "#{index} file content"
      end
    end
  end
end