summaryrefslogtreecommitdiff
path: root/qa/qa/specs/features/browser_ui/1_manage/import/import_github_repo_spec.rb
blob: b5a8df15ddcd0bbff73f62c81e69f025fc55a744 (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
# frozen_string_literal: true

module QA
  RSpec.describe 'Manage', product_group: :import do
    describe 'GitHub import' do
      include_context 'with github import'

      context 'when imported via UI' do
        let(:imported_project) do
          Resource::ProjectImportedFromGithub.init do |project|
            project.import = true
            project.group = group
            project.github_personal_access_token = Runtime::Env.github_access_token
            project.github_repository_path = github_repo
            project.api_client = api_client
          end
        end

        let(:imported_issue) do
          Resource::Issue.init do |resource|
            resource.project = imported_project
            resource.iid = imported_project.issues.first[:iid]
            resource.api_client = api_client
          end.reload!
        end

        let(:imported_issue_events) do
          imported_issue.label_events.map { |e| { name: "#{e[:action]}_label", label: e.dig(:label, :name) } }
        end

        before do
          Flow::Login.sign_in(as: user)
          Page::Main::Menu.perform(&:go_to_create_project)
          Page::Project::New.perform do |project_page|
            project_page.click_import_project
            project_page.click_github_link
          end
        end

        it 'imports a project', testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/347877' do
          Page::Project::Import::Github.perform do |import_page|
            import_page.add_personal_access_token(Runtime::Env.github_access_token)

            import_page.select_advanced_option(:single_endpoint_issue_events_import)
            import_page.select_advanced_option(:single_endpoint_notes_import)
            import_page.select_advanced_option(:attachments_import)

            import_page.import!(github_repo, group.full_path, imported_project.name)

            aggregate_failures do
              expect(import_page).to have_imported_project(github_repo, wait: 240)
              # validate link is present instead of navigating to avoid dealing with multiple tabs
              # which makes the test more complicated
              expect(import_page).to have_go_to_project_link(github_repo)
            end
          end

          imported_project.reload!.visit!
          Page::Project::Show.perform do |project|
            aggregate_failures do
              expect(project).to have_content(imported_project.name)
              expect(project).to have_content('Project for github import test')
            end
          end

          # Validate :single_endpoint_issue_events_import option was triggered correctly and imported the events
          expect(imported_issue_events).to match_array(
            [
              { name: "add_label", label: "question" },
              { name: "add_label", label: "good first issue" },
              { name: "add_label", label: "help wanted" }
            ]
          )
        end
      end
    end
  end
end