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

learn_gitlab_helper_spec.rb « helpers « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9fce7495b5a8eca4817a0efbfb04989946992f52 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe LearnGitlabHelper do
  include AfterNextHelpers
  include Devise::Test::ControllerHelpers

  let_it_be(:user) { create(:user) }
  let_it_be(:project) { create(:project, name: LearnGitlab::Project::PROJECT_NAME, namespace: user.namespace) }
  let_it_be(:namespace) { project.namespace }

  before do
    allow_next_instance_of(LearnGitlab::Project) do |learn_gitlab|
      allow(learn_gitlab).to receive(:project).and_return(project)
    end

    OnboardingProgress.onboard(namespace)
    OnboardingProgress.register(namespace, :git_write)
  end

  describe '#learn_gitlab_enabled?' do
    using RSpec::Parameterized::TableSyntax

    let_it_be(:user) { create(:user) }
    let_it_be(:project) { create(:project, namespace: user.namespace) }

    let(:params) { { namespace_id: project.namespace.to_param, project_id: project } }

    subject { helper.learn_gitlab_enabled?(project) }

    where(:onboarding, :learn_gitlab_available, :result) do
      true        | true                  | true
      true        | false                 | false
      false       | true                  | false
    end

    with_them do
      before do
        allow(OnboardingProgress).to receive(:onboarding?).with(project.namespace).and_return(onboarding)
        allow_next(LearnGitlab::Project, user).to receive(:available?).and_return(learn_gitlab_available)
      end

      context 'when signed in' do
        before do
          sign_in(user)
        end

        it { is_expected.to eq(result) }
      end
    end

    context 'when not signed in' do
      it { is_expected.to eq(false) }
    end
  end

  describe '#learn_gitlab_data' do
    subject(:learn_gitlab_data) { helper.learn_gitlab_data(project) }

    let(:onboarding_actions_data) { Gitlab::Json.parse(learn_gitlab_data[:actions]).deep_symbolize_keys }
    let(:onboarding_sections_data) { Gitlab::Json.parse(learn_gitlab_data[:sections]).deep_symbolize_keys }
    let(:onboarding_project_data) { Gitlab::Json.parse(learn_gitlab_data[:project]).deep_symbolize_keys }

    shared_examples 'has all data' do
      it 'has all actions' do
        expected_keys = [
          :issue_created,
          :git_write,
          :pipeline_created,
          :merge_request_created,
          :user_added,
          :trial_started,
          :required_mr_approvals_enabled,
          :code_owners_enabled,
          :security_scan_enabled
        ]

        expect(onboarding_actions_data.keys).to contain_exactly(*expected_keys)
      end

      it 'has all section data', :aggregate_failures do
        expect(onboarding_sections_data.keys).to contain_exactly(:deploy, :plan, :workspace)
        expect(onboarding_sections_data.values.map { |section| section.keys }).to match_array([[:svg]] * 3)
      end

      it 'has all project data', :aggregate_failures do
        expect(onboarding_project_data.keys).to contain_exactly(:name)
        expect(onboarding_project_data.values).to match_array([project.name])
      end
    end

    it_behaves_like 'has all data'

    it 'sets correct paths' do
      expect(onboarding_actions_data).to match({
                                                 trial_started: a_hash_including(
                                                   url: a_string_matching(%r{/learn_gitlab/-/issues/2\z})
                                                 ),
                                                 pipeline_created: a_hash_including(
                                                   url: a_string_matching(%r{/learn_gitlab/-/issues/7\z})
                                                 ),
                                                 code_owners_enabled: a_hash_including(
                                                   url: a_string_matching(%r{/learn_gitlab/-/issues/10\z})
                                                 ),
                                                 required_mr_approvals_enabled: a_hash_including(
                                                   url: a_string_matching(%r{/learn_gitlab/-/issues/11\z})
                                                 ),
                                                 issue_created: a_hash_including(
                                                   url: a_string_matching(%r{/learn_gitlab/-/issues\z})
                                                 ),
                                                 git_write: a_hash_including(
                                                   url: a_string_matching(%r{/learn_gitlab\z})
                                                 ),
                                                 user_added: a_hash_including(
                                                   url: a_string_matching(%r{/learn_gitlab/-/project_members\z})
                                                 ),
                                                 merge_request_created: a_hash_including(
                                                   url: a_string_matching(%r{/learn_gitlab/-/merge_requests\z})
                                                 ),
                                                 security_scan_enabled: a_hash_including(
                                                   url: a_string_matching(%r{/learn_gitlab/-/security/configuration\z})
                                                 )
                                               })
    end

    it 'sets correct completion statuses' do
      expect(onboarding_actions_data).to match({
                                                 issue_created: a_hash_including(completed: false),
                                                 git_write: a_hash_including(completed: true),
                                                 pipeline_created: a_hash_including(completed: false),
                                                 merge_request_created: a_hash_including(completed: false),
                                                 user_added: a_hash_including(completed: false),
                                                 trial_started: a_hash_including(completed: false),
                                                 required_mr_approvals_enabled: a_hash_including(completed: false),
                                                 code_owners_enabled: a_hash_including(completed: false),
                                                 security_scan_enabled: a_hash_including(completed: false)
                                               })
    end
  end
end