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

index_spec.js « table « components « repository « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 697d2dcc7f5d2077b4e87ef98c25ac9cd0581695 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import { GlSkeletonLoader, GlButton } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import { nextTick } from 'vue';
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',
    webPath: '/blob',
  },
  {
    id: '124abc',
    sha: '124abc',
    flatPath: 'blob2',
    name: 'blob2.md',
    type: 'blob',
    webUrl: 'http://test.com',
  },
  {
    id: '125abc',
    sha: '125abc',
    flatPath: 'blob3',
    name: 'blob3.md',
    type: 'blob',
    webUrl: 'http://test.com',
    mode: '120000',
  },
];

const MOCK_COMMITS = [
  {
    fileName: 'blob.md',
    filePath: 'test_dir/blob.md',
    type: 'blob',
    commit: {
      message: 'Updated blob.md',
    },
  },
  {
    fileName: 'blob2.md',
    filePath: 'test_dir/blob2.md',
    type: 'blob',
    commit: {
      message: 'Updated blob2.md',
    },
  },
  {
    fileName: 'blob3.md',
    filePath: 'test_dir/blob3.md',
    type: 'blob',
    commit: {
      message: 'Updated blob3.md',
    },
  },
  {
    fileName: 'root_blob.md',
    filePath: '/root_blob.md',
    type: 'blob',
    commit: {
      message: 'Updated root_blob.md',
    },
  },
];

function factory({ path, isLoading = false, hasMore = true, entries = {}, commits = [] }) {
  vm = shallowMount(Table, {
    propsData: {
      path,
      isLoading,
      entries,
      hasMore,
      commits,
    },
    mocks: {
      $apollo,
    },
    provide: {
      glFeatures: { lazyLoadCommits: true },
    },
  });
}

const findTableRows = () => vm.findAllComponents(TableRow);

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

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

    // setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
    // eslint-disable-next-line no-restricted-syntax
    vm.setData({ ref });

    await nextTick();
    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.findComponent(GlSkeletonLoader).exists()).toBe(true);
  });

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

    const rows = findTableRows();

    expect(rows.length).toEqual(3);
    expect(rows.at(2).attributes().mode).toEqual('120000');
    expect(rows.at(2).props().rowNumber).toBe(2);
    expect(rows.at(2).props().commitInfo).toEqual(MOCK_COMMITS[2]);
  });

  it('renders correct commit info for blobs in the root', () => {
    factory({
      path: '/',
      entries: {
        blobs: [
          {
            id: '126abc',
            sha: '126abc',
            flatPath: 'root_blob.md',
            name: 'root_blob.md',
            type: 'blob',
            webUrl: 'http://test.com',
            mode: '120000',
          },
        ],
      },
      commits: MOCK_COMMITS,
    });

    expect(findTableRows().at(0).props().commitInfo).toEqual(MOCK_COMMITS[3]);
  });

  describe('Show more button', () => {
    const showMoreButton = () => vm.find(GlButton);

    it.each`
      hasMore  | expectButtonToExist
      ${true}  | ${true}
      ${false} | ${false}
    `('renders correctly', ({ hasMore, expectButtonToExist }) => {
      factory({ path: '/', hasMore });
      expect(showMoreButton().exists()).toBe(expectButtonToExist);
    });

    it('when is clicked, emits showMore event', async () => {
      factory({ path: '/' });

      showMoreButton().vm.$emit('click');

      await nextTick();

      expect(vm.emitted('showMore')).toHaveLength(1);
    });
  });
});