debian-mirror-gitlab/spec/frontend/code_navigation/components/app_spec.js

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

87 lines
2.2 KiB
JavaScript
Raw Normal View History

2022-04-04 11:22:00 +05:30
import { shallowMount } from '@vue/test-utils';
import Vue from 'vue';
2021-03-11 19:13:27 +05:30
import Vuex from 'vuex';
2022-07-16 23:28:13 +05:30
import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
2020-03-13 15:44:24 +05:30
import App from '~/code_navigation/components/app.vue';
import Popover from '~/code_navigation/components/popover.vue';
2021-03-11 19:13:27 +05:30
import createState from '~/code_navigation/store/state';
2020-03-13 15:44:24 +05:30
2022-05-07 20:08:51 +05:30
const setInitialData = jest.fn();
2020-03-13 15:44:24 +05:30
const fetchData = jest.fn();
const showDefinition = jest.fn();
let wrapper;
2022-04-04 11:22:00 +05:30
Vue.use(Vuex);
2020-03-13 15:44:24 +05:30
2022-05-07 20:08:51 +05:30
function factory(initialState = {}, props = {}) {
2020-03-13 15:44:24 +05:30
const store = new Vuex.Store({
state: {
...createState(),
...initialState,
2021-06-08 01:23:25 +05:30
definitionPathPrefix: 'https://test.com/blob/main',
2020-03-13 15:44:24 +05:30
},
actions: {
2022-05-07 20:08:51 +05:30
setInitialData,
2020-03-13 15:44:24 +05:30
fetchData,
showDefinition,
},
});
2022-05-07 20:08:51 +05:30
wrapper = shallowMount(App, { store, propsData: { ...props } });
2020-03-13 15:44:24 +05:30
}
describe('Code navigation app component', () => {
2022-05-07 20:08:51 +05:30
it('sets initial data on mount if the correct props are passed', () => {
const codeNavigationPath = 'code/nav/path.js';
const path = 'blob/path.js';
const definitionPathPrefix = 'path/prefix';
2022-06-21 17:19:12 +05:30
const wrapTextNodes = true;
2022-05-07 20:08:51 +05:30
2022-06-21 17:19:12 +05:30
factory(
{},
{ codeNavigationPath, blobPath: path, pathPrefix: definitionPathPrefix, wrapTextNodes },
);
2022-05-07 20:08:51 +05:30
expect(setInitialData).toHaveBeenCalledWith(expect.anything(), {
blobs: [{ codeNavigationPath, path }],
definitionPathPrefix,
2022-06-21 17:19:12 +05:30
wrapTextNodes,
2022-05-07 20:08:51 +05:30
});
});
2020-03-13 15:44:24 +05:30
it('fetches data on mount', () => {
factory();
expect(fetchData).toHaveBeenCalled();
});
it('hides popover when no definition set', () => {
factory();
2022-10-11 01:57:18 +05:30
expect(wrapper.findComponent(Popover).exists()).toBe(false);
2020-03-13 15:44:24 +05:30
});
it('renders popover when definition set', () => {
factory({
currentDefinition: { hover: 'console' },
currentDefinitionPosition: { x: 0 },
2020-05-24 23:13:21 +05:30
currentBlobPath: 'index.js',
2020-03-13 15:44:24 +05:30
});
2022-10-11 01:57:18 +05:30
expect(wrapper.findComponent(Popover).exists()).toBe(true);
2020-03-13 15:44:24 +05:30
});
it('calls showDefinition when clicking blob viewer', () => {
2022-07-16 23:28:13 +05:30
setHTMLFixture('<div class="blob-viewer"></div>');
2020-03-13 15:44:24 +05:30
factory();
document.querySelector('.blob-viewer').click();
expect(showDefinition).toHaveBeenCalled();
2022-07-16 23:28:13 +05:30
resetHTMLFixture();
2020-03-13 15:44:24 +05:30
});
});