2019-11-07 13:06:21 -05:00
|
|
|
import { shallowMount } from '@vue/test-utils';
|
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-06-03 08:10:18 -04:00
|
|
|
import TreeContent from '~/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('/');
|
|
|
|
|
2019-11-14 07:06:30 -05:00
|
|
|
vm.setData({ entries: { blobs: [{ name: 'README.md' }] } });
|
2019-11-07 13:06:21 -05:00
|
|
|
|
2020-08-12 08:10:25 -04:00
|
|
|
await vm.vm.$nextTick();
|
|
|
|
|
|
|
|
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(() => {});
|
|
|
|
|
|
|
|
await vm.vm.$nextTick();
|
|
|
|
|
|
|
|
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
|
|
|
|
2020-08-12 08:10:25 -04:00
|
|
|
await vm.vm.$nextTick();
|
|
|
|
|
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
|
|
|
|
2020-08-21 08:10:22 -04:00
|
|
|
await vm.vm.$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('/');
|
|
|
|
|
|
|
|
vm.setData({ fetchCounter: 5, clickedShowMore: false });
|
|
|
|
|
|
|
|
await vm.vm.$nextTick();
|
|
|
|
|
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');
|
|
|
|
vm.setData({ entries: { blobs }, pagesLoaded });
|
|
|
|
|
|
|
|
await vm.vm.$nextTick();
|
|
|
|
|
|
|
|
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('/');
|
|
|
|
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
|
|
|
|
|
|
|
it('loads commit data when row-appear event is emitted', () => {
|
|
|
|
const path = 'some/path';
|
|
|
|
const rowNumber = 1;
|
|
|
|
|
|
|
|
factory(path);
|
|
|
|
findFileTable().vm.$emit('row-appear', { hasCommit: false, rowNumber });
|
|
|
|
|
|
|
|
expect(isRequested).toHaveBeenCalledWith(rowNumber);
|
|
|
|
expect(loadCommits).toHaveBeenCalledWith('', path, '', rowNumber);
|
|
|
|
});
|
2019-11-07 13:06:21 -05:00
|
|
|
});
|