summaryrefslogtreecommitdiff
path: root/spec/frontend/super_sidebar/components/nav_item_spec.js
blob: 22989c1a5f9dfde2a90a3bed89d7562b44882d41 (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
import { GlBadge } from '@gitlab/ui';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import NavItem from '~/super_sidebar/components/nav_item.vue';

describe('NavItem component', () => {
  let wrapper;

  const findLink = () => wrapper.findByTestId('nav-item-link');
  const findPill = () => wrapper.findComponent(GlBadge);
  const createWrapper = (item, props = {}) => {
    wrapper = shallowMountExtended(NavItem, {
      propsData: {
        item,
        ...props,
      },
    });
  };

  describe('pills', () => {
    it.each([0, 5, 3.4, 'foo', '10%'])('item with pill_data `%p` renders a pill', (pillCount) => {
      createWrapper({ title: 'Foo', pill_count: pillCount });

      expect(findPill().text()).toEqual(pillCount.toString());
    });

    it.each([null, undefined, false, true, '', NaN, Number.POSITIVE_INFINITY])(
      'item with pill_data `%p` renders no pill',
      (pillCount) => {
        createWrapper({ title: 'Foo', pill_count: pillCount });

        expect(findPill().exists()).toEqual(false);
      },
    );
  });

  it('applies custom link classes', () => {
    const customClass = 'customClass';
    createWrapper(
      { title: 'Foo' },
      {
        linkClasses: {
          [customClass]: true,
        },
      },
    );

    expect(findLink().attributes('class')).toContain(customClass);
  });
});