2018-09-17 07:17:00 -04:00
|
|
|
import Vue from 'vue';
|
2020-05-07 08:09:46 -04:00
|
|
|
import { createComponentWithStore } from 'helpers/vue_mount_component_helper';
|
2018-09-17 07:17:00 -04:00
|
|
|
import FileRowExtra from '~/ide/components/file_row_extra.vue';
|
2021-02-14 13:09:20 -05:00
|
|
|
import { createStore } from '~/ide/stores';
|
2020-07-21 05:09:34 -04:00
|
|
|
import { file } from '../helpers';
|
2018-09-17 07:17:00 -04:00
|
|
|
|
|
|
|
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-04-04 14:55:49 -04:00
|
|
|
dropdownOpen: false,
|
2018-09-17 07:17:00 -04:00
|
|
|
});
|
|
|
|
|
2020-05-07 08:09:46 -04:00
|
|
|
jest.spyOn(vm, 'getUnstagedFilesCountForPath', 'get').mockReturnValue(() => unstagedFilesCount);
|
|
|
|
jest.spyOn(vm, 'getStagedFilesCountForPath', 'get').mockReturnValue(() => stagedFilesCount);
|
|
|
|
jest.spyOn(vm, 'getChangesInFolder', 'get').mockReturnValue(() => changesCount);
|
2018-09-17 07:17:00 -04:00
|
|
|
|
|
|
|
vm.$mount();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
|
|
|
|
|
|
|
stagedFilesCount = 0;
|
|
|
|
unstagedFilesCount = 0;
|
|
|
|
changesCount = 0;
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('folderChangesTooltip', () => {
|
|
|
|
it('returns undefined when changes count is 0', () => {
|
2020-03-13 08:09:22 -04:00
|
|
|
changesCount = 0;
|
2018-09-17 07:17:00 -04:00
|
|
|
|
2020-03-13 08:09:22 -04:00
|
|
|
expect(vm.folderChangesTooltip).toBe(undefined);
|
2018-09-17 07:17:00 -04:00
|
|
|
});
|
|
|
|
|
2020-12-23 07:10:26 -05:00
|
|
|
[
|
|
|
|
{ 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-09-17 07:17:00 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
2020-12-23 16:10:24 -05:00
|
|
|
it('does not show when tree is open', (done) => {
|
2018-09-17 07:17:00 -04:00
|
|
|
vm.file.type = 'tree';
|
|
|
|
vm.file.opened = true;
|
|
|
|
changesCount = 1;
|
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.$el.querySelector('.ide-tree-changes')).toBe(null);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-12-23 16:10:24 -05:00
|
|
|
it('shows for trees with changes', (done) => {
|
2018-09-17 07:17:00 -04:00
|
|
|
vm.file.type = 'tree';
|
|
|
|
vm.file.opened = false;
|
|
|
|
changesCount = 1;
|
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.$el.querySelector('.ide-tree-changes')).not.toBe(null);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('changes file icon', () => {
|
|
|
|
it('hides when file is not changed', () => {
|
2018-10-03 05:05:43 -04:00
|
|
|
expect(vm.$el.querySelector('.file-changed-icon')).toBe(null);
|
2018-09-17 07:17:00 -04:00
|
|
|
});
|
|
|
|
|
2020-12-23 16:10:24 -05:00
|
|
|
it('shows when file is changed', (done) => {
|
2018-09-17 07:17:00 -04:00
|
|
|
vm.file.changed = true;
|
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
2018-10-03 05:05:43 -04:00
|
|
|
expect(vm.$el.querySelector('.file-changed-icon')).not.toBe(null);
|
2018-09-17 07:17:00 -04:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-12-23 16:10:24 -05:00
|
|
|
it('shows when file is staged', (done) => {
|
2018-09-17 07:17:00 -04:00
|
|
|
vm.file.staged = true;
|
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
2018-10-03 05:05:43 -04:00
|
|
|
expect(vm.$el.querySelector('.file-changed-icon')).not.toBe(null);
|
2018-09-17 07:17:00 -04:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-12-23 16:10:24 -05:00
|
|
|
it('shows when file is a tempFile', (done) => {
|
2018-09-17 07:17:00 -04:00
|
|
|
vm.file.tempFile = true;
|
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
2018-10-03 05:05:43 -04:00
|
|
|
expect(vm.$el.querySelector('.file-changed-icon')).not.toBe(null);
|
2018-09-17 07:17:00 -04:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2019-10-04 11:06:38 -04:00
|
|
|
|
2020-12-23 16:10:24 -05:00
|
|
|
it('shows when file is renamed', (done) => {
|
2019-10-04 11:06:38 -04:00
|
|
|
vm.file.prevPath = 'original-file';
|
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.$el.querySelector('.file-changed-icon')).not.toBe(null);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-12-23 16:10:24 -05:00
|
|
|
it('hides when file is renamed', (done) => {
|
2019-10-04 11:06:38 -04:00
|
|
|
vm.file.prevPath = 'original-file';
|
|
|
|
vm.file.type = 'tree';
|
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.$el.querySelector('.file-changed-icon')).toBe(null);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2018-09-17 07:17:00 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('merge request icon', () => {
|
|
|
|
it('hides when not a merge request change', () => {
|
2020-08-20 17:10:18 -04:00
|
|
|
expect(vm.$el.querySelector('[data-testid="git-merge-icon"]')).toBe(null);
|
2018-09-17 07:17:00 -04:00
|
|
|
});
|
|
|
|
|
2020-12-23 16:10:24 -05:00
|
|
|
it('shows when a merge request change', (done) => {
|
2018-09-17 07:17:00 -04:00
|
|
|
vm.file.mrChange = true;
|
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
2020-08-20 17:10:18 -04:00
|
|
|
expect(vm.$el.querySelector('[data-testid="git-merge-icon"]')).not.toBe(null);
|
2018-09-17 07:17:00 -04:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|