summaryrefslogtreecommitdiff
path: root/spec/frontend/repository/components/table/index_spec.js
blob: 41450becabb46e40c569209e56854b56cc2235a6 (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
import { shallowMount } from '@vue/test-utils';
import { GlSkeletonLoading } from '@gitlab/ui';
import Table from '~/repository/components/table/index.vue';
import TableRow from '~/repository/components/table/row.vue';

let vm;
let $apollo;

const MOCK_BLOBS = [
  {
    id: '123abc',
    sha: '123abc',
    flatPath: 'blob',
    name: 'blob.md',
    type: 'blob',
    webUrl: 'http://test.com',
  },
  {
    id: '124abc',
    sha: '124abc',
    flatPath: 'blob2',
    name: 'blob2.md',
    type: 'blob',
    webUrl: 'http://test.com',
  },
];

function factory({ path, isLoading = false, entries = {} }) {
  vm = shallowMount(Table, {
    propsData: {
      path,
      isLoading,
      entries,
    },
    mocks: {
      $apollo,
    },
  });
}

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

  it.each`
    path            | ref
    ${'/'}          | ${'master'}
    ${'app/assets'} | ${'master'}
    ${'/'}          | ${'test'}
  `('renders table caption for $ref in $path', ({ path, ref }) => {
    factory({ path });

    vm.setData({ ref });

    expect(vm.find('.table').attributes('aria-label')).toEqual(
      `Files, directories, and submodules in the path ${path} for commit reference ${ref}`,
    );
  });

  it('shows loading icon', () => {
    factory({ path: '/', isLoading: true });

    expect(vm.find(GlSkeletonLoading).exists()).toBe(true);
  });

  it('renders table rows', () => {
    factory({
      path: '/',
      entries: {
        blobs: MOCK_BLOBS,
      },
    });

    expect(vm.find(TableRow).exists()).toBe(true);
    expect(vm.findAll(TableRow).length).toBe(2);
  });
});