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.

298 lines
7.1 KiB
JavaScript
Raw Normal View History

2023-06-20 00:43:36 +05:30
import Vue from 'vue';
import VueApollo from 'vue-apollo';
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';
2023-06-20 00:43:36 +05:30
import refQuery from '~/repository/queries/ref.query.graphql';
2021-09-04 01:27:46 +05:30
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
2023-06-20 00:43:36 +05:30
import createMockApollo from 'helpers/mock_apollo_helper';
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' };
2023-06-20 00:43:36 +05:30
let wrapper;
2019-09-04 21:01:54 +05:30
let $router;
2023-06-20 00:43:36 +05:30
const createMockApolloProvider = (mockData) => {
Vue.use(VueApollo);
const apolloProver = createMockApollo([]);
apolloProver.clients.defaultClient.cache.writeQuery({ query: refQuery, data: { ...mockData } });
return apolloProver;
};
function factory({ mockData = { ref: 'main', escapedRef: 'main' }, propsData = {} } = {}) {
2019-09-04 21:01:54 +05:30
$router = {
push: jest.fn(),
};
2023-06-20 00:43:36 +05:30
wrapper = shallowMount(TableRow, {
apolloProvider: createMockApolloProvider(mockData),
2019-09-04 21:01:54 +05:30
propsData: {
2023-06-20 00:43:36 +05:30
id: '1',
sha: '0as4k',
2022-01-26 12:08:38 +05:30
commitInfo: COMMIT_MOCK,
2023-06-20 00:43:36 +05:30
name: 'name',
currentPath: 'gitlab-org/gitlab-ce',
2019-09-30 21:07:59 +05:30
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,
2023-06-20 00:43:36 +05:30
path: 'gitlab-org/gitlab-ce',
type: 'tree',
...propsData,
2021-09-04 01:27:46 +05:30
},
directives: {
2023-05-27 22:25:52 +05:30
GlHoverLoad: createMockDirective('gl-hover-load'),
2019-09-04 21:01:54 +05:30
},
mocks: {
$router,
},
stubs: {
RouterLink: RouterLinkStub,
},
});
}
describe('Repository table row component', () => {
2023-06-20 00:43:36 +05:30
const findIcon = () => wrapper.findComponent(GlIcon);
const findFileIcon = () => wrapper.findComponent(FileIcon);
const findBadge = () => wrapper.findComponent(GlBadge);
const findRouterLink = () => wrapper.findComponent(RouterLinkStub);
const findIntersectionObserver = () => wrapper.findComponent(GlIntersectionObserver);
2021-09-04 01:27:46 +05:30
2023-06-20 00:43:36 +05:30
it('renders table row', () => {
2019-09-04 21:01:54 +05:30
factory({
2023-06-20 00:43:36 +05:30
propsData: {
id: '1',
sha: '123',
path: 'test',
type: 'file',
currentPath: '/',
},
2019-09-04 21:01:54 +05:30
});
2023-06-20 00:43:36 +05:30
expect(wrapper.element).toMatchSnapshot();
2020-03-13 15:44:24 +05:30
});
2023-06-20 00:43:36 +05:30
it('renders a symlink table row', () => {
2020-07-28 23:09:34 +05:30
factory({
2023-06-20 00:43:36 +05:30
propsData: {
id: '1',
sha: '123',
path: 'test',
type: 'blob',
currentPath: '/',
mode: FILE_SYMLINK_MODE,
},
2020-07-28 23:09:34 +05:30
});
2023-06-20 00:43:36 +05:30
expect(wrapper.element).toMatchSnapshot();
2020-07-28 23:09:34 +05:30
});
2023-06-20 00:43:36 +05:30
it('renders table row for path with special character', () => {
2020-03-13 15:44:24 +05:30
factory({
2023-06-20 00:43:36 +05:30
propsData: {
id: '1',
sha: '123',
path: 'test$/test',
type: 'file',
currentPath: 'test$',
},
2020-03-13 15:44:24 +05:30
});
2023-06-20 00:43:36 +05:30
expect(wrapper.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({
2023-06-20 00:43:36 +05:30
propsData: {
id: '1',
sha: '123',
path: 'test',
type: 'blob',
currentPath: '/',
},
2021-09-04 01:27:46 +05:30
});
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'}
2023-06-20 00:43:36 +05:30
`('renders a $componentName for type $type', ({ type, component }) => {
2019-09-04 21:01:54 +05:30
factory({
2023-06-20 00:43:36 +05:30
propsData: {
id: '1',
sha: '123',
path: 'test',
type,
currentPath: '/',
},
2019-09-04 21:01:54 +05:30
});
2023-06-20 00:43:36 +05:30
expect(wrapper.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'}
2023-06-20 00:43:36 +05:30
`('renders link for $path', ({ path }) => {
2020-03-13 15:44:24 +05:30
factory({
2023-06-20 00:43:36 +05:30
propsData: {
id: '1',
sha: '123',
path,
type: 'tree',
currentPath: '/',
},
2020-03-13 15:44:24 +05:30
});
2023-06-20 00:43:36 +05:30
expect(wrapper.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
});
});
2023-06-20 00:43:36 +05:30
it('renders link for directory with hash', () => {
2020-03-13 15:44:24 +05:30
factory({
2023-06-20 00:43:36 +05:30
propsData: {
id: '1',
sha: '123',
path: 'test#',
type: 'tree',
currentPath: '/',
},
2020-03-13 15:44:24 +05:30
});
2023-06-20 00:43:36 +05:30
expect(wrapper.find('.tree-item-link').props('to')).toEqual({ path: '/-/tree/main/test%23' });
2019-09-04 21:01:54 +05:30
});
2023-06-20 00:43:36 +05:30
it('renders commit ID for submodule', () => {
2019-09-04 21:01:54 +05:30
factory({
2023-06-20 00:43:36 +05:30
propsData: {
id: '1',
sha: '123',
path: 'test',
type: 'commit',
currentPath: '/',
},
2019-09-04 21:01:54 +05:30
});
2023-06-20 00:43:36 +05:30
expect(wrapper.find('.commit-sha').text()).toContain('1');
2019-09-04 21:01:54 +05:30
});
2023-06-20 00:43:36 +05:30
it('renders link with href', () => {
2019-09-04 21:01:54 +05:30
factory({
2023-06-20 00:43:36 +05:30
propsData: {
id: '1',
sha: '123',
path: 'test',
type: 'blob',
url: 'https://test.com',
currentPath: '/',
},
2019-09-04 21:01:54 +05:30
});
2023-06-20 00:43:36 +05:30
expect(wrapper.find('a').attributes('href')).toEqual('https://test.com');
2019-09-04 21:01:54 +05:30
});
2023-06-20 00:43:36 +05:30
it('renders LFS badge', () => {
2019-09-04 21:01:54 +05:30
factory({
2023-06-20 00:43:36 +05:30
propsData: {
id: '1',
sha: '123',
path: 'test',
type: 'commit',
currentPath: '/',
lfsOid: '1',
},
2019-09-04 21:01:54 +05:30
});
2023-06-20 00:43:36 +05:30
expect(findBadge().exists()).toBe(true);
2019-09-04 21:01:54 +05:30
});
2019-09-30 21:07:59 +05:30
2023-06-20 00:43:36 +05:30
it('renders commit and web links with href for submodule', () => {
2019-09-30 21:07:59 +05:30
factory({
2023-06-20 00:43:36 +05:30
propsData: {
id: '1',
sha: '123',
path: 'test',
type: 'commit',
url: 'https://test.com',
submoduleTreeUrl: 'https://test.com/commit',
currentPath: '/',
},
2019-09-30 21:07:59 +05:30
});
2023-06-20 00:43:36 +05:30
expect(wrapper.find('a').attributes('href')).toEqual('https://test.com');
expect(wrapper.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
2023-06-20 00:43:36 +05:30
it('renders lock icon', () => {
2019-12-26 22:10:19 +05:30
factory({
2023-06-20 00:43:36 +05:30
propsData: {
id: '1',
sha: '123',
path: 'test',
type: 'tree',
currentPath: '/',
},
2019-12-26 22:10:19 +05:30
});
2023-06-20 00:43:36 +05:30
expect(findIcon().exists()).toBe(true);
expect(findIcon().props('name')).toBe('lock');
2020-03-13 15:44:24 +05:30
});
it('renders loading icon when path is loading', () => {
factory({
2023-06-20 00:43:36 +05:30
propsData: {
id: '1',
sha: '1',
path: 'test',
type: 'tree',
currentPath: '/',
loadingPath: 'test',
},
2020-03-13 15:44:24 +05:30
});
2023-06-20 00:43:36 +05:30
expect(findFileIcon().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({
2023-06-20 00:43:36 +05:30
propsData: {
id: '1',
sha: '1',
path: 'test',
type: 'tree',
currentPath: '/',
commitInfo: null,
},
2021-11-18 22:05:49 +05:30
});
});
2022-01-26 12:08:38 +05:30
afterAll(() => jest.useRealTimers());
2023-06-20 00:43:36 +05:30
it('emits a `row-appear` event', () => {
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);
2023-06-20 00:43:36 +05:30
expect(wrapper.emitted('row-appear')).toEqual([[123]]);
2021-11-18 22:05:49 +05:30
});
});
2019-09-04 21:01:54 +05:30
});