summaryrefslogtreecommitdiff
path: root/spec/helpers/learn_gitlab_helper_spec.rb
blob: 1159fd96d597b37e6ce7d0e51e21fe02aff48e91 (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
# 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
    project.add_developer(user)

    allow(helper).to receive(:user).and_return(user)
    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 '.onboarding_actions_data' do
    subject(:onboarding_actions_data) { helper.onboarding_actions_data(project) }

    it 'has all actions' do
      expect(onboarding_actions_data.keys).to contain_exactly(
        :issue_created,
        :git_write,
        :pipeline_created,
        :merge_request_created,
        :user_added,
        :trial_started,
        :required_mr_approvals_enabled,
        :code_owners_enabled,
        :security_scan_enabled
      )
    end

    it 'sets correct path and completion status' do
      expect(onboarding_actions_data[:git_write]).to eq({
        url: project_issue_url(project, LearnGitlab::Onboarding::ACTION_ISSUE_IDS[:git_write]),
        completed: true,
        svg: helper.image_path("learn_gitlab/git_write.svg")
      })
      expect(onboarding_actions_data[:pipeline_created]).to eq({
        url: project_issue_url(project, LearnGitlab::Onboarding::ACTION_ISSUE_IDS[:pipeline_created]),
        completed: false,
        svg: helper.image_path("learn_gitlab/pipeline_created.svg")
      })
    end
  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 '.onboarding_sections_data' do
    subject(:sections) { helper.onboarding_sections_data }

    it 'has the right keys' do
      expect(sections.keys).to contain_exactly(:deploy, :plan, :workspace)
    end
    it 'has the svg' do
      expect(sections.values.map { |section| section.keys }).to eq([[:svg]] * 3)
    end
  end
end