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

module QA
  RSpec.describe 'Create' do
    describe 'Sharing snippets' do
      let(:snippet) do
        Resource::Snippet.fabricate! do |snippet|
          snippet.title = 'Shared snippet'
          snippet.visibility = 'Public'
          snippet.file_name = 'code.py'
          snippet.file_content = 'code to be shared'
        end
      end

      before do
        Flow::Login.sign_in
      end

      after do
        snippet&.remove_via_api!
      end

      context 'when the snippet is public' do
        it 'can be shared with not signed-in users', testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/347836' do
          snippet.visit!

          sharing_link = Page::Dashboard::Snippet::Show.perform do |snippet|
            expect(snippet).to have_embed_dropdown
            snippet.get_sharing_link
          end

          Page::Main::Menu.perform(&:sign_out)

          page.visit(sharing_link)

          Page::Dashboard::Snippet::Show.perform do |snippet|
            expect(snippet).to have_snippet_title('Shared snippet')
            expect(snippet).to have_visibility_type(/public/i)
            expect(snippet).to have_file_content('code to be shared')
            expect(snippet).to have_embed_dropdown
          end
        end
      end

      context 'when the snippet is changed to private' do
        it 'does not display Embed/Share dropdown', testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/347835' do
          snippet.visit!

          Page::Dashboard::Snippet::Show.perform do |snippet|
            expect(snippet).to have_embed_dropdown

            snippet.click_edit_button
          end

          Page::Dashboard::Snippet::Edit.perform do |snippet|
            snippet.change_visibility_to('Private')
            snippet.save_changes
          end

          Page::Dashboard::Snippet::Show.perform do |snippet|
            expect(snippet).not_to have_embed_dropdown
          end
        end
      end
    end
  end
end