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

82 lines
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';
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', () => {
afterEach(() => {
wrapper.destroy();
});
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';
factory({}, { codeNavigationPath, blobPath: path, pathPrefix: definitionPathPrefix });
expect(setInitialData).toHaveBeenCalledWith(expect.anything(), {
blobs: [{ codeNavigationPath, path }],
definitionPathPrefix,
});
});
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();
expect(wrapper.find(Popover).exists()).toBe(false);
});
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
});
expect(wrapper.find(Popover).exists()).toBe(true);
});
it('calls showDefinition when clicking blob viewer', () => {
setFixtures('<div class="blob-viewer"></div>');
factory();
document.querySelector('.blob-viewer').click();
expect(showDefinition).toHaveBeenCalled();
});
});