summaryrefslogtreecommitdiff
path: root/spec/lib/sidebars/projects/menus/learn_gitlab_menu_spec.rb
blob: 4ae29f28f3a9023a3177c78b475b61032eb97249 (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

require 'spec_helper'

RSpec.describe Sidebars::Projects::Menus::LearnGitlabMenu do
  let_it_be(:project) { build(:project) }
  let_it_be(:learn_gitlab_enabled) { true }

  let(:context) do
    Sidebars::Projects::Context.new(
      current_user: nil,
      container: project,
      learn_gitlab_enabled: learn_gitlab_enabled
    )
  end

  subject { described_class.new(context) }

  it 'does not contain any sub menu' do
    expect(subject.has_items?).to be false
  end

  describe '#nav_link_html_options' do
    let_it_be(:data_tracking) do
      {
        class: 'home',
        data: {
          track_label: 'learn_gitlab'
        }
      }
    end

    specify do
      expect(subject.nav_link_html_options).to eq(data_tracking)
    end
  end

  describe '#render?' do
    context 'when learn gitlab experiment is enabled' do
      it 'returns true' do
        expect(subject.render?).to eq true
      end
    end

    context 'when learn gitlab experiment is disabled' do
      let(:learn_gitlab_enabled) { false }

      it 'returns false' do
        expect(subject.render?).to eq false
      end
    end
  end

  describe '#has_pill?' do
    context 'when learn gitlab experiment is enabled' do
      it 'returns true' do
        expect(subject.has_pill?).to eq true
      end
    end

    context 'when learn gitlab experiment is disabled' do
      let(:learn_gitlab_enabled) { false }

      it 'returns false' do
        expect(subject.has_pill?).to eq false
      end
    end
  end

  describe '#pill_count' do
    it 'returns pill count' do
      expect_next_instance_of(Onboarding::Completion) do |onboarding|
        expect(onboarding).to receive(:percentage).and_return(20)
      end

      expect(subject.pill_count).to eq '20%'
    end
  end
end