2019-12-26 22:10:19 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2022-04-04 11:22:00 +05:30
|
|
|
import { nextTick } from 'vue';
|
2021-11-11 11:23:49 +05:30
|
|
|
import paginatedTreeQuery from 'shared_queries/repository/paginated_tree.query.graphql';
|
2019-12-26 22:10:19 +05:30
|
|
|
import FilePreview from '~/repository/components/preview/index.vue';
|
2020-11-24 15:15:51 +05:30
|
|
|
import FileTable from '~/repository/components/table/index.vue';
|
2022-01-26 12:08:38 +05:30
|
|
|
import TreeContent from 'jh_else_ce/repository/components/tree_content.vue';
|
2021-11-18 22:05:49 +05:30
|
|
|
import { loadCommits, isRequested, resetRequestedCommits } from '~/repository/commits_service';
|
2023-03-17 16:20:25 +05:30
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
|
|
|
import { createAlert } from '~/flash';
|
|
|
|
import { i18n } from '~/repository/constants';
|
|
|
|
import { graphQLErrors } from '../mock_data';
|
2021-11-18 22:05:49 +05:30
|
|
|
|
|
|
|
jest.mock('~/repository/commits_service', () => ({
|
|
|
|
loadCommits: jest.fn(() => Promise.resolve()),
|
|
|
|
isRequested: jest.fn(),
|
|
|
|
resetRequestedCommits: jest.fn(),
|
|
|
|
}));
|
2023-03-17 16:20:25 +05:30
|
|
|
jest.mock('~/flash');
|
2019-12-26 22:10:19 +05:30
|
|
|
|
|
|
|
let vm;
|
|
|
|
let $apollo;
|
2023-03-17 16:20:25 +05:30
|
|
|
const mockResponse = jest.fn().mockReturnValue(Promise.resolve({ data: {} }));
|
2019-12-26 22:10:19 +05:30
|
|
|
|
2023-03-17 16:20:25 +05:30
|
|
|
function factory(path, appoloMockResponse = mockResponse) {
|
2019-12-26 22:10:19 +05:30
|
|
|
$apollo = {
|
2023-03-17 16:20:25 +05:30
|
|
|
query: appoloMockResponse,
|
2019-12-26 22:10:19 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
vm = shallowMount(TreeContent, {
|
|
|
|
propsData: {
|
|
|
|
path,
|
|
|
|
},
|
|
|
|
mocks: {
|
|
|
|
$apollo,
|
|
|
|
},
|
2021-09-30 23:02:18 +05:30
|
|
|
provide: {
|
|
|
|
glFeatures: {
|
|
|
|
increasePageSizeExponentially: true,
|
2021-11-11 11:23:49 +05:30
|
|
|
paginatedTreeGraphqlQuery: true,
|
2021-09-30 23:02:18 +05:30
|
|
|
},
|
|
|
|
},
|
2019-12-26 22:10:19 +05:30
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('Repository table component', () => {
|
2022-11-25 23:54:43 +05:30
|
|
|
const findFileTable = () => vm.findComponent(FileTable);
|
2021-09-30 23:02:18 +05:30
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
afterEach(() => {
|
|
|
|
vm.destroy();
|
|
|
|
});
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
it('renders file preview', async () => {
|
2019-12-26 22:10:19 +05:30
|
|
|
factory('/');
|
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
// setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
|
|
|
|
// eslint-disable-next-line no-restricted-syntax
|
2019-12-26 22:10:19 +05:30
|
|
|
vm.setData({ entries: { blobs: [{ name: 'README.md' }] } });
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
expect(vm.findComponent(FilePreview).exists()).toBe(true);
|
2020-10-24 23:57:45 +05:30
|
|
|
});
|
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
it('trigger fetchFiles and resetRequestedCommits when mounted', async () => {
|
2020-10-24 23:57:45 +05:30
|
|
|
factory('/');
|
|
|
|
|
|
|
|
jest.spyOn(vm.vm, 'fetchFiles').mockImplementation(() => {});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
expect(vm.vm.fetchFiles).toHaveBeenCalled();
|
2021-11-18 22:05:49 +05:30
|
|
|
expect(resetRequestedCommits).toHaveBeenCalled();
|
2019-12-26 22:10:19 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('normalizeData', () => {
|
|
|
|
it('normalizes edge nodes', () => {
|
|
|
|
factory('/');
|
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
const output = vm.vm.normalizeData('blobs', { nodes: ['1', '2'] });
|
2019-12-26 22:10:19 +05:30
|
|
|
|
|
|
|
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-10-24 23:57:45 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
describe('FileTable showMore', () => {
|
2020-10-24 23:57:45 +05:30
|
|
|
describe('when is present', () => {
|
|
|
|
beforeEach(async () => {
|
|
|
|
factory('/');
|
|
|
|
});
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
it('is changes hasShowMore to false when "showMore" event is emitted', async () => {
|
2021-09-30 23:02:18 +05:30
|
|
|
findFileTable().vm.$emit('showMore');
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
expect(vm.vm.hasShowMore).toBe(false);
|
2020-10-24 23:57:45 +05:30
|
|
|
});
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
it('changes clickedShowMore when "showMore" event is emitted', async () => {
|
2021-09-30 23:02:18 +05:30
|
|
|
findFileTable().vm.$emit('showMore');
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
expect(vm.vm.clickedShowMore).toBe(true);
|
|
|
|
});
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
it('triggers fetchFiles when "showMore" event is emitted', () => {
|
2020-10-24 23:57:45 +05:30
|
|
|
jest.spyOn(vm.vm, 'fetchFiles');
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
findFileTable().vm.$emit('showMore');
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
expect(vm.vm.fetchFiles).toHaveBeenCalled();
|
2020-10-24 23:57:45 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('is not rendered if less than 1000 files', async () => {
|
|
|
|
factory('/');
|
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
// setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
|
|
|
|
// eslint-disable-next-line no-restricted-syntax
|
2020-10-24 23:57:45 +05:30
|
|
|
vm.setData({ fetchCounter: 5, clickedShowMore: false });
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
expect(vm.vm.hasShowMore).toBe(false);
|
2020-10-24 23:57:45 +05:30
|
|
|
});
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
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-10-24 23:57:45 +05:30
|
|
|
factory('/');
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
const blobs = new Array(totalBlobs).fill('fakeBlob');
|
2022-03-02 08:16:31 +05:30
|
|
|
// setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
|
|
|
|
// eslint-disable-next-line no-restricted-syntax
|
2021-09-30 23:02:18 +05:30
|
|
|
vm.setData({ entries: { blobs }, pagesLoaded });
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
2021-09-30 23:02:18 +05:30
|
|
|
|
|
|
|
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('/');
|
2022-03-02 08:16:31 +05:30
|
|
|
// setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
|
|
|
|
// eslint-disable-next-line no-restricted-syntax
|
2021-09-30 23:02:18 +05:30
|
|
|
vm.setData({ fetchCounter });
|
|
|
|
|
|
|
|
vm.vm.fetchFiles();
|
|
|
|
|
|
|
|
expect($apollo.query).toHaveBeenCalledWith({
|
2021-11-11 11:23:49 +05:30
|
|
|
query: paginatedTreeQuery,
|
2021-09-30 23:02:18 +05:30
|
|
|
variables: {
|
|
|
|
pageSize,
|
|
|
|
nextPageCursor: '',
|
|
|
|
path: '/',
|
|
|
|
projectPath: '',
|
|
|
|
ref: '',
|
|
|
|
},
|
|
|
|
});
|
2020-10-24 23:57:45 +05:30
|
|
|
});
|
|
|
|
});
|
2021-11-18 22:05:49 +05:30
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
describe('commit data', () => {
|
2021-11-18 22:05:49 +05:30
|
|
|
const path = 'some/path';
|
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
it('loads commit data for both top and bottom batches when row-appear event is emitted', () => {
|
|
|
|
const rowNumber = 50;
|
2021-11-18 22:05:49 +05:30
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
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-11-18 22:05:49 +05:30
|
|
|
});
|
2023-03-17 16:20:25 +05:30
|
|
|
|
|
|
|
describe('error handling', () => {
|
|
|
|
const gitalyError = { graphQLErrors };
|
|
|
|
it.each`
|
|
|
|
error | message
|
|
|
|
${gitalyError} | ${i18n.gitalyError}
|
|
|
|
${'Error'} | ${i18n.generalError}
|
|
|
|
`('should show an expected error', async ({ error, message }) => {
|
|
|
|
factory('/', jest.fn().mockRejectedValue(error));
|
|
|
|
await waitForPromises();
|
|
|
|
expect(createAlert).toHaveBeenCalledWith({ message, captureError: true });
|
|
|
|
});
|
|
|
|
});
|
2019-12-26 22:10:19 +05:30
|
|
|
});
|