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

admin_menus_shared_examples.rb « menus « admin « sidebars « lib « shared_examples « support « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4168d8675356d8f436c6aa1d401baea7187ce01c (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
# frozen_string_literal: true

RSpec.shared_examples 'Admin menu' do |link:, title:, icon:, separated: false|
  let_it_be(:user) { build(:user, :admin) }

  before do
    allow(user).to receive(:can_admin_all_resources?).and_return(true)
  end

  let(:context) { Sidebars::Context.new(current_user: user, container: nil) }

  subject { described_class.new(context) }

  it 'renders the correct link' do
    expect(subject.link).to match link
  end

  it 'renders the correct title' do
    expect(subject.title).to eq title
  end

  it 'renders the correct icon' do
    expect(subject.sprite_icon).to be icon
  end

  it 'renders the separator if needed' do
    expect(subject.separated?).to be separated
  end

  describe '#render?' do
    context 'when user is admin' do
      it 'renders' do
        expect(subject.render?).to be true
      end
    end

    context 'when user is not admin' do
      it 'does not render' do
        expect(described_class.new(Sidebars::Context.new(current_user: build(:user),
          container: nil)).render?).to be false
      end
    end

    context 'when user is not logged in' do
      it 'does not render' do
        expect(described_class.new(Sidebars::Context.new(current_user: nil, container: nil)).render?).to be false
      end
    end
  end
end

RSpec.shared_examples 'Admin menu without sub menus' do |active_routes:|
  let_it_be(:user) { build(:user, :admin) }

  let(:context) { Sidebars::Context.new(current_user: user, container: nil) }

  subject { described_class.new(context) }

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

  it 'defines correct active route' do
    expect(subject.active_routes).to eq active_routes
  end
end

RSpec.shared_examples 'Admin menu with sub menus' do
  let_it_be(:user) { build(:user, :admin) }

  let(:context) { Sidebars::Context.new(current_user: user, container: nil) }

  subject { described_class.new(context) }

  it 'contains submemus' do
    expect(subject.has_items?).to be true
  end
end

RSpec.shared_examples 'Admin menu with extra container html options' do |extra_container_html_options:|
  let_it_be(:user) { build(:user, :admin) }

  let(:context) { Sidebars::Context.new(current_user: user, container: nil) }

  subject { described_class.new(context) }

  it 'contains extra container html options' do
    expect(subject.extra_container_html_options).to eq extra_container_html_options
  end
end