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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
import { mount } from '@vue/test-utils';
import { GlIcon } from '@gitlab/ui';
import Vue, { nextTick } from 'vue';
import { trimText } from 'helpers/text_helper';
import waitForPromises from 'helpers/wait_for_promises';
import ListItem from '~/ide/components/commit_sidebar/list_item.vue';
import { createRouter } from '~/ide/ide_router';
import { createStore } from '~/ide/stores';
import { file } from '../../helpers';
describe('Multi-file editor commit sidebar list item', () => {
let wrapper;
let testFile;
let findPathEl;
let store;
let router;
beforeEach(() => {
store = createStore();
jest.spyOn(store, 'dispatch');
router = createRouter(store);
testFile = file('test-file');
store.state.entries[testFile.path] = testFile;
wrapper = mount(ListItem, {
store,
propsData: {
file: testFile,
activeFileKey: `staged-${testFile.key}`,
},
});
findPathEl = wrapper.find('.multi-file-commit-list-path');
});
const findPathText = () => trimText(findPathEl.text());
it('renders file path', () => {
expect(findPathText()).toContain(testFile.path);
});
it('correctly renders renamed entries', async () => {
Vue.set(testFile, 'prevName', 'Old name');
await nextTick();
expect(findPathText()).toEqual(`Old name → ${testFile.name}`);
});
it('correctly renders entry, the name of which did not change after rename (as within a folder)', async () => {
Vue.set(testFile, 'prevName', testFile.name);
await nextTick();
expect(findPathText()).toEqual(testFile.name);
});
it('opens a closed file in the editor when clicking the file path', async () => {
jest.spyOn(router, 'push').mockImplementation(() => {});
await findPathEl.trigger('click');
expect(store.dispatch).toHaveBeenCalledWith('openPendingTab', expect.anything());
expect(router.push).toHaveBeenCalled();
});
it('calls updateViewer with diff when clicking file', async () => {
jest.spyOn(router, 'push').mockImplementation(() => {});
await findPathEl.trigger('click');
await waitForPromises();
expect(store.dispatch).toHaveBeenCalledWith('updateViewer', 'diff');
});
describe('icon name', () => {
const getIconName = () => wrapper.findComponent(GlIcon).props('name');
it('is modified when not a tempFile', () => {
expect(getIconName()).toBe('file-modified');
});
it('is addition when is a tempFile', async () => {
testFile.tempFile = true;
await nextTick();
expect(getIconName()).toBe('file-addition');
});
it('is deletion when is deleted', async () => {
testFile.deleted = true;
await nextTick();
expect(getIconName()).toBe('file-deletion');
});
});
describe('icon class', () => {
const getIconClass = () => wrapper.findComponent(GlIcon).classes();
it('is modified when not a tempFile', () => {
expect(getIconClass()).toContain('ide-file-modified');
});
it('is addition when is a tempFile', async () => {
testFile.tempFile = true;
await nextTick();
expect(getIconClass()).toContain('ide-file-addition');
});
it('returns deletion when is deleted', async () => {
testFile.deleted = true;
await nextTick();
expect(getIconClass()).toContain('ide-file-deletion');
});
});
describe('is active', () => {
it('does not add active class when dont keys match', () => {
expect(wrapper.find('.is-active').exists()).toBe(false);
});
it('adds active class when keys match', async () => {
await wrapper.setProps({ keyPrefix: 'staged' });
expect(wrapper.find('.is-active').exists()).toBe(true);
});
});
});
|