debian-mirror-gitlab/spec/frontend/repository/components/table/index_spec.js

116 lines
2.5 KiB
JavaScript
Raw Normal View History

2019-09-04 21:01:54 +05:30
import { shallowMount } from '@vue/test-utils';
2020-11-24 15:15:51 +05:30
import { GlDeprecatedSkeletonLoading as GlSkeletonLoading, GlButton } from '@gitlab/ui';
2019-09-04 21:01:54 +05:30
import Table from '~/repository/components/table/index.vue';
2019-12-26 22:10:19 +05:30
import TableRow from '~/repository/components/table/row.vue';
2019-09-04 21:01:54 +05:30
let vm;
let $apollo;
2019-12-26 22:10:19 +05:30
const MOCK_BLOBS = [
{
id: '123abc',
sha: '123abc',
flatPath: 'blob',
name: 'blob.md',
type: 'blob',
2020-10-24 23:57:45 +05:30
webPath: '/blob',
2019-12-26 22:10:19 +05:30
},
{
id: '124abc',
sha: '124abc',
flatPath: 'blob2',
name: 'blob2.md',
type: 'blob',
webUrl: 'http://test.com',
},
2020-07-28 23:09:34 +05:30
{
id: '125abc',
sha: '125abc',
flatPath: 'blob3',
name: 'blob3.md',
type: 'blob',
webUrl: 'http://test.com',
mode: '120000',
},
2019-12-26 22:10:19 +05:30
];
2020-11-24 15:15:51 +05:30
function factory({ path, isLoading = false, hasMore = true, entries = {} }) {
2019-09-04 21:01:54 +05:30
vm = shallowMount(Table, {
propsData: {
path,
2019-12-26 22:10:19 +05:30
isLoading,
entries,
2020-11-24 15:15:51 +05:30
hasMore,
2019-09-04 21:01:54 +05:30
},
mocks: {
$apollo,
},
});
}
describe('Repository table component', () => {
afterEach(() => {
vm.destroy();
});
it.each`
path | ref
${'/'} | ${'master'}
${'app/assets'} | ${'master'}
${'/'} | ${'test'}
`('renders table caption for $ref in $path', ({ path, ref }) => {
2019-12-26 22:10:19 +05:30
factory({ path });
2019-09-04 21:01:54 +05:30
vm.setData({ ref });
2020-03-13 15:44:24 +05:30
return vm.vm.$nextTick(() => {
expect(vm.find('.table').attributes('aria-label')).toEqual(
`Files, directories, and submodules in the path ${path} for commit reference ${ref}`,
);
});
2019-09-04 21:01:54 +05:30
});
it('shows loading icon', () => {
2019-12-26 22:10:19 +05:30
factory({ path: '/', isLoading: true });
2019-09-04 21:01:54 +05:30
2019-12-26 22:10:19 +05:30
expect(vm.find(GlSkeletonLoading).exists()).toBe(true);
2019-09-04 21:01:54 +05:30
});
2019-12-26 22:10:19 +05:30
it('renders table rows', () => {
factory({
path: '/',
entries: {
blobs: MOCK_BLOBS,
},
2019-09-04 21:01:54 +05:30
});
2020-07-28 23:09:34 +05:30
const rows = vm.findAll(TableRow);
expect(rows.length).toEqual(3);
expect(rows.at(2).attributes().mode).toEqual('120000');
2019-09-04 21:01:54 +05:30
});
2020-11-24 15:15:51 +05:30
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 vm.vm.$nextTick();
expect(vm.emitted('showMore')).toHaveLength(1);
});
});
2019-09-04 21:01:54 +05:30
});