2020-03-13 15:44:24 +05:30
|
|
|
import { shallowMount, createLocalVue } from '@vue/test-utils';
|
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
|
|
|
|
|
|
|
const localVue = createLocalVue();
|
|
|
|
const fetchData = jest.fn();
|
|
|
|
const showDefinition = jest.fn();
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
localVue.use(Vuex);
|
|
|
|
|
|
|
|
function factory(initialState = {}) {
|
|
|
|
const store = new Vuex.Store({
|
|
|
|
state: {
|
|
|
|
...createState(),
|
|
|
|
...initialState,
|
2020-04-22 19:07:51 +05:30
|
|
|
definitionPathPrefix: 'https://test.com/blob/master',
|
2020-03-13 15:44:24 +05:30
|
|
|
},
|
|
|
|
actions: {
|
|
|
|
fetchData,
|
|
|
|
showDefinition,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
wrapper = shallowMount(App, { store, localVue });
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('Code navigation app component', () => {
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
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();
|
|
|
|
});
|
|
|
|
});
|