2019-11-07 13:06:21 -05:00
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2022-01-25 10:12:32 -05:00
|
|
|
import { nextTick } from 'vue';
|
2021-09-02 11:11:35 -04:00
|
|
|
import paginatedTreeQuery from 'shared_queries/repository/paginated_tree.query.graphql';
|
2019-11-07 13:06:21 -05:00
|
|
|
import FilePreview from '~/repository/components/preview/index.vue';
|
2020-08-21 08:10:22 -04:00
|
|
|
import FileTable from '~/repository/components/table/index.vue';
|
2021-12-06 07:10:19 -05:00
|
|
|
import TreeContent from 'jh_else_ce/repository/components/tree_content.vue';
|
2021-10-08 14:13:02 -04:00
|
|
|
import { loadCommits, isRequested, resetRequestedCommits } from '~/repository/commits_service';
|
|
|
|
|
|
|
|
jest.mock('~/repository/commits_service', () => ({
|
|
|
|
loadCommits: jest.fn(() => Promise.resolve()),
|
|
|
|
isRequested: jest.fn(),
|
|
|
|
resetRequestedCommits: jest.fn(),
|
|
|
|
}));
|
2019-11-07 13:06:21 -05:00
|
|
|
|
|
|
|
let vm;
|
|
|
|
let $apollo;
|
|
|
|
|
|
|
|
function factory(path, data = () => ({})) {
|
|
|
|
$apollo = {
|
|
|
|
query: jest.fn().mockReturnValue(Promise.resolve({ data: data() })),
|
|
|
|
};
|
|
|
|
|
|
|
|
vm = shallowMount(TreeContent, {
|
|
|
|
propsData: {
|
|
|
|
path,
|
|
|
|
},
|
|
|
|
mocks: {
|
|
|
|
$apollo,
|
|
|
|
},
|
2021-07-14 11:09:57 -04:00
|
|
|
provide: {
|
|
|
|
glFeatures: {
|
|
|
|
increasePageSizeExponentially: true,
|
2021-09-02 11:11:35 -04:00
|
|
|
paginatedTreeGraphqlQuery: true,
|
2021-10-08 14:13:02 -04:00
|
|
|
lazyLoadCommits: true,
|
2021-07-14 11:09:57 -04:00
|
|
|
},
|
|
|
|
},
|
2019-11-07 13:06:21 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('Repository table component', () => {
|
2021-07-12 08:09:39 -04:00
|
|
|
const findFileTable = () => vm.find(FileTable);
|
|
|
|
|
2019-11-07 13:06:21 -05:00
|
|
|
afterEach(() => {
|
|
|
|
vm.destroy();
|
|
|
|
});
|
|
|
|
|
2020-08-12 08:10:25 -04:00
|
|
|
it('renders file preview', async () => {
|
2019-11-07 13:06:21 -05:00
|
|
|
factory('/');
|
|
|
|
|
2021-12-29 10:10:45 -05:00
|
|
|
// setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
|
|
|
|
// eslint-disable-next-line no-restricted-syntax
|
2019-11-14 07:06:30 -05:00
|
|
|
vm.setData({ entries: { blobs: [{ name: 'README.md' }] } });
|
2019-11-07 13:06:21 -05:00
|
|
|
|
2022-01-25 10:12:32 -05:00
|
|
|
await nextTick();
|
2020-08-12 08:10:25 -04:00
|
|
|
|
|
|
|
expect(vm.find(FilePreview).exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
2021-10-08 14:13:02 -04:00
|
|
|
it('trigger fetchFiles and resetRequestedCommits when mounted', async () => {
|
2020-08-12 08:10:25 -04:00
|
|
|
factory('/');
|
|
|
|
|
|
|
|
jest.spyOn(vm.vm, 'fetchFiles').mockImplementation(() => {});
|
|
|
|
|
2022-01-25 10:12:32 -05:00
|
|
|
await nextTick();
|
2020-08-12 08:10:25 -04:00
|
|
|
|
|
|
|
expect(vm.vm.fetchFiles).toHaveBeenCalled();
|
2021-10-08 14:13:02 -04:00
|
|
|
expect(resetRequestedCommits).toHaveBeenCalled();
|
2019-11-07 13:06:21 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('normalizeData', () => {
|
|
|
|
it('normalizes edge nodes', () => {
|
|
|
|
factory('/');
|
|
|
|
|
2021-09-02 11:11:35 -04:00
|
|
|
const output = vm.vm.normalizeData('blobs', { nodes: ['1', '2'] });
|
2019-11-07 13:06:21 -05:00
|
|
|
|
|
|
|
expect(output).toEqual(['1', '2']);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('hasNextPage', () => {
|
|
|
|
it('returns undefined when hasNextPage is false', () => {
|
|
|
|
factory('/');
|
|
|
|
|
|
|
|
const output = vm.vm.hasNextPage({
|
|
|
|
trees: { pageInfo: { hasNextPage: false } },
|
|
|
|
submodules: { pageInfo: { hasNextPage: false } },
|
|
|
|
blobs: { pageInfo: { hasNextPage: false } },
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(output).toBe(undefined);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns pageInfo object when hasNextPage is true', () => {
|
|
|
|
factory('/');
|
|
|
|
|
|
|
|
const output = vm.vm.hasNextPage({
|
|
|
|
trees: { pageInfo: { hasNextPage: false } },
|
|
|
|
submodules: { pageInfo: { hasNextPage: false } },
|
|
|
|
blobs: { pageInfo: { hasNextPage: true, nextCursor: 'test' } },
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(output).toEqual({ hasNextPage: true, nextCursor: 'test' });
|
|
|
|
});
|
|
|
|
});
|
2020-08-12 08:10:25 -04:00
|
|
|
|
2020-08-21 08:10:22 -04:00
|
|
|
describe('FileTable showMore', () => {
|
2020-08-12 08:10:25 -04:00
|
|
|
describe('when is present', () => {
|
|
|
|
beforeEach(async () => {
|
|
|
|
factory('/');
|
|
|
|
});
|
|
|
|
|
2020-08-21 08:10:22 -04:00
|
|
|
it('is changes hasShowMore to false when "showMore" event is emitted', async () => {
|
2021-07-12 08:09:39 -04:00
|
|
|
findFileTable().vm.$emit('showMore');
|
2020-08-21 08:10:22 -04:00
|
|
|
|
2022-01-25 10:12:32 -05:00
|
|
|
await nextTick();
|
2020-08-12 08:10:25 -04:00
|
|
|
|
2020-08-21 08:10:22 -04:00
|
|
|
expect(vm.vm.hasShowMore).toBe(false);
|
2020-08-12 08:10:25 -04:00
|
|
|
});
|
|
|
|
|
2020-08-21 08:10:22 -04:00
|
|
|
it('changes clickedShowMore when "showMore" event is emitted', async () => {
|
2021-07-12 08:09:39 -04:00
|
|
|
findFileTable().vm.$emit('showMore');
|
2020-08-12 08:10:25 -04:00
|
|
|
|
2022-01-25 10:12:32 -05:00
|
|
|
await nextTick();
|
2020-08-12 08:10:25 -04:00
|
|
|
|
|
|
|
expect(vm.vm.clickedShowMore).toBe(true);
|
|
|
|
});
|
|
|
|
|
2020-08-21 08:10:22 -04:00
|
|
|
it('triggers fetchFiles when "showMore" event is emitted', () => {
|
2020-08-12 08:10:25 -04:00
|
|
|
jest.spyOn(vm.vm, 'fetchFiles');
|
|
|
|
|
2021-07-12 08:09:39 -04:00
|
|
|
findFileTable().vm.$emit('showMore');
|
2020-08-12 08:10:25 -04:00
|
|
|
|
2020-08-21 08:10:22 -04:00
|
|
|
expect(vm.vm.fetchFiles).toHaveBeenCalled();
|
2020-08-12 08:10:25 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('is not rendered if less than 1000 files', async () => {
|
|
|
|
factory('/');
|
|
|
|
|
2021-12-29 10:10:45 -05:00
|
|
|
// setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
|
|
|
|
// eslint-disable-next-line no-restricted-syntax
|
2020-08-12 08:10:25 -04:00
|
|
|
vm.setData({ fetchCounter: 5, clickedShowMore: false });
|
|
|
|
|
2022-01-25 10:12:32 -05:00
|
|
|
await nextTick();
|
2020-08-12 08:10:25 -04:00
|
|
|
|
2020-08-21 08:10:22 -04:00
|
|
|
expect(vm.vm.hasShowMore).toBe(false);
|
2020-08-12 08:10:25 -04:00
|
|
|
});
|
|
|
|
|
2021-07-12 08:09:39 -04:00
|
|
|
it.each`
|
|
|
|
totalBlobs | pagesLoaded | limitReached
|
|
|
|
${900} | ${1} | ${false}
|
|
|
|
${1000} | ${1} | ${true}
|
|
|
|
${1002} | ${1} | ${true}
|
|
|
|
${1002} | ${2} | ${false}
|
|
|
|
${1900} | ${2} | ${false}
|
|
|
|
${2000} | ${2} | ${true}
|
|
|
|
`('has limit of 1000 entries per page', async ({ totalBlobs, pagesLoaded, limitReached }) => {
|
2020-08-12 08:10:25 -04:00
|
|
|
factory('/');
|
|
|
|
|
2021-07-12 08:09:39 -04:00
|
|
|
const blobs = new Array(totalBlobs).fill('fakeBlob');
|
2021-12-29 10:10:45 -05:00
|
|
|
// setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
|
|
|
|
// eslint-disable-next-line no-restricted-syntax
|
2021-07-12 08:09:39 -04:00
|
|
|
vm.setData({ entries: { blobs }, pagesLoaded });
|
|
|
|
|
2022-01-25 10:12:32 -05:00
|
|
|
await nextTick();
|
2021-07-12 08:09:39 -04:00
|
|
|
|
|
|
|
expect(findFileTable().props('hasMore')).toBe(limitReached);
|
|
|
|
});
|
|
|
|
|
|
|
|
it.each`
|
|
|
|
fetchCounter | pageSize
|
|
|
|
${0} | ${10}
|
|
|
|
${2} | ${30}
|
|
|
|
${4} | ${50}
|
|
|
|
${6} | ${70}
|
|
|
|
${8} | ${90}
|
|
|
|
${10} | ${100}
|
|
|
|
${20} | ${100}
|
|
|
|
${100} | ${100}
|
|
|
|
${200} | ${100}
|
|
|
|
`('exponentially increases page size, to a maximum of 100', ({ fetchCounter, pageSize }) => {
|
|
|
|
factory('/');
|
2021-12-29 10:10:45 -05:00
|
|
|
// setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
|
|
|
|
// eslint-disable-next-line no-restricted-syntax
|
2021-07-12 08:09:39 -04:00
|
|
|
vm.setData({ fetchCounter });
|
|
|
|
|
|
|
|
vm.vm.fetchFiles();
|
|
|
|
|
|
|
|
expect($apollo.query).toHaveBeenCalledWith({
|
2021-09-02 11:11:35 -04:00
|
|
|
query: paginatedTreeQuery,
|
2021-07-12 08:09:39 -04:00
|
|
|
variables: {
|
|
|
|
pageSize,
|
|
|
|
nextPageCursor: '',
|
|
|
|
path: '/',
|
|
|
|
projectPath: '',
|
|
|
|
ref: '',
|
|
|
|
},
|
|
|
|
});
|
2020-08-12 08:10:25 -04:00
|
|
|
});
|
|
|
|
});
|
2021-10-08 14:13:02 -04:00
|
|
|
|
2021-12-08 10:13:43 -05:00
|
|
|
describe('commit data', () => {
|
2021-10-08 14:13:02 -04:00
|
|
|
const path = 'some/path';
|
|
|
|
|
2021-12-08 10:13:43 -05:00
|
|
|
it('loads commit data for both top and bottom batches when row-appear event is emitted', () => {
|
|
|
|
const rowNumber = 50;
|
2021-10-08 14:13:02 -04:00
|
|
|
|
2021-12-08 10:13:43 -05:00
|
|
|
factory(path);
|
|
|
|
findFileTable().vm.$emit('row-appear', rowNumber);
|
|
|
|
|
|
|
|
expect(isRequested).toHaveBeenCalledWith(rowNumber);
|
|
|
|
|
|
|
|
expect(loadCommits.mock.calls).toEqual([
|
|
|
|
['', path, '', rowNumber],
|
|
|
|
['', path, '', rowNumber - 25],
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('loads commit data once if rowNumber is zero', () => {
|
|
|
|
factory(path);
|
|
|
|
findFileTable().vm.$emit('row-appear', 0);
|
|
|
|
|
|
|
|
expect(loadCommits.mock.calls).toEqual([['', path, '', 0]]);
|
|
|
|
});
|
2021-10-08 14:13:02 -04:00
|
|
|
});
|
2019-11-07 13:06:21 -05:00
|
|
|
});
|