2022-10-03 12:08:27 +00:00
|
|
|
import { mount } from '@vue/test-utils';
|
|
|
|
import { GlIcon } from '@gitlab/ui';
|
2022-01-25 15:12:32 +00:00
|
|
|
import Vue, { nextTick } from 'vue';
|
2020-04-03 15:09:56 +00:00
|
|
|
import { trimText } from 'helpers/text_helper';
|
2022-02-10 12:18:48 +00:00
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
2022-10-03 12:08:27 +00:00
|
|
|
import ListItem from '~/ide/components/commit_sidebar/list_item.vue';
|
2020-06-05 00:08:38 +00:00
|
|
|
import { createRouter } from '~/ide/ide_router';
|
2021-02-14 18:09:20 +00:00
|
|
|
import { createStore } from '~/ide/stores';
|
2020-06-05 00:08:38 +00:00
|
|
|
import { file } from '../../helpers';
|
2018-03-20 14:12:48 +00:00
|
|
|
|
|
|
|
describe('Multi-file editor commit sidebar list item', () => {
|
2022-10-03 12:08:27 +00:00
|
|
|
let wrapper;
|
2018-03-20 14:12:48 +00:00
|
|
|
let f;
|
2019-10-04 15:06:38 +00:00
|
|
|
let findPathEl;
|
2020-06-05 00:08:38 +00:00
|
|
|
let store;
|
|
|
|
let router;
|
2018-03-20 14:12:48 +00:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2020-06-05 00:08:38 +00:00
|
|
|
store = createStore();
|
2022-10-03 12:08:27 +00:00
|
|
|
jest.spyOn(store, 'dispatch');
|
2020-06-05 00:08:38 +00:00
|
|
|
|
2022-10-03 12:08:27 +00:00
|
|
|
router = createRouter(store);
|
2018-03-20 14:12:48 +00:00
|
|
|
|
|
|
|
f = file('test-file');
|
|
|
|
|
2018-03-27 15:39:24 +00:00
|
|
|
store.state.entries[f.path] = f;
|
|
|
|
|
2022-10-03 12:08:27 +00:00
|
|
|
wrapper = mount(ListItem, {
|
|
|
|
store,
|
|
|
|
propsData: {
|
|
|
|
file: f,
|
|
|
|
activeFileKey: `staged-${f.key}`,
|
|
|
|
},
|
|
|
|
});
|
2019-10-04 15:06:38 +00:00
|
|
|
|
2022-10-03 12:08:27 +00:00
|
|
|
findPathEl = wrapper.find('.multi-file-commit-list-path');
|
2018-03-20 14:12:48 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
2022-10-03 12:08:27 +00:00
|
|
|
wrapper.destroy();
|
2018-03-20 14:12:48 +00:00
|
|
|
});
|
|
|
|
|
2022-10-03 12:08:27 +00:00
|
|
|
const findPathText = () => trimText(findPathEl.text());
|
2019-10-04 15:06:38 +00:00
|
|
|
|
2018-03-20 14:12:48 +00:00
|
|
|
it('renders file path', () => {
|
2019-10-04 15:06:38 +00:00
|
|
|
expect(findPathText()).toContain(f.path);
|
|
|
|
});
|
|
|
|
|
2022-01-25 15:12:32 +00:00
|
|
|
it('correctly renders renamed entries', async () => {
|
2022-10-03 12:08:27 +00:00
|
|
|
Vue.set(f, 'prevName', 'Old name');
|
2022-01-25 15:12:32 +00:00
|
|
|
await nextTick();
|
2022-10-03 12:08:27 +00:00
|
|
|
|
2022-01-25 15:12:32 +00:00
|
|
|
expect(findPathText()).toEqual(`Old name → ${f.name}`);
|
2019-10-04 15:06:38 +00:00
|
|
|
});
|
|
|
|
|
2022-01-25 15:12:32 +00:00
|
|
|
it('correctly renders entry, the name of which did not change after rename (as within a folder)', async () => {
|
2022-10-03 12:08:27 +00:00
|
|
|
Vue.set(f, 'prevName', f.name);
|
2022-01-25 15:12:32 +00:00
|
|
|
await nextTick();
|
2022-10-03 12:08:27 +00:00
|
|
|
|
2022-01-25 15:12:32 +00:00
|
|
|
expect(findPathText()).toEqual(f.name);
|
2018-03-20 14:12:48 +00:00
|
|
|
});
|
|
|
|
|
2022-02-10 12:18:48 +00:00
|
|
|
it('opens a closed file in the editor when clicking the file path', async () => {
|
2020-04-03 15:09:56 +00:00
|
|
|
jest.spyOn(router, 'push').mockImplementation(() => {});
|
2018-03-20 14:12:48 +00:00
|
|
|
|
2022-10-03 12:08:27 +00:00
|
|
|
await findPathEl.trigger('click');
|
2018-03-23 15:59:09 +00:00
|
|
|
|
2022-10-03 12:08:27 +00:00
|
|
|
expect(store.dispatch).toHaveBeenCalledWith('openPendingTab', expect.anything());
|
2022-02-10 12:18:48 +00:00
|
|
|
expect(router.push).toHaveBeenCalled();
|
2018-03-20 14:12:48 +00:00
|
|
|
});
|
|
|
|
|
2022-02-10 12:18:48 +00:00
|
|
|
it('calls updateViewer with diff when clicking file', async () => {
|
2020-04-03 15:09:56 +00:00
|
|
|
jest.spyOn(router, 'push').mockImplementation(() => {});
|
2018-03-20 14:12:48 +00:00
|
|
|
|
2022-10-03 12:08:27 +00:00
|
|
|
await findPathEl.trigger('click');
|
2022-02-10 12:18:48 +00:00
|
|
|
await waitForPromises();
|
2018-03-27 15:39:24 +00:00
|
|
|
|
2022-10-03 12:08:27 +00:00
|
|
|
expect(store.dispatch).toHaveBeenCalledWith('updateViewer', 'diff');
|
2018-03-20 14:12:48 +00:00
|
|
|
});
|
|
|
|
|
2022-10-03 12:08:27 +00:00
|
|
|
describe('icon name', () => {
|
|
|
|
const getIconName = () => wrapper.findComponent(GlIcon).props('name');
|
|
|
|
|
|
|
|
it('is modified when not a tempFile', () => {
|
|
|
|
expect(getIconName()).toBe('file-modified');
|
|
|
|
});
|
2018-03-20 14:12:48 +00:00
|
|
|
|
2022-10-03 12:08:27 +00:00
|
|
|
it('is addition when is a tempFile', async () => {
|
|
|
|
f.tempFile = true;
|
|
|
|
await nextTick();
|
2018-03-20 14:12:48 +00:00
|
|
|
|
2022-10-03 12:08:27 +00:00
|
|
|
expect(getIconName()).toBe('file-addition');
|
|
|
|
});
|
2018-07-26 14:56:56 +00:00
|
|
|
|
2022-10-03 12:08:27 +00:00
|
|
|
it('is deletion when is deleted', async () => {
|
|
|
|
f.deleted = true;
|
|
|
|
await nextTick();
|
2018-07-26 14:56:56 +00:00
|
|
|
|
2022-10-03 12:08:27 +00:00
|
|
|
expect(getIconName()).toBe('file-deletion');
|
2018-03-20 14:12:48 +00:00
|
|
|
});
|
2022-10-03 12:08:27 +00:00
|
|
|
});
|
2018-03-20 14:12:48 +00:00
|
|
|
|
2022-10-03 12:08:27 +00:00
|
|
|
describe('icon class', () => {
|
|
|
|
const getIconClass = () => wrapper.findComponent(GlIcon).classes();
|
2018-03-20 14:12:48 +00:00
|
|
|
|
2022-10-03 12:08:27 +00:00
|
|
|
it('is modified when not a tempFile', () => {
|
|
|
|
expect(getIconClass()).toContain('ide-file-modified');
|
|
|
|
});
|
2018-03-20 14:12:48 +00:00
|
|
|
|
2022-10-03 12:08:27 +00:00
|
|
|
it('is addition when is a tempFile', async () => {
|
|
|
|
f.tempFile = true;
|
|
|
|
await nextTick();
|
2018-07-26 14:56:56 +00:00
|
|
|
|
2022-10-03 12:08:27 +00:00
|
|
|
expect(getIconClass()).toContain('ide-file-addition');
|
|
|
|
});
|
2018-07-26 14:56:56 +00:00
|
|
|
|
2022-10-03 12:08:27 +00:00
|
|
|
it('returns deletion when is deleted', async () => {
|
|
|
|
f.deleted = true;
|
|
|
|
await nextTick();
|
|
|
|
|
|
|
|
expect(getIconClass()).toContain('ide-file-deletion');
|
2018-03-20 14:12:48 +00:00
|
|
|
});
|
|
|
|
});
|
2018-06-12 10:46:00 +00:00
|
|
|
|
|
|
|
describe('is active', () => {
|
|
|
|
it('does not add active class when dont keys match', () => {
|
2022-10-03 12:08:27 +00:00
|
|
|
expect(wrapper.find('.is-active').exists()).toBe(false);
|
2018-06-12 10:46:00 +00:00
|
|
|
});
|
|
|
|
|
2022-01-25 15:12:32 +00:00
|
|
|
it('adds active class when keys match', async () => {
|
2022-10-03 12:08:27 +00:00
|
|
|
await wrapper.setProps({ keyPrefix: 'staged' });
|
2018-06-12 10:46:00 +00:00
|
|
|
|
2022-10-03 12:08:27 +00:00
|
|
|
expect(wrapper.find('.is-active').exists()).toBe(true);
|
2018-06-12 10:46:00 +00:00
|
|
|
});
|
|
|
|
});
|
2018-03-20 14:12:48 +00:00
|
|
|
});
|