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

147 lines
3.9 KiB
JavaScript
Raw Normal View History

2022-04-04 11:22:00 +05:30
import Vue, { nextTick } from 'vue';
2020-05-24 23:13:21 +05:30
import { createComponentWithStore } from 'helpers/vue_mount_component_helper';
2018-12-05 23:21:45 +05:30
import FileRowExtra from '~/ide/components/file_row_extra.vue';
2021-03-11 19:13:27 +05:30
import { createStore } 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', () => {
let Component;
let vm;
let unstagedFilesCount = 0;
let stagedFilesCount = 0;
let changesCount = 0;
beforeAll(() => {
Component = Vue.extend(FileRowExtra);
});
beforeEach(() => {
vm = createComponentWithStore(Component, createStore(), {
file: {
...file('test'),
},
2019-07-07 11:18:12 +05:30
dropdownOpen: false,
2018-12-05 23:21:45 +05:30
});
2020-05-24 23:13:21 +05:30
jest.spyOn(vm, 'getUnstagedFilesCountForPath', 'get').mockReturnValue(() => unstagedFilesCount);
jest.spyOn(vm, 'getStagedFilesCountForPath', 'get').mockReturnValue(() => stagedFilesCount);
jest.spyOn(vm, 'getChangesInFolder', 'get').mockReturnValue(() => changesCount);
2018-12-05 23:21:45 +05:30
vm.$mount();
});
afterEach(() => {
vm.$destroy();
stagedFilesCount = 0;
unstagedFilesCount = 0;
changesCount = 0;
});
describe('folderChangesTooltip', () => {
it('returns undefined when changes count is 0', () => {
2020-04-08 14:13:33 +05:30
changesCount = 0;
2018-12-05 23:21:45 +05:30
2020-04-08 14:13:33 +05:30
expect(vm.folderChangesTooltip).toBe(undefined);
2018-12-05 23:21:45 +05:30
});
2021-03-08 18:12:59 +05:30
[
{ input: 1, output: '1 changed file' },
{ input: 2, output: '2 changed files' },
].forEach(({ input, output }) => {
it('returns changed files count if changes count is not 0', () => {
changesCount = input;
expect(vm.folderChangesTooltip).toBe(output);
});
});
2018-12-05 23:21:45 +05:30
});
describe('show tree changes count', () => {
it('does not show for blobs', () => {
vm.file.type = 'blob';
expect(vm.$el.querySelector('.ide-tree-changes')).toBe(null);
});
it('does not show when changes count is 0', () => {
vm.file.type = 'tree';
expect(vm.$el.querySelector('.ide-tree-changes')).toBe(null);
});
2022-04-04 11:22:00 +05:30
it('does not show when tree is open', async () => {
2018-12-05 23:21:45 +05:30
vm.file.type = 'tree';
vm.file.opened = true;
changesCount = 1;
2022-04-04 11:22:00 +05:30
await nextTick();
expect(vm.$el.querySelector('.ide-tree-changes')).toBe(null);
2018-12-05 23:21:45 +05:30
});
2022-04-04 11:22:00 +05:30
it('shows for trees with changes', async () => {
2018-12-05 23:21:45 +05:30
vm.file.type = 'tree';
vm.file.opened = false;
changesCount = 1;
2022-04-04 11:22:00 +05:30
await nextTick();
expect(vm.$el.querySelector('.ide-tree-changes')).not.toBe(null);
2018-12-05 23:21:45 +05:30
});
});
describe('changes file icon', () => {
it('hides when file is not changed', () => {
expect(vm.$el.querySelector('.file-changed-icon')).toBe(null);
});
2022-04-04 11:22:00 +05:30
it('shows when file is changed', async () => {
2018-12-05 23:21:45 +05:30
vm.file.changed = true;
2022-04-04 11:22:00 +05:30
await nextTick();
expect(vm.$el.querySelector('.file-changed-icon')).not.toBe(null);
2018-12-05 23:21:45 +05:30
});
2022-04-04 11:22:00 +05:30
it('shows when file is staged', async () => {
2018-12-05 23:21:45 +05:30
vm.file.staged = true;
2022-04-04 11:22:00 +05:30
await nextTick();
expect(vm.$el.querySelector('.file-changed-icon')).not.toBe(null);
2018-12-05 23:21:45 +05:30
});
2022-04-04 11:22:00 +05:30
it('shows when file is a tempFile', async () => {
2018-12-05 23:21:45 +05:30
vm.file.tempFile = true;
2022-04-04 11:22:00 +05:30
await nextTick();
expect(vm.$el.querySelector('.file-changed-icon')).not.toBe(null);
2018-12-05 23:21:45 +05:30
});
2019-12-21 20:55:43 +05:30
2022-04-04 11:22:00 +05:30
it('shows when file is renamed', async () => {
2019-12-21 20:55:43 +05:30
vm.file.prevPath = 'original-file';
2022-04-04 11:22:00 +05:30
await nextTick();
expect(vm.$el.querySelector('.file-changed-icon')).not.toBe(null);
2019-12-21 20:55:43 +05:30
});
2022-04-04 11:22:00 +05:30
it('hides when file is renamed', async () => {
2019-12-21 20:55:43 +05:30
vm.file.prevPath = 'original-file';
vm.file.type = 'tree';
2022-04-04 11:22:00 +05:30
await nextTick();
expect(vm.$el.querySelector('.file-changed-icon')).toBe(null);
2019-12-21 20:55:43 +05:30
});
2018-12-05 23:21:45 +05:30
});
describe('merge request icon', () => {
it('hides when not a merge request change', () => {
2020-11-24 15:15:51 +05:30
expect(vm.$el.querySelector('[data-testid="git-merge-icon"]')).toBe(null);
2018-12-05 23:21:45 +05:30
});
2022-04-04 11:22:00 +05:30
it('shows when a merge request change', async () => {
2018-12-05 23:21:45 +05:30
vm.file.mrChange = true;
2022-04-04 11:22:00 +05:30
await nextTick();
expect(vm.$el.querySelector('[data-testid="git-merge-icon"]')).not.toBe(null);
2018-12-05 23:21:45 +05:30
});
});
});