2022-04-04 11:22:00 +05:30
|
|
|
import Vue, { nextTick } from 'vue';
|
2020-05-24 23:13:21 +05:30
|
|
|
import { mountComponentWithStore } from 'helpers/vue_mount_component_helper';
|
2018-11-20 20:47:30 +05:30
|
|
|
import Bar from '~/ide/components/file_templates/bar.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-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
describe('IDE file templates bar component', () => {
|
|
|
|
let Component;
|
|
|
|
let vm;
|
|
|
|
|
|
|
|
beforeAll(() => {
|
|
|
|
Component = Vue.extend(Bar);
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
const store = createStore();
|
|
|
|
|
|
|
|
store.state.openFiles.push({
|
|
|
|
...file('file'),
|
|
|
|
opened: true,
|
|
|
|
active: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
vm = mountComponentWithStore(Component, { store });
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('template type dropdown', () => {
|
|
|
|
it('renders dropdown component', () => {
|
|
|
|
expect(vm.$el.querySelector('.dropdown').textContent).toContain('Choose a type');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls setSelectedTemplateType when clicking item', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
jest.spyOn(vm, 'setSelectedTemplateType').mockImplementation();
|
2018-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
vm.$el.querySelector('.dropdown-content button').click();
|
|
|
|
|
|
|
|
expect(vm.setSelectedTemplateType).toHaveBeenCalledWith({
|
|
|
|
name: '.gitlab-ci.yml',
|
|
|
|
key: 'gitlab_ci_ymls',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('template dropdown', () => {
|
2022-04-04 11:22:00 +05:30
|
|
|
beforeEach(async () => {
|
2018-11-20 20:47:30 +05:30
|
|
|
vm.$store.state.fileTemplates.templates = [
|
|
|
|
{
|
|
|
|
name: 'test',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
vm.$store.state.fileTemplates.selectedTemplateType = {
|
|
|
|
name: '.gitlab-ci.yml',
|
|
|
|
key: 'gitlab_ci_ymls',
|
|
|
|
};
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
2018-11-20 20:47:30 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders dropdown component', () => {
|
|
|
|
expect(vm.$el.querySelectorAll('.dropdown')[1].textContent).toContain('Choose a template');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls fetchTemplate on click', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
jest.spyOn(vm, 'fetchTemplate').mockImplementation();
|
2018-11-20 20:47:30 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
vm.$el.querySelectorAll('.dropdown-content')[1].querySelector('button').click();
|
2018-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
expect(vm.fetchTemplate).toHaveBeenCalledWith({
|
|
|
|
name: 'test',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('shows undo button if updateSuccess is true', async () => {
|
2018-11-20 20:47:30 +05:30
|
|
|
vm.$store.state.fileTemplates.updateSuccess = true;
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
|
|
|
expect(vm.$el.querySelector('.btn-default').style.display).not.toBe('none');
|
2018-11-20 20:47:30 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('calls undoFileTemplate when clicking undo button', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
jest.spyOn(vm, 'undoFileTemplate').mockImplementation();
|
2018-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
vm.$el.querySelector('.btn-default').click();
|
|
|
|
|
|
|
|
expect(vm.undoFileTemplate).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('calls setSelectedTemplateType if activeFile name matches a template', async () => {
|
2018-11-20 20:47:30 +05:30
|
|
|
const fileName = '.gitlab-ci.yml';
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
jest.spyOn(vm, 'setSelectedTemplateType').mockImplementation(() => {});
|
2018-11-20 20:47:30 +05:30
|
|
|
vm.$store.state.openFiles[0].name = fileName;
|
|
|
|
|
|
|
|
vm.setInitialType();
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
|
|
|
expect(vm.setSelectedTemplateType).toHaveBeenCalledWith({
|
|
|
|
name: fileName,
|
|
|
|
key: 'gitlab_ci_ymls',
|
2018-11-20 20:47:30 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|