debian-mirror-gitlab/spec/frontend/ide/components/file_templates/bar_spec.js

114 lines
2.9 KiB
JavaScript
Raw Normal View History

2018-11-20 20:47:30 +05:30
import Vue 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', () => {
2021-03-08 18:12:59 +05:30
beforeEach((done) => {
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',
};
vm.$nextTick(done);
});
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',
});
});
});
2021-03-08 18:12:59 +05:30
it('shows undo button if updateSuccess is true', (done) => {
2018-11-20 20:47:30 +05:30
vm.$store.state.fileTemplates.updateSuccess = true;
vm.$nextTick(() => {
expect(vm.$el.querySelector('.btn-default').style.display).not.toBe('none');
done();
});
});
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();
});
2021-03-08 18:12:59 +05:30
it('calls setSelectedTemplateType if activeFile name matches a template', (done) => {
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();
vm.$nextTick(() => {
expect(vm.setSelectedTemplateType).toHaveBeenCalledWith({
name: fileName,
key: 'gitlab_ci_ymls',
});
done();
});
});
});