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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

145 lines
3.8 KiB
JavaScript
Raw Normal View History

2022-11-25 23:54:43 +05:30
import Vuex from 'vuex';
import { mount } from '@vue/test-utils';
2018-12-05 23:21:45 +05:30
import FileRowExtra from '~/ide/components/file_row_extra.vue';
2022-11-25 23:54:43 +05:30
import { createStoreOptions } from '~/ide/stores';
2020-10-24 23:57:45 +05:30
import { file } from '../helpers';
2018-12-05 23:21:45 +05:30
describe('IDE extra file row component', () => {
2022-11-25 23:54:43 +05:30
let wrapper;
let store;
2018-12-05 23:21:45 +05:30
let unstagedFilesCount = 0;
let stagedFilesCount = 0;
let changesCount = 0;
2022-11-25 23:54:43 +05:30
const createComponent = (fileProps) => {
const storeConfig = createStoreOptions();
2018-12-05 23:21:45 +05:30
2022-11-25 23:54:43 +05:30
store = new Vuex.Store({
...storeConfig,
getters: {
getUnstagedFilesCountForPath: () => () => unstagedFilesCount,
getStagedFilesCountForPath: () => () => stagedFilesCount,
getChangesInFolder: () => () => changesCount,
2018-12-05 23:21:45 +05:30
},
});
2022-11-25 23:54:43 +05:30
wrapper = mount(FileRowExtra, {
store,
propsData: {
file: {
...file('test'),
type: 'tree',
...fileProps,
},
dropdownOpen: false,
},
});
};
2018-12-05 23:21:45 +05:30
afterEach(() => {
stagedFilesCount = 0;
unstagedFilesCount = 0;
changesCount = 0;
});
2022-11-25 23:54:43 +05:30
describe('folder changes tooltip', () => {
2021-03-08 18:12:59 +05:30
[
{ input: 1, output: '1 changed file' },
{ input: 2, output: '2 changed files' },
].forEach(({ input, output }) => {
2022-11-25 23:54:43 +05:30
it('shows changed files count if changes count is not 0', () => {
2021-03-08 18:12:59 +05:30
changesCount = input;
2022-11-25 23:54:43 +05:30
createComponent();
2021-03-08 18:12:59 +05:30
2022-11-25 23:54:43 +05:30
expect(wrapper.find('.ide-file-modified').attributes('title')).toBe(output);
2021-03-08 18:12:59 +05:30
});
});
2018-12-05 23:21:45 +05:30
});
describe('show tree changes count', () => {
2022-11-25 23:54:43 +05:30
const findTreeChangesCount = () => wrapper.find('.ide-tree-changes');
2018-12-05 23:21:45 +05:30
it('does not show for blobs', () => {
2022-11-25 23:54:43 +05:30
createComponent({ type: 'blob' });
2018-12-05 23:21:45 +05:30
2022-11-25 23:54:43 +05:30
expect(findTreeChangesCount().exists()).toBe(false);
2018-12-05 23:21:45 +05:30
});
it('does not show when changes count is 0', () => {
2022-11-25 23:54:43 +05:30
createComponent({ type: 'tree' });
2018-12-05 23:21:45 +05:30
2022-11-25 23:54:43 +05:30
expect(findTreeChangesCount().exists()).toBe(false);
2018-12-05 23:21:45 +05:30
});
2022-11-25 23:54:43 +05:30
it('does not show when tree is open', () => {
2018-12-05 23:21:45 +05:30
changesCount = 1;
2022-11-25 23:54:43 +05:30
createComponent({ type: 'tree', opened: true });
2018-12-05 23:21:45 +05:30
2022-11-25 23:54:43 +05:30
expect(findTreeChangesCount().exists()).toBe(false);
2018-12-05 23:21:45 +05:30
});
2022-11-25 23:54:43 +05:30
it('shows for trees with changes', () => {
2018-12-05 23:21:45 +05:30
changesCount = 1;
2022-11-25 23:54:43 +05:30
createComponent({ type: 'tree', opened: false });
2018-12-05 23:21:45 +05:30
2022-11-25 23:54:43 +05:30
expect(findTreeChangesCount().exists()).toBe(true);
2018-12-05 23:21:45 +05:30
});
});
describe('changes file icon', () => {
2022-11-25 23:54:43 +05:30
const findChangedFileIcon = () => wrapper.find('.file-changed-icon');
2018-12-05 23:21:45 +05:30
it('hides when file is not changed', () => {
2022-11-25 23:54:43 +05:30
createComponent();
expect(findChangedFileIcon().exists()).toBe(false);
2018-12-05 23:21:45 +05:30
});
2022-11-25 23:54:43 +05:30
it('shows when file is changed', () => {
createComponent({ type: 'blob', changed: true });
2018-12-05 23:21:45 +05:30
2022-11-25 23:54:43 +05:30
expect(findChangedFileIcon().exists()).toBe(true);
2018-12-05 23:21:45 +05:30
});
2022-11-25 23:54:43 +05:30
it('shows when file is staged', () => {
createComponent({ type: 'blob', staged: true });
2018-12-05 23:21:45 +05:30
2022-11-25 23:54:43 +05:30
expect(findChangedFileIcon().exists()).toBe(true);
2018-12-05 23:21:45 +05:30
});
2022-11-25 23:54:43 +05:30
it('shows when file is a tempFile', () => {
createComponent({ type: 'blob', tempFile: true });
2018-12-05 23:21:45 +05:30
2022-11-25 23:54:43 +05:30
expect(findChangedFileIcon().exists()).toBe(true);
2018-12-05 23:21:45 +05:30
});
2019-12-21 20:55:43 +05:30
2022-11-25 23:54:43 +05:30
it('shows when file is renamed', () => {
createComponent({ type: 'blob', prevPath: 'original-file' });
2019-12-21 20:55:43 +05:30
2022-11-25 23:54:43 +05:30
expect(findChangedFileIcon().exists()).toBe(true);
2019-12-21 20:55:43 +05:30
});
2022-11-25 23:54:43 +05:30
it('hides when tree is renamed', () => {
createComponent({ type: 'tree', prevPath: 'original-path' });
2019-12-21 20:55:43 +05:30
2022-11-25 23:54:43 +05:30
expect(findChangedFileIcon().exists()).toBe(false);
2019-12-21 20:55:43 +05:30
});
2018-12-05 23:21:45 +05:30
});
describe('merge request icon', () => {
2022-11-25 23:54:43 +05:30
const findMergeRequestIcon = () => wrapper.find('[data-testid="git-merge-icon"]');
2018-12-05 23:21:45 +05:30
it('hides when not a merge request change', () => {
2022-11-25 23:54:43 +05:30
createComponent();
expect(findMergeRequestIcon().exists()).toBe(false);
2018-12-05 23:21:45 +05:30
});
2022-11-25 23:54:43 +05:30
it('shows when a merge request change', () => {
createComponent({ mrChange: true });
2018-12-05 23:21:45 +05:30
2022-11-25 23:54:43 +05:30
expect(findMergeRequestIcon().exists()).toBe(true);
2018-12-05 23:21:45 +05:30
});
});
});