debian-mirror-gitlab/spec/frontend/blob/components/blob_edit_content_spec.js

91 lines
2.2 KiB
JavaScript
Raw Normal View History

2020-04-08 14:13:33 +05:30
import { shallowMount } from '@vue/test-utils';
import BlobEditContent from '~/blob/components/blob_edit_content.vue';
import { initEditorLite } from '~/blob/utils';
import { nextTick } from 'vue';
jest.mock('~/blob/utils', () => ({
initEditorLite: jest.fn(),
}));
describe('Blob Header Editing', () => {
let wrapper;
const value = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
const fileName = 'lorem.txt';
2020-04-22 19:07:51 +05:30
function createComponent(props = {}) {
2020-04-08 14:13:33 +05:30
wrapper = shallowMount(BlobEditContent, {
propsData: {
value,
fileName,
2020-04-22 19:07:51 +05:30
...props,
2020-04-08 14:13:33 +05:30
},
});
}
beforeEach(() => {
createComponent();
});
afterEach(() => {
wrapper.destroy();
});
describe('rendering', () => {
it('matches the snapshot', () => {
expect(wrapper.element).toMatchSnapshot();
});
it('renders content', () => {
expect(wrapper.text()).toContain(value);
});
});
describe('functionality', () => {
2020-04-22 19:07:51 +05:30
it('does not fail without content', () => {
const spy = jest.spyOn(global.console, 'error');
createComponent({ value: undefined });
expect(spy).not.toHaveBeenCalled();
expect(wrapper.contains('#editor')).toBe(true);
});
2020-04-08 14:13:33 +05:30
it('initialises Editor Lite', () => {
const el = wrapper.find({ ref: 'editor' }).element;
expect(initEditorLite).toHaveBeenCalledWith({
el,
blobPath: fileName,
blobContent: value,
});
});
it('reacts to the changes in fileName', () => {
wrapper.vm.editor = {
updateModelLanguage: jest.fn(),
};
const newFileName = 'ipsum.txt';
wrapper.setProps({
fileName: newFileName,
});
return nextTick().then(() => {
expect(wrapper.vm.editor.updateModelLanguage).toHaveBeenCalledWith(newFileName);
});
});
it('emits input event when the blob content is changed', () => {
const editorEl = wrapper.find({ ref: 'editor' });
wrapper.vm.editor = {
getValue: jest.fn().mockReturnValue(value),
};
2020-04-22 19:07:51 +05:30
editorEl.trigger('keyup');
2020-04-08 14:13:33 +05:30
return nextTick().then(() => {
expect(wrapper.emitted().input[0]).toEqual([value]);
});
});
});
});