2022-11-25 23:54:43 +05:30
|
|
|
import { nextTick } from 'vue';
|
|
|
|
import { mount } from '@vue/test-utils';
|
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', () => {
|
2022-11-25 23:54:43 +05:30
|
|
|
let wrapper;
|
|
|
|
let store;
|
2018-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
beforeEach(() => {
|
2022-11-25 23:54:43 +05:30
|
|
|
store = createStore();
|
|
|
|
jest.spyOn(store, 'dispatch').mockImplementation();
|
2018-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
store.state.openFiles.push({
|
|
|
|
...file('file'),
|
|
|
|
opened: true,
|
|
|
|
active: true,
|
|
|
|
});
|
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
wrapper = mount(Bar, { store });
|
2018-11-20 20:47:30 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
2022-11-25 23:54:43 +05:30
|
|
|
wrapper.destroy();
|
2018-11-20 20:47:30 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('template type dropdown', () => {
|
|
|
|
it('renders dropdown component', () => {
|
2022-11-25 23:54:43 +05:30
|
|
|
expect(wrapper.find('.dropdown').text()).toContain('Choose a type');
|
2018-11-20 20:47:30 +05:30
|
|
|
});
|
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
it('calls setSelectedTemplateType when clicking item', async () => {
|
|
|
|
await wrapper.find('.dropdown-menu button').trigger('click');
|
2018-11-20 20:47:30 +05:30
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
expect(store.dispatch).toHaveBeenCalledWith('fileTemplates/setSelectedTemplateType', {
|
2018-11-20 20:47:30 +05:30
|
|
|
name: '.gitlab-ci.yml',
|
|
|
|
key: 'gitlab_ci_ymls',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('template dropdown', () => {
|
2022-11-25 23:54:43 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
store.state.fileTemplates.templates = [
|
2018-11-20 20:47:30 +05:30
|
|
|
{
|
|
|
|
name: 'test',
|
|
|
|
},
|
|
|
|
];
|
2022-11-25 23:54:43 +05:30
|
|
|
store.state.fileTemplates.selectedTemplateType = {
|
2018-11-20 20:47:30 +05:30
|
|
|
name: '.gitlab-ci.yml',
|
|
|
|
key: 'gitlab_ci_ymls',
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders dropdown component', () => {
|
2022-11-25 23:54:43 +05:30
|
|
|
expect(wrapper.findAll('.dropdown').at(1).text()).toContain('Choose a template');
|
2018-11-20 20:47:30 +05:30
|
|
|
});
|
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
it('calls fetchTemplate on dropdown open', async () => {
|
|
|
|
await wrapper.findAll('.dropdown-menu').at(1).find('button').trigger('click');
|
2018-11-20 20:47:30 +05:30
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
expect(store.dispatch).toHaveBeenCalledWith('fileTemplates/fetchTemplate', {
|
2018-11-20 20:47:30 +05:30
|
|
|
name: 'test',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
const findUndoButton = () => wrapper.find('.btn-default-secondary');
|
2022-04-04 11:22:00 +05:30
|
|
|
it('shows undo button if updateSuccess is true', async () => {
|
2022-11-25 23:54:43 +05:30
|
|
|
store.state.fileTemplates.updateSuccess = true;
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
2018-11-20 20:47:30 +05:30
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
expect(findUndoButton().isVisible()).toBe(true);
|
|
|
|
});
|
2018-11-20 20:47:30 +05:30
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
it('calls undoFileTemplate when clicking undo button', async () => {
|
|
|
|
await findUndoButton().trigger('click');
|
2018-11-20 20:47:30 +05:30
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
expect(store.dispatch).toHaveBeenCalledWith('fileTemplates/undoFileTemplate', undefined);
|
2018-11-20 20:47:30 +05:30
|
|
|
});
|
|
|
|
|
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';
|
2022-11-25 23:54:43 +05:30
|
|
|
store.state.openFiles = [{ ...file(fileName), opened: true, active: true }];
|
2018-11-20 20:47:30 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
2022-11-25 23:54:43 +05:30
|
|
|
|
|
|
|
expect(store.dispatch).toHaveBeenCalledWith('fileTemplates/setSelectedTemplateType', {
|
2022-04-04 11:22:00 +05:30
|
|
|
name: fileName,
|
|
|
|
key: 'gitlab_ci_ymls',
|
2018-11-20 20:47:30 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|