2017-08-11 12:36:59 -04:00
|
|
|
import Vue from 'vue';
|
2018-06-21 08:22:40 -04:00
|
|
|
import createStore from '~/notes/stores';
|
2017-12-08 15:24:52 -05:00
|
|
|
import issueNoteForm from '~/notes/components/note_form.vue';
|
2017-11-30 17:44:41 -05:00
|
|
|
import { noteableDataMock, notesDataMock } from '../mock_data';
|
2017-08-11 14:54:26 -04:00
|
|
|
import { keyboardDownEvent } from '../../issue_show/helpers';
|
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;
|
2017-08-11 12:36:59 -04:00
|
|
|
let vm;
|
|
|
|
let props;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2017-08-11 14:54:26 -04:00
|
|
|
const Component = Vue.extend(issueNoteForm);
|
2017-08-11 12:36:59 -04:00
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
vm = new Component({
|
|
|
|
store,
|
|
|
|
propsData: props,
|
|
|
|
}).$mount();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
|
|
|
});
|
|
|
|
|
2018-09-07 09:39:20 -04:00
|
|
|
describe('noteHash', () => {
|
|
|
|
it('returns note hash string based on `noteId`', () => {
|
|
|
|
expect(vm.noteHash).toBe(`#note_${props.noteId}`);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('return note hash as `#` when `noteId` is empty', done => {
|
|
|
|
vm.noteId = '';
|
|
|
|
Vue.nextTick()
|
|
|
|
.then(() => {
|
|
|
|
expect(vm.noteHash).toBe('#');
|
|
|
|
})
|
|
|
|
.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 => {
|
2017-08-11 14:54:26 -04:00
|
|
|
vm.isEditing = true;
|
2017-08-11 12:36:59 -04:00
|
|
|
vm.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
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
2017-08-11 14:54:26 -04:00
|
|
|
expect(
|
2018-06-21 08:22:40 -04:00
|
|
|
vm.$el
|
|
|
|
.querySelector('.js-conflict-edit-warning')
|
|
|
|
.textContent.replace(/\s+/g, ' ')
|
|
|
|
.trim(),
|
2017-08-11 14:54:26 -04:00
|
|
|
).toEqual(message);
|
2017-08-11 12:36:59 -04:00
|
|
|
done();
|
|
|
|
});
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('form', () => {
|
|
|
|
it('should render text area with placeholder', () => {
|
2018-06-21 08:22:40 -04:00
|
|
|
expect(vm.$el.querySelector('textarea').getAttribute('placeholder')).toEqual(
|
|
|
|
'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;
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
expect(vm.$el.querySelector(`a[href="${markdownDocsPath}"]`).textContent.trim()).toEqual(
|
|
|
|
'Markdown',
|
|
|
|
);
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('keyboard events', () => {
|
|
|
|
describe('up', () => {
|
|
|
|
it('should ender edit mode', () => {
|
2017-08-11 14:54:26 -04:00
|
|
|
spyOn(vm, 'editMyLastNote').and.callThrough();
|
|
|
|
vm.$el.querySelector('textarea').value = 'Foo';
|
|
|
|
vm.$el.querySelector('textarea').dispatchEvent(keyboardDownEvent(38, true));
|
2017-08-04 11:51:35 -04:00
|
|
|
|
2017-08-11 14:54:26 -04:00
|
|
|
expect(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', () => {
|
2017-08-11 14:54:26 -04:00
|
|
|
spyOn(vm, 'handleUpdate').and.callThrough();
|
|
|
|
vm.$el.querySelector('textarea').value = 'Foo';
|
|
|
|
vm.$el.querySelector('textarea').dispatchEvent(keyboardDownEvent(13, true));
|
2017-08-04 11:51:35 -04:00
|
|
|
|
2018-01-11 21:22:28 -05:00
|
|
|
expect(vm.handleUpdate).toHaveBeenCalled();
|
|
|
|
});
|
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', () => {
|
|
|
|
spyOn(vm, 'handleUpdate').and.callThrough();
|
|
|
|
vm.$el.querySelector('textarea').value = 'Foo';
|
|
|
|
vm.$el.querySelector('textarea').dispatchEvent(keyboardDownEvent(13, false, true));
|
|
|
|
|
2017-08-11 14:54:26 -04:00
|
|
|
expect(vm.handleUpdate).toHaveBeenCalled();
|
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 => {
|
2017-08-11 14:54:26 -04:00
|
|
|
spyOn(vm, 'cancelHandler').and.callThrough();
|
|
|
|
vm.isEditing = true;
|
2017-08-04 11:51:35 -04:00
|
|
|
|
2017-08-11 14:54:26 -04:00
|
|
|
Vue.nextTick(() => {
|
|
|
|
vm.$el.querySelector('.note-edit-cancel').click();
|
2017-08-04 11:51:35 -04:00
|
|
|
|
2017-08-11 14:54:26 -04:00
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(vm.cancelHandler).toHaveBeenCalled();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
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 => {
|
2017-08-11 14:54:26 -04:00
|
|
|
vm.isEditing = true;
|
2017-08-04 11:51:35 -04:00
|
|
|
|
2017-08-11 14:54:26 -04:00
|
|
|
Vue.nextTick(() => {
|
|
|
|
vm.$el.querySelector('textarea').value = 'Foo';
|
|
|
|
vm.$el.querySelector('.js-vue-issue-save').click();
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(vm.isSubmitting).toEqual(true);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-08-09 15:13:00 -04:00
|
|
|
});
|