2018-05-09 12:01:36 +05:30
|
|
|
import Vue from 'vue';
|
2020-01-01 13:55:28 +05:30
|
|
|
import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
|
2018-11-18 11:00:15 +05:30
|
|
|
import { createStore } from '~/ide/stores';
|
2018-05-09 12:01:36 +05:30
|
|
|
import modal from '~/ide/components/new_dropdown/modal.vue';
|
|
|
|
|
|
|
|
describe('new file modal component', () => {
|
|
|
|
const Component = Vue.extend(modal);
|
|
|
|
let vm;
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
['tree', 'blob'].forEach(type => {
|
|
|
|
describe(type, () => {
|
|
|
|
beforeEach(() => {
|
2018-11-18 11:00:15 +05:30
|
|
|
const store = createStore();
|
|
|
|
store.state.entryModal = {
|
2018-05-09 12:01:36 +05:30
|
|
|
type,
|
|
|
|
path: '',
|
2019-07-07 11:18:12 +05:30
|
|
|
entry: {
|
|
|
|
path: '',
|
|
|
|
},
|
2018-11-18 11:00:15 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
vm = createComponentWithStore(Component, store).$mount();
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
vm.name = 'testing';
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it(`sets modal title as ${type}`, () => {
|
|
|
|
const title = type === 'tree' ? 'directory' : 'file';
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
expect(vm.$el.querySelector('.modal-title').textContent.trim()).toBe(`Create new ${title}`);
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it(`sets button label as ${type}`, () => {
|
|
|
|
const title = type === 'tree' ? 'directory' : 'file';
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
expect(vm.$el.querySelector('.btn-success').textContent.trim()).toBe(`Create ${title}`);
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it(`sets form label as ${type}`, () => {
|
2018-11-18 11:00:15 +05:30
|
|
|
expect(vm.$el.querySelector('.label-bold').textContent.trim()).toBe('Name');
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
it(`${type === 'tree' ? 'does not show' : 'shows'} file templates`, () => {
|
|
|
|
const templateFilesEl = vm.$el.querySelector('.file-templates');
|
|
|
|
if (type === 'tree') {
|
|
|
|
expect(templateFilesEl).toBeNull();
|
|
|
|
} else {
|
|
|
|
expect(templateFilesEl instanceof Element).toBeTruthy();
|
|
|
|
}
|
|
|
|
});
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
describe('rename entry', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
const store = createStore();
|
|
|
|
store.state.entryModal = {
|
|
|
|
type: 'rename',
|
2018-05-09 12:01:36 +05:30
|
|
|
path: '',
|
2018-11-18 11:00:15 +05:30
|
|
|
entry: {
|
|
|
|
name: 'test',
|
|
|
|
type: 'blob',
|
2019-07-07 11:18:12 +05:30
|
|
|
path: 'test-path',
|
2018-11-18 11:00:15 +05:30
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
vm = createComponentWithStore(Component, store).$mount();
|
|
|
|
});
|
|
|
|
|
|
|
|
['tree', 'blob'].forEach(type => {
|
|
|
|
it(`renders title and button for renaming ${type}`, done => {
|
|
|
|
const text = type === 'tree' ? 'folder' : 'file';
|
|
|
|
|
|
|
|
vm.$store.state.entryModal.entry.type = type;
|
|
|
|
|
|
|
|
vm.$nextTick(() => {
|
|
|
|
expect(vm.$el.querySelector('.modal-title').textContent.trim()).toBe(`Rename ${text}`);
|
|
|
|
expect(vm.$el.querySelector('.btn-success').textContent.trim()).toBe(`Rename ${text}`);
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('entryName', () => {
|
|
|
|
it('returns entries name', () => {
|
2019-07-07 11:18:12 +05:30
|
|
|
expect(vm.entryName).toBe('test-path');
|
2018-11-18 11:00:15 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('updated name', () => {
|
|
|
|
vm.name = 'index.js';
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
expect(vm.entryName).toBe('index.js');
|
|
|
|
});
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
it('removes leading/trailing spaces when found in the new name', () => {
|
|
|
|
vm.entryName = ' index.js ';
|
|
|
|
|
|
|
|
expect(vm.entryName).toBe('index.js');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not remove internal spaces in the file name', () => {
|
|
|
|
vm.entryName = ' In Praise of Idleness.txt ';
|
|
|
|
|
|
|
|
expect(vm.entryName).toBe('In Praise of Idleness.txt');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('submitForm', () => {
|
|
|
|
it('throws an error when target entry exists', () => {
|
|
|
|
const store = createStore();
|
|
|
|
store.state.entryModal = {
|
|
|
|
type: 'rename',
|
|
|
|
path: 'test-path/test',
|
|
|
|
entry: {
|
|
|
|
name: 'test',
|
|
|
|
type: 'blob',
|
|
|
|
path: 'test-path/test',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
store.state.entries = {
|
|
|
|
'test-path/test': {
|
|
|
|
name: 'test',
|
|
|
|
deleted: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
vm = createComponentWithStore(Component, store).$mount();
|
|
|
|
const flashSpy = spyOnDependency(modal, 'flash');
|
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
expect(flashSpy).not.toHaveBeenCalled();
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
vm.submitForm();
|
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
expect(flashSpy).toHaveBeenCalledWith(
|
|
|
|
'The name "test-path/test" is already taken in this directory.',
|
|
|
|
'alert',
|
|
|
|
jasmine.anything(),
|
|
|
|
null,
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
);
|
2018-11-18 11:00:15 +05:30
|
|
|
});
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
});
|