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

breadcrumbs_spec.js « components « repository « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a0dc608ddc993a2b0a408c6df876bb4d4f1c521e (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
import { shallowMount, RouterLinkStub } from '@vue/test-utils';
import { GlDropdown } from '@gitlab/ui';
import Breadcrumbs from '~/repository/components/breadcrumbs.vue';

let vm;

function factory(currentPath, extraProps = {}) {
  vm = shallowMount(Breadcrumbs, {
    propsData: {
      currentPath,
      ...extraProps,
    },
    stubs: {
      RouterLink: RouterLinkStub,
    },
  });
}

describe('Repository breadcrumbs component', () => {
  afterEach(() => {
    vm.destroy();
  });

  it.each`
    path                        | linkCount
    ${'/'}                      | ${1}
    ${'app'}                    | ${2}
    ${'app/assets'}             | ${3}
    ${'app/assets/javascripts'} | ${4}
  `('renders $linkCount links for path $path', ({ path, linkCount }) => {
    factory(path);

    expect(vm.findAll(RouterLinkStub).length).toEqual(linkCount);
  });

  it('escapes hash in directory path', () => {
    factory('app/assets/javascripts#');

    expect(vm.findAll(RouterLinkStub).at(3).props('to')).toEqual(
      '/-/tree/app/assets/javascripts%23',
    );
  });

  it('renders last link as active', () => {
    factory('app/assets');

    expect(vm.findAll(RouterLinkStub).at(2).attributes('aria-current')).toEqual('page');
  });

  it('does not render add to tree dropdown when permissions are false', () => {
    factory('/', { canCollaborate: false });

    vm.setData({ userPermissions: { forkProject: false, createMergeRequestIn: false } });

    return vm.vm.$nextTick(() => {
      expect(vm.find(GlDropdown).exists()).toBe(false);
    });
  });

  it('renders add to tree dropdown when permissions are true', () => {
    factory('/', { canCollaborate: true });

    vm.setData({ userPermissions: { forkProject: true, createMergeRequestIn: true } });

    return vm.vm.$nextTick(() => {
      expect(vm.find(GlDropdown).exists()).toBe(true);
    });
  });
});