debian-mirror-gitlab/spec/frontend/repository/components/tree_content_spec.js

135 lines
3.3 KiB
JavaScript
Raw Normal View History

2019-12-26 22:10:19 +05:30
import { shallowMount } from '@vue/test-utils';
2020-10-24 23:57:45 +05:30
import TreeContent, { INITIAL_FETCH_COUNT } from '~/repository/components/tree_content.vue';
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';
2019-12-26 22:10:19 +05:30
let vm;
let $apollo;
function factory(path, data = () => ({})) {
$apollo = {
query: jest.fn().mockReturnValue(Promise.resolve({ data: data() })),
};
vm = shallowMount(TreeContent, {
propsData: {
path,
},
mocks: {
$apollo,
},
});
}
describe('Repository table component', () => {
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('/');
vm.setData({ entries: { blobs: [{ name: 'README.md' }] } });
2020-10-24 23:57:45 +05:30
await vm.vm.$nextTick();
expect(vm.find(FilePreview).exists()).toBe(true);
});
it('trigger fetchFiles when mounted', async () => {
factory('/');
jest.spyOn(vm.vm, 'fetchFiles').mockImplementation(() => {});
await vm.vm.$nextTick();
expect(vm.vm.fetchFiles).toHaveBeenCalled();
2019-12-26 22:10:19 +05:30
});
describe('normalizeData', () => {
it('normalizes edge nodes', () => {
factory('/');
const output = vm.vm.normalizeData('blobs', [{ node: '1' }, { node: '2' }]);
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', () => {
2020-11-24 15:15:51 +05:30
const fileTable = () => vm.find(FileTable);
2020-10-24 23:57:45 +05:30
beforeEach(async () => {
factory('/');
});
2020-11-24 15:15:51 +05:30
it('is changes hasShowMore to false when "showMore" event is emitted', async () => {
fileTable().vm.$emit('showMore');
2020-10-24 23:57:45 +05:30
await vm.vm.$nextTick();
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 () => {
fileTable().vm.$emit('showMore');
2020-10-24 23:57:45 +05:30
2020-11-24 15:15:51 +05:30
await vm.vm.$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');
2020-11-24 15:15:51 +05:30
fileTable().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('/');
vm.setData({ fetchCounter: 5, clickedShowMore: false });
await vm.vm.$nextTick();
2020-11-24 15:15:51 +05:30
expect(vm.vm.hasShowMore).toBe(false);
2020-10-24 23:57:45 +05:30
});
it('has limit of 1000 files on initial load', () => {
factory('/');
expect(INITIAL_FETCH_COUNT * vm.vm.pageSize).toBe(1000);
});
});
2019-12-26 22:10:19 +05:30
});