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

module QA
  RSpec.describe 'Create', :reliable, product_group: :editor, quarantine: {
    only: { subdomain: 'pre' },
    type: :investigating,
    issue: 'https://gitlab.com/gitlab-org/gitlab/-/issues/378697'
  } do
    describe 'Multiple file snippet' do
      let(:first_file_content) { 'First file content' }
      let(:second_file_content) { 'Second file content' }
      let(:third_file_content) { 'Third file content' }

      let(:personal_snippet) do
        Resource::Snippet.fabricate_via_api! do |snippet|
          snippet.title = 'Personal snippet to copy file contents from'
          snippet.file_name = 'First file name'
          snippet.file_content = first_file_content

          snippet.add_files do |files|
            files.append(name: 'Second file name', content: second_file_content)
            files.append(name: 'Third file name', content: third_file_content)
          end
        end
      end

      let(:project_snippet) do
        Resource::ProjectSnippet.fabricate_via_api! do |snippet|
          snippet.title = 'Project snippet to copy file contents from'
          snippet.file_name = 'First file name'
          snippet.file_content = first_file_content

          snippet.add_files do |files|
            files.append(name: 'Second file name', content: second_file_content)
            files.append(name: 'Third file name', content: third_file_content)
          end
        end
      end

      let(:files) do
        [
          {
            number: 1,
            content: first_file_content
          },
          {
            number: 2,
            content: second_file_content
          },
          {
            number: 3,
            content: third_file_content
          }
        ]
      end

      before do
        Flow::Login.sign_in
      end

      shared_examples 'copying snippet file contents' do |snippet_type, testcase|
        it "copies file contents of a multi-file #{snippet_type} to a comment and verifies them", testcase: testcase do
          send(snippet_type).visit!

          files.each do |files|
            Page::Dashboard::Snippet::Show.perform do |snippet|
              snippet.copy_file_contents_to_comment(files[:number])
              expect(snippet).to have_comment_content(files[:content])
              snippet.delete_comment(files[:content])
            end
          end
        end
      end

      it_behaves_like 'copying snippet file contents', :personal_snippet, 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/347849'
      it_behaves_like 'copying snippet file contents', :project_snippet, 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/347848'
    end
  end
end