2019-02-26 13:43:32 -05:00
|
|
|
import { shallowMount, createLocalVue } from '@vue/test-utils';
|
2018-06-21 08:22:40 -04:00
|
|
|
import createStore from '~/notes/stores';
|
2019-02-26 13:43:32 -05:00
|
|
|
import NoteForm from '~/notes/components/note_form.vue';
|
|
|
|
import MarkdownField from '~/vue_shared/components/markdown/field.vue';
|
2017-11-30 17:44:41 -05:00
|
|
|
import { noteableDataMock, notesDataMock } from '../mock_data';
|
2017-08-11 12:36:59 -04:00
|
|
|
|
2017-08-11 14:54:26 -04:00
|
|
|
describe('issue_note_form component', () => {
|
2018-06-21 08:22:40 -04:00
|
|
|
let store;
|
2019-02-26 13:43:32 -05:00
|
|
|
let wrapper;
|
2017-08-11 12:36:59 -04:00
|
|
|
let props;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2018-06-21 08:22:40 -04:00
|
|
|
store = createStore();
|
2017-11-30 17:44:41 -05:00
|
|
|
store.dispatch('setNoteableData', noteableDataMock);
|
2017-08-11 12:36:59 -04:00
|
|
|
store.dispatch('setNotesData', notesDataMock);
|
|
|
|
|
|
|
|
props = {
|
2017-08-11 14:54:26 -04:00
|
|
|
isEditing: false,
|
2017-08-11 12:36:59 -04:00
|
|
|
noteBody: 'Magni suscipit eius consectetur enim et ex et commodi.',
|
2018-09-07 09:39:20 -04:00
|
|
|
noteId: '545',
|
2017-08-11 12:36:59 -04:00
|
|
|
};
|
|
|
|
|
2019-02-26 13:43:32 -05:00
|
|
|
const localVue = createLocalVue();
|
|
|
|
wrapper = shallowMount(NoteForm, {
|
2017-08-11 12:36:59 -04:00
|
|
|
store,
|
|
|
|
propsData: props,
|
2019-02-26 13:43:32 -05:00
|
|
|
// see https://gitlab.com/gitlab-org/gitlab-ce/issues/56317 for the following
|
|
|
|
localVue,
|
|
|
|
sync: false,
|
|
|
|
});
|
2017-08-11 12:36:59 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
2019-02-26 13:43:32 -05:00
|
|
|
wrapper.destroy();
|
2017-08-11 12:36:59 -04:00
|
|
|
});
|
|
|
|
|
2018-09-07 09:39:20 -04:00
|
|
|
describe('noteHash', () => {
|
|
|
|
it('returns note hash string based on `noteId`', () => {
|
2019-02-26 13:43:32 -05:00
|
|
|
expect(wrapper.vm.noteHash).toBe(`#note_${props.noteId}`);
|
2018-09-07 09:39:20 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('return note hash as `#` when `noteId` is empty', done => {
|
2019-02-26 13:43:32 -05:00
|
|
|
wrapper.setProps({
|
|
|
|
...props,
|
|
|
|
noteId: '',
|
|
|
|
});
|
|
|
|
|
|
|
|
wrapper.vm
|
|
|
|
.$nextTick()
|
2018-09-07 09:39:20 -04:00
|
|
|
.then(() => {
|
2019-02-26 13:43:32 -05:00
|
|
|
expect(wrapper.vm.noteHash).toBe('#');
|
2018-09-07 09:39:20 -04:00
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-08-11 14:54:26 -04:00
|
|
|
describe('conflicts editing', () => {
|
2018-06-21 08:22:40 -04:00
|
|
|
it('should show conflict message if note changes outside the component', done => {
|
2019-02-26 13:43:32 -05:00
|
|
|
wrapper.setProps({
|
|
|
|
...props,
|
|
|
|
isEditing: true,
|
|
|
|
noteBody: 'Foo',
|
|
|
|
});
|
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
const message =
|
|
|
|
'This comment has changed since you started editing, please review the updated comment to ensure information is not lost.';
|
2017-08-11 12:36:59 -04:00
|
|
|
|
2019-02-26 13:43:32 -05:00
|
|
|
wrapper.vm
|
|
|
|
.$nextTick()
|
|
|
|
.then(() => {
|
|
|
|
const conflictWarning = wrapper.find('.js-conflict-edit-warning');
|
|
|
|
|
|
|
|
expect(conflictWarning.exists()).toBe(true);
|
|
|
|
expect(
|
|
|
|
conflictWarning
|
|
|
|
.text()
|
|
|
|
.replace(/\s+/g, ' ')
|
|
|
|
.trim(),
|
|
|
|
).toBe(message);
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('form', () => {
|
|
|
|
it('should render text area with placeholder', () => {
|
2019-02-26 13:43:32 -05:00
|
|
|
const textarea = wrapper.find('textarea');
|
|
|
|
|
|
|
|
expect(textarea.attributes('placeholder')).toEqual(
|
2018-06-21 08:22:40 -04:00
|
|
|
'Write a comment or drag your files here…',
|
|
|
|
);
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should link to markdown docs', () => {
|
2017-08-17 13:25:56 -04:00
|
|
|
const { markdownDocsPath } = notesDataMock;
|
2019-02-26 13:43:32 -05:00
|
|
|
const markdownField = wrapper.find(MarkdownField);
|
|
|
|
const markdownFieldProps = markdownField.props();
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2019-02-26 13:43:32 -05:00
|
|
|
expect(markdownFieldProps.markdownDocsPath).toBe(markdownDocsPath);
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('keyboard events', () => {
|
2019-02-26 13:43:32 -05:00
|
|
|
let textarea;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
textarea = wrapper.find('textarea');
|
|
|
|
textarea.setValue('Foo');
|
|
|
|
});
|
|
|
|
|
2017-08-04 11:51:35 -04:00
|
|
|
describe('up', () => {
|
|
|
|
it('should ender edit mode', () => {
|
2019-02-26 13:43:32 -05:00
|
|
|
// TODO: do not spy on vm
|
|
|
|
spyOn(wrapper.vm, 'editMyLastNote').and.callThrough();
|
|
|
|
|
|
|
|
textarea.trigger('keydown.up');
|
2017-08-04 11:51:35 -04:00
|
|
|
|
2019-02-26 13:43:32 -05:00
|
|
|
expect(wrapper.vm.editMyLastNote).toHaveBeenCalled();
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('enter', () => {
|
2018-01-11 21:22:28 -05:00
|
|
|
it('should save note when cmd+enter is pressed', () => {
|
2019-02-26 13:43:32 -05:00
|
|
|
textarea.trigger('keydown.enter', { metaKey: true });
|
|
|
|
|
|
|
|
const { handleFormUpdate } = wrapper.emitted();
|
2017-08-04 11:51:35 -04:00
|
|
|
|
2019-02-26 13:43:32 -05:00
|
|
|
expect(handleFormUpdate.length).toBe(1);
|
2018-01-11 21:22:28 -05:00
|
|
|
});
|
2018-10-09 13:01:49 -04:00
|
|
|
|
2018-01-11 21:22:28 -05:00
|
|
|
it('should save note when ctrl+enter is pressed', () => {
|
2019-02-26 13:43:32 -05:00
|
|
|
textarea.trigger('keydown.enter', { ctrlKey: true });
|
2018-01-11 21:22:28 -05:00
|
|
|
|
2019-02-26 13:43:32 -05:00
|
|
|
const { handleFormUpdate } = wrapper.emitted();
|
|
|
|
|
|
|
|
expect(handleFormUpdate.length).toBe(1);
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('actions', () => {
|
2018-06-21 08:22:40 -04:00
|
|
|
it('should be possible to cancel', done => {
|
2019-02-26 13:43:32 -05:00
|
|
|
// TODO: do not spy on vm
|
|
|
|
spyOn(wrapper.vm, 'cancelHandler').and.callThrough();
|
|
|
|
wrapper.setProps({
|
|
|
|
...props,
|
|
|
|
isEditing: true,
|
|
|
|
});
|
2017-08-04 11:51:35 -04:00
|
|
|
|
2019-02-26 13:43:32 -05:00
|
|
|
wrapper.vm
|
|
|
|
.$nextTick()
|
|
|
|
.then(() => {
|
|
|
|
const cancelButton = wrapper.find('.note-edit-cancel');
|
|
|
|
cancelButton.trigger('click');
|
2017-08-04 11:51:35 -04:00
|
|
|
|
2019-02-26 13:43:32 -05:00
|
|
|
expect(wrapper.vm.cancelHandler).toHaveBeenCalled();
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
it('should be possible to update the note', done => {
|
2019-02-26 13:43:32 -05:00
|
|
|
wrapper.setProps({
|
|
|
|
...props,
|
|
|
|
isEditing: true,
|
2017-08-11 14:54:26 -04:00
|
|
|
});
|
2019-02-26 13:43:32 -05:00
|
|
|
|
|
|
|
wrapper.vm
|
|
|
|
.$nextTick()
|
|
|
|
.then(() => {
|
|
|
|
const textarea = wrapper.find('textarea');
|
|
|
|
textarea.setValue('Foo');
|
|
|
|
const saveButton = wrapper.find('.js-vue-issue-save');
|
|
|
|
saveButton.trigger('click');
|
|
|
|
|
|
|
|
expect(wrapper.vm.isSubmitting).toEqual(true);
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-08-09 15:13:00 -04:00
|
|
|
});
|