2021-02-14 13:09:20 -05:00
|
|
|
import { mount, createLocalVue } from '@vue/test-utils';
|
2018-03-20 10:12:48 -04:00
|
|
|
import Vue from 'vue';
|
2020-09-25 11:09:36 -04:00
|
|
|
import Vuex from 'vuex';
|
2021-01-14 19:10:45 -05:00
|
|
|
import { keepAlive } from 'helpers/keep_alive_component_helper';
|
2018-04-17 11:27:46 -04:00
|
|
|
import IdeTree from '~/ide/components/ide_tree.vue';
|
2020-07-21 05:09:34 -04:00
|
|
|
import { createStore } from '~/ide/stores';
|
|
|
|
import { file } from '../helpers';
|
2018-04-17 12:02:48 -04:00
|
|
|
import { projectData } from '../mock_data';
|
2018-03-20 10:12:48 -04:00
|
|
|
|
2020-09-25 11:09:36 -04:00
|
|
|
const localVue = createLocalVue();
|
|
|
|
localVue.use(Vuex);
|
|
|
|
|
|
|
|
describe('IdeTree', () => {
|
2020-07-21 05:09:34 -04:00
|
|
|
let store;
|
2020-09-25 11:09:36 -04:00
|
|
|
let wrapper;
|
2018-03-20 10:12:48 -04:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2020-07-21 05:09:34 -04:00
|
|
|
store = createStore();
|
|
|
|
|
2018-04-17 12:02:48 -04:00
|
|
|
store.state.currentProjectId = 'abcproject';
|
2021-06-14 20:10:11 -04:00
|
|
|
store.state.currentBranchId = 'main';
|
2020-05-07 17:09:26 -04:00
|
|
|
store.state.projects.abcproject = { ...projectData };
|
2021-06-14 20:10:11 -04:00
|
|
|
Vue.set(store.state.trees, 'abcproject/main', {
|
2018-04-17 12:02:48 -04:00
|
|
|
tree: [file('fileName')],
|
2018-03-20 10:12:48 -04:00
|
|
|
loading: false,
|
|
|
|
});
|
2018-04-17 12:02:48 -04:00
|
|
|
|
2020-09-25 11:09:36 -04:00
|
|
|
wrapper = mount(keepAlive(IdeTree), {
|
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
2018-03-20 10:12:48 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
2020-09-25 11:09:36 -04:00
|
|
|
wrapper.destroy();
|
2018-03-20 10:12:48 -04:00
|
|
|
});
|
|
|
|
|
2018-04-17 12:02:48 -04:00
|
|
|
it('renders list of files', () => {
|
2020-09-25 11:09:36 -04:00
|
|
|
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-04-17 12:02:48 -04:00
|
|
|
});
|
2018-03-20 10:12:48 -04:00
|
|
|
});
|