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

nav_item_router_link_spec.js « components « super_sidebar « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a7ca56325fee72f033ba06ea4692041bb2735cb1 (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
import { RouterLinkStub } from '@vue/test-utils';
import { mountExtended } from 'helpers/vue_test_utils_helper';
import NavItemRouterLink from '~/super_sidebar/components/nav_item_router_link.vue';

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

  const createWrapper = ({ item, routerLinkSlotProps = {} }) => {
    wrapper = mountExtended(NavItemRouterLink, {
      propsData: {
        item,
      },
      stubs: {
        RouterLink: {
          ...RouterLinkStub,
          render() {
            const children = this.$scopedSlots.default({
              href: '/foo',
              isActive: false,
              navigate: jest.fn(),
              ...routerLinkSlotProps,
            });
            return children;
          },
        },
      },
    });
  };

  describe('when `RouterLink` is not active', () => {
    it('renders an anchor tag without active CSS class and `aria-current` attribute', () => {
      createWrapper({ item: { title: 'foo', to: { name: 'foo' } } });

      expect(wrapper.attributes()).toEqual({
        href: '/foo',
        custom: '',
      });
    });
  });

  describe('when `RouterLink` is active', () => {
    it('renders an anchor tag with active CSS class and `aria-current="page"`', () => {
      createWrapper({
        item: { title: 'foo', to: { name: 'foo' } },
        routerLinkSlotProps: { isActive: true },
      });

      expect(wrapper.findComponent(RouterLinkStub).props('activeClass')).toBe('gl-bg-t-gray-a-08');
      expect(wrapper.attributes()).toEqual({
        href: '/foo',
        'aria-current': 'page',
        custom: '',
      });
    });
  });
});