File: menu_item_spec.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (47 lines) | stat: -rw-r--r-- 1,506 bytes parent folder | download
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
# frozen_string_literal: true

require 'fast_spec_helper'

RSpec.describe Sidebars::MenuItem, feature_category: :navigation do
  let(:title) { 'foo' }
  let(:html_options) { {} }
  let(:extra) { {} }
  let(:menu_item) { described_class.new(title: title, active_routes: {}, link: '', container_html_options: html_options, **extra) }

  it 'includes by default aria-label attribute set to the title' do
    expect(menu_item.container_html_options).to eq({ aria: { label: title } })
  end

  context 'when aria-label is overridde during initialization' do
    let(:html_options) { { aria: { label: 'bar' } } }

    it 'sets the aria-label to the new attribute' do
      expect(menu_item.container_html_options).to eq html_options
    end
  end

  describe "#serialize_for_super_sidebar" do
    let(:html_options) { { class: 'custom-class' } }
    let(:extra) { { avatar: '/avatar.png', entity_id: 123 } }

    subject { menu_item.serialize_for_super_sidebar }

    it 'includes custom CSS classes' do
      expect(subject[:link_classes]).to be('custom-class')
    end

    it 'includes avatar data' do
      expect(subject[:avatar]).to be('/avatar.png')
      expect(subject[:entity_id]).to be(123)
    end

    context 'with pill data' do
      let(:extra) { { has_pill: true, pill_count: '5', pill_count_field: 'countField' } }

      it 'includes pill count data' do
        expect(subject[:pill_count]).to eq('5')
        expect(subject[:pill_count_field]).to eq('countField')
      end
    end
  end
end