debian-mirror-gitlab/spec/frontend/ide/components/ide_tree_spec.js

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

85 lines
1.8 KiB
JavaScript
Raw Normal View History

2022-04-04 11:22:00 +05:30
import { mount } from '@vue/test-utils';
2018-10-15 14:42:47 +05:30
import Vue from 'vue';
2021-01-03 14:25:43 +05:30
import Vuex from 'vuex';
2023-06-20 00:43:36 +05:30
import { viewerTypes } from '~/ide/constants';
2018-10-15 14:42:47 +05:30
import IdeTree from '~/ide/components/ide_tree.vue';
2023-06-20 00:43:36 +05:30
import { createStoreOptions } from '~/ide/stores';
2020-10-24 23:57:45 +05:30
import { file } from '../helpers';
2018-10-15 14:42:47 +05:30
import { projectData } from '../mock_data';
2022-04-04 11:22:00 +05:30
Vue.use(Vuex);
2021-01-03 14:25:43 +05:30
describe('IdeTree', () => {
2020-10-24 23:57:45 +05:30
let store;
2021-01-03 14:25:43 +05:30
let wrapper;
2018-10-15 14:42:47 +05:30
2023-06-20 00:43:36 +05:30
const actionSpies = {
updateViewer: jest.fn(),
};
const testState = {
currentProjectId: 'abcproject',
currentBranchId: 'main',
projects: {
abcproject: { ...projectData },
},
trees: {
'abcproject/main': {
tree: [file('fileName')],
loading: false,
},
},
};
const createComponent = (replaceState) => {
const defaultStore = createStoreOptions();
store = new Vuex.Store({
...defaultStore,
state: {
...defaultStore.state,
...testState,
replaceState,
},
actions: {
...defaultStore.actions,
...actionSpies,
},
2018-10-15 14:42:47 +05:30
});
2023-06-20 00:43:36 +05:30
wrapper = mount(IdeTree, {
2021-01-03 14:25:43 +05:30
store,
});
2023-06-20 00:43:36 +05:30
};
2018-10-15 14:42:47 +05:30
2023-06-20 00:43:36 +05:30
beforeEach(() => {
createComponent();
2021-01-03 14:25:43 +05:30
});
2023-06-20 00:43:36 +05:30
afterEach(() => {
actionSpies.updateViewer.mockClear();
});
2021-01-03 14:25:43 +05:30
2023-06-20 00:43:36 +05:30
describe('renders properly', () => {
it('renders list of files', () => {
expect(wrapper.text()).toContain('fileName');
});
});
2021-01-03 14:25:43 +05:30
2023-06-20 00:43:36 +05:30
describe('activated', () => {
beforeEach(() => {
createComponent({
viewer: viewerTypes.diff,
});
2021-01-03 14:25:43 +05:30
});
it('re initializes the component', () => {
2023-06-20 00:43:36 +05:30
expect(actionSpies.updateViewer).toHaveBeenCalled();
2021-01-03 14:25:43 +05:30
});
it('updates viewer to "editor" by default', () => {
2023-06-20 00:43:36 +05:30
expect(actionSpies.updateViewer).toHaveBeenCalledWith(expect.any(Object), viewerTypes.edit);
2021-01-03 14:25:43 +05:30
});
2018-10-15 14:42:47 +05:30
});
});