1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
import { mount } from '@vue/test-utils';
import Vue from 'vue';
import Vuex from 'vuex';
import { viewerTypes } from '~/ide/constants';
import IdeTree from '~/ide/components/ide_tree.vue';
import { createStoreOptions } from '~/ide/stores';
import { file } from '../helpers';
import { projectData } from '../mock_data';
Vue.use(Vuex);
describe('IdeTree', () => {
let store;
let wrapper;
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,
},
});
wrapper = mount(IdeTree, {
store,
});
};
beforeEach(() => {
createComponent();
});
afterEach(() => {
actionSpies.updateViewer.mockClear();
});
describe('renders properly', () => {
it('renders list of files', () => {
expect(wrapper.text()).toContain('fileName');
});
});
describe('activated', () => {
beforeEach(() => {
createComponent({
viewer: viewerTypes.diff,
});
});
it('re initializes the component', () => {
expect(actionSpies.updateViewer).toHaveBeenCalled();
});
it('updates viewer to "editor" by default', () => {
expect(actionSpies.updateViewer).toHaveBeenCalledWith(expect.any(Object), viewerTypes.edit);
});
});
});
|