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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

272 lines
6.4 KiB
JavaScript
Raw Normal View History

2021-11-18 22:05:49 +05:30
import { GlBadge, GlLink, GlIcon, GlIntersectionObserver } from '@gitlab/ui';
2021-03-11 19:13:27 +05:30
import { shallowMount, RouterLinkStub } from '@vue/test-utils';
2022-04-04 11:22:00 +05:30
import { nextTick } from 'vue';
2021-09-04 01:27:46 +05:30
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
2019-09-04 21:01:54 +05:30
import TableRow from '~/repository/components/table/row.vue';
2020-04-22 19:07:51 +05:30
import FileIcon from '~/vue_shared/components/file_icon.vue';
2020-07-28 23:09:34 +05:30
import { FILE_SYMLINK_MODE } from '~/vue_shared/constants';
2022-01-26 12:08:38 +05:30
import { ROW_APPEAR_DELAY } from '~/repository/constants';
2019-09-04 21:01:54 +05:30
2021-11-18 22:05:49 +05:30
const COMMIT_MOCK = { lockLabel: 'Locked by Root', committedDate: '2019-01-01' };
2019-09-04 21:01:54 +05:30
let vm;
let $router;
function factory(propsData = {}) {
$router = {
push: jest.fn(),
};
vm = shallowMount(TableRow, {
propsData: {
2022-01-26 12:08:38 +05:30
commitInfo: COMMIT_MOCK,
2019-09-04 21:01:54 +05:30
...propsData,
2019-09-30 21:07:59 +05:30
name: propsData.path,
projectPath: 'gitlab-org/gitlab-ce',
2019-09-04 21:01:54 +05:30
url: `https://test.com`,
2021-09-04 01:27:46 +05:30
totalEntries: 10,
2021-11-18 22:05:49 +05:30
rowNumber: 123,
2021-09-04 01:27:46 +05:30
},
directives: {
GlHoverLoad: createMockDirective(),
2019-09-04 21:01:54 +05:30
},
2021-04-29 21:17:54 +05:30
provide: {
2022-08-13 15:12:31 +05:30
glFeatures: { lazyLoadCommits: true },
2021-04-29 21:17:54 +05:30
},
2019-09-04 21:01:54 +05:30
mocks: {
$router,
},
stubs: {
RouterLink: RouterLinkStub,
},
});
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-06-08 01:23:25 +05:30
vm.setData({ escapedRef: 'main' });
2019-09-04 21:01:54 +05:30
}
describe('Repository table row component', () => {
2022-11-25 23:54:43 +05:30
const findRouterLink = () => vm.findComponent(RouterLinkStub);
2021-11-18 22:05:49 +05:30
const findIntersectionObserver = () => vm.findComponent(GlIntersectionObserver);
2021-09-04 01:27:46 +05:30
2019-09-04 21:01:54 +05:30
afterEach(() => {
vm.destroy();
});
2022-04-04 11:22:00 +05:30
it('renders table row', async () => {
2019-09-04 21:01:54 +05:30
factory({
id: '1',
2019-12-26 22:10:19 +05:30
sha: '123',
2019-09-04 21:01:54 +05:30
path: 'test',
type: 'file',
currentPath: '/',
});
2022-04-04 11:22:00 +05:30
await nextTick();
expect(vm.element).toMatchSnapshot();
2020-03-13 15:44:24 +05:30
});
2022-04-04 11:22:00 +05:30
it('renders a symlink table row', async () => {
2020-07-28 23:09:34 +05:30
factory({
id: '1',
sha: '123',
path: 'test',
type: 'blob',
currentPath: '/',
mode: FILE_SYMLINK_MODE,
});
2022-04-04 11:22:00 +05:30
await nextTick();
expect(vm.element).toMatchSnapshot();
2020-07-28 23:09:34 +05:30
});
2022-04-04 11:22:00 +05:30
it('renders table row for path with special character', async () => {
2020-03-13 15:44:24 +05:30
factory({
id: '1',
sha: '123',
path: 'test$/test',
type: 'file',
currentPath: 'test$',
});
2022-04-04 11:22:00 +05:30
await nextTick();
expect(vm.element).toMatchSnapshot();
2019-09-04 21:01:54 +05:30
});
2021-09-04 01:27:46 +05:30
it('renders a gl-hover-load directive', () => {
factory({
id: '1',
sha: '123',
path: 'test',
type: 'blob',
currentPath: '/',
});
const hoverLoadDirective = getBinding(findRouterLink().element, 'gl-hover-load');
expect(hoverLoadDirective).not.toBeUndefined();
expect(hoverLoadDirective.value).toBeInstanceOf(Function);
});
2019-09-04 21:01:54 +05:30
it.each`
type | component | componentName
${'tree'} | ${RouterLinkStub} | ${'RouterLink'}
2021-04-29 21:17:54 +05:30
${'blob'} | ${RouterLinkStub} | ${'RouterLink'}
2019-09-04 21:01:54 +05:30
${'commit'} | ${'a'} | ${'hyperlink'}
2022-04-04 11:22:00 +05:30
`('renders a $componentName for type $type', async ({ type, component }) => {
2019-09-04 21:01:54 +05:30
factory({
id: '1',
2019-12-26 22:10:19 +05:30
sha: '123',
2019-09-04 21:01:54 +05:30
path: 'test',
type,
currentPath: '/',
});
2022-04-04 11:22:00 +05:30
await nextTick();
2022-11-25 23:54:43 +05:30
expect(vm.findComponent(component).exists()).toBe(true);
2019-09-04 21:01:54 +05:30
});
2020-03-13 15:44:24 +05:30
it.each`
path
${'test#'}
${'Änderungen'}
2022-04-04 11:22:00 +05:30
`('renders link for $path', async ({ path }) => {
2020-03-13 15:44:24 +05:30
factory({
id: '1',
sha: '123',
path,
type: 'tree',
currentPath: '/',
});
2022-04-04 11:22:00 +05:30
await nextTick();
2022-11-25 23:54:43 +05:30
expect(vm.findComponent({ ref: 'link' }).props('to')).toEqual({
2022-04-04 11:22:00 +05:30
path: `/-/tree/main/${encodeURIComponent(path)}`,
2020-03-13 15:44:24 +05:30
});
});
2022-04-04 11:22:00 +05:30
it('renders link for directory with hash', async () => {
2020-03-13 15:44:24 +05:30
factory({
id: '1',
sha: '123',
path: 'test#',
type: 'tree',
currentPath: '/',
});
2022-04-04 11:22:00 +05:30
await nextTick();
expect(vm.find('.tree-item-link').props('to')).toEqual({ path: '/-/tree/main/test%23' });
2019-09-04 21:01:54 +05:30
});
2022-04-04 11:22:00 +05:30
it('renders commit ID for submodule', async () => {
2019-09-04 21:01:54 +05:30
factory({
id: '1',
2019-12-26 22:10:19 +05:30
sha: '123',
2019-09-04 21:01:54 +05:30
path: 'test',
type: 'commit',
currentPath: '/',
});
2022-04-04 11:22:00 +05:30
await nextTick();
expect(vm.find('.commit-sha').text()).toContain('1');
2019-09-04 21:01:54 +05:30
});
2022-04-04 11:22:00 +05:30
it('renders link with href', async () => {
2019-09-04 21:01:54 +05:30
factory({
id: '1',
2019-12-26 22:10:19 +05:30
sha: '123',
2019-09-04 21:01:54 +05:30
path: 'test',
type: 'blob',
url: 'https://test.com',
currentPath: '/',
});
2022-04-04 11:22:00 +05:30
await nextTick();
expect(vm.find('a').attributes('href')).toEqual('https://test.com');
2019-09-04 21:01:54 +05:30
});
2022-04-04 11:22:00 +05:30
it('renders LFS badge', async () => {
2019-09-04 21:01:54 +05:30
factory({
id: '1',
2019-12-26 22:10:19 +05:30
sha: '123',
2019-09-04 21:01:54 +05:30
path: 'test',
type: 'commit',
currentPath: '/',
lfsOid: '1',
});
2022-04-04 11:22:00 +05:30
await nextTick();
2022-11-25 23:54:43 +05:30
expect(vm.findComponent(GlBadge).exists()).toBe(true);
2019-09-04 21:01:54 +05:30
});
2019-09-30 21:07:59 +05:30
2022-04-04 11:22:00 +05:30
it('renders commit and web links with href for submodule', async () => {
2019-09-30 21:07:59 +05:30
factory({
id: '1',
2019-12-26 22:10:19 +05:30
sha: '123',
2019-09-30 21:07:59 +05:30
path: 'test',
type: 'commit',
url: 'https://test.com',
submoduleTreeUrl: 'https://test.com/commit',
currentPath: '/',
});
2022-04-04 11:22:00 +05:30
await nextTick();
expect(vm.find('a').attributes('href')).toEqual('https://test.com');
2022-11-25 23:54:43 +05:30
expect(vm.findComponent(GlLink).attributes('href')).toEqual('https://test.com/commit');
2019-09-30 21:07:59 +05:30
});
2019-12-26 22:10:19 +05:30
2022-04-04 11:22:00 +05:30
it('renders lock icon', async () => {
2019-12-26 22:10:19 +05:30
factory({
id: '1',
sha: '123',
path: 'test',
type: 'tree',
currentPath: '/',
});
2022-04-04 11:22:00 +05:30
await nextTick();
2022-11-25 23:54:43 +05:30
expect(vm.findComponent(GlIcon).exists()).toBe(true);
expect(vm.findComponent(GlIcon).props('name')).toBe('lock');
2020-03-13 15:44:24 +05:30
});
it('renders loading icon when path is loading', () => {
factory({
id: '1',
sha: '1',
path: 'test',
type: 'tree',
currentPath: '/',
loadingPath: 'test',
});
2022-11-25 23:54:43 +05:30
expect(vm.findComponent(FileIcon).props('loading')).toBe(true);
2019-12-26 22:10:19 +05:30
});
2021-11-18 22:05:49 +05:30
describe('row visibility', () => {
beforeEach(() => {
factory({
id: '1',
sha: '1',
path: 'test',
type: 'tree',
currentPath: '/',
2022-01-26 12:08:38 +05:30
commitInfo: null,
2021-11-18 22:05:49 +05:30
});
});
2022-01-26 12:08:38 +05:30
afterAll(() => jest.useRealTimers());
it('emits a `row-appear` event', async () => {
2022-08-13 15:12:31 +05:30
const setTimeoutSpy = jest.spyOn(global, 'setTimeout');
2021-11-18 22:05:49 +05:30
findIntersectionObserver().vm.$emit('appear');
2022-01-26 12:08:38 +05:30
jest.runAllTimers();
2022-08-13 15:12:31 +05:30
expect(setTimeoutSpy).toHaveBeenCalledTimes(1);
expect(setTimeoutSpy).toHaveBeenLastCalledWith(expect.any(Function), ROW_APPEAR_DELAY);
2022-01-26 12:08:38 +05:30
expect(vm.emitted('row-appear')).toEqual([[123]]);
2021-11-18 22:05:49 +05:30
});
});
2019-09-04 21:01:54 +05:30
});