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

61 lines
1.5 KiB
JavaScript
Raw Normal View History

2018-10-15 14:42:47 +05:30
import Vue from 'vue';
2021-01-03 14:25:43 +05:30
import Vuex from 'vuex';
import { mount, createLocalVue } from '@vue/test-utils';
2018-10-15 14:42:47 +05:30
import IdeTree from '~/ide/components/ide_tree.vue';
2020-10-24 23:57:45 +05:30
import { createStore } from '~/ide/stores';
2021-01-03 14:25:43 +05:30
import { keepAlive } from '../../helpers/keep_alive_component_helper';
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';
2021-01-03 14:25:43 +05:30
const localVue = createLocalVue();
localVue.use(Vuex);
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
beforeEach(() => {
2020-10-24 23:57:45 +05:30
store = createStore();
2018-10-15 14:42:47 +05:30
store.state.currentProjectId = 'abcproject';
store.state.currentBranchId = 'master';
2020-05-24 23:13:21 +05:30
store.state.projects.abcproject = { ...projectData };
2018-10-15 14:42:47 +05:30
Vue.set(store.state.trees, 'abcproject/master', {
tree: [file('fileName')],
loading: false,
});
2021-01-03 14:25:43 +05:30
wrapper = mount(keepAlive(IdeTree), {
store,
localVue,
});
2018-10-15 14:42:47 +05:30
});
afterEach(() => {
2021-01-03 14:25:43 +05:30
wrapper.destroy();
2018-10-15 14:42:47 +05:30
});
it('renders list of files', () => {
2021-01-03 14:25:43 +05:30
expect(wrapper.text()).toContain('fileName');
});
describe('activated', () => {
let inititializeSpy;
beforeEach(async () => {
inititializeSpy = jest.spyOn(wrapper.find(IdeTree).vm, 'initialize');
store.state.viewer = 'diff';
await wrapper.vm.reactivate();
});
it('re initializes the component', () => {
expect(inititializeSpy).toHaveBeenCalled();
});
it('updates viewer to "editor" by default', () => {
expect(store.state.viewer).toBe('editor');
});
2018-10-15 14:42:47 +05:30
});
});