2018-06-21 12:22:40 +00:00
|
|
|
import Vue from 'vue';
|
|
|
|
import DiffLineNoteForm from '~/diffs/components/diff_line_note_form.vue';
|
|
|
|
import store from '~/mr_notes/stores';
|
|
|
|
import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
|
|
|
|
import diffFileMockData from '../mock_data/diff_file';
|
2018-07-31 19:24:16 +00:00
|
|
|
import { noteableDataMock } from '../../notes/mock_data';
|
2018-06-21 12:22:40 +00:00
|
|
|
|
|
|
|
describe('DiffLineNoteForm', () => {
|
|
|
|
let component;
|
|
|
|
let diffFile;
|
|
|
|
let diffLines;
|
|
|
|
const getDiffFileMock = () => Object.assign({}, diffFileMockData);
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
diffFile = getDiffFileMock();
|
2018-11-09 19:48:41 +00:00
|
|
|
diffLines = diffFile.highlighted_diff_lines;
|
2018-06-21 12:22:40 +00:00
|
|
|
|
|
|
|
component = createComponentWithStore(Vue.extend(DiffLineNoteForm), store, {
|
2018-11-09 19:48:41 +00:00
|
|
|
diffFileHash: diffFile.file_hash,
|
2018-06-21 12:22:40 +00:00
|
|
|
diffLines,
|
|
|
|
line: diffLines[0],
|
|
|
|
noteTargetLine: diffLines[0],
|
2018-06-22 20:16:46 +00:00
|
|
|
});
|
|
|
|
|
2018-07-31 19:24:16 +00:00
|
|
|
Object.defineProperties(component, {
|
|
|
|
noteableData: { value: noteableDataMock },
|
|
|
|
isLoggedIn: { value: true },
|
2018-06-22 20:16:46 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
component.$mount();
|
2018-06-21 12:22:40 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('methods', () => {
|
|
|
|
describe('handleCancelCommentForm', () => {
|
2018-07-31 19:24:16 +00:00
|
|
|
it('should ask for confirmation when shouldConfirm and isDirty passed as truthy', () => {
|
|
|
|
spyOn(window, 'confirm').and.returnValue(false);
|
|
|
|
|
|
|
|
component.handleCancelCommentForm(true, true);
|
2018-10-09 18:03:09 +00:00
|
|
|
|
2018-07-31 19:24:16 +00:00
|
|
|
expect(window.confirm).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should ask for confirmation when one of the params false', () => {
|
|
|
|
spyOn(window, 'confirm').and.returnValue(false);
|
|
|
|
|
|
|
|
component.handleCancelCommentForm(true, false);
|
2018-10-09 18:03:09 +00:00
|
|
|
|
2018-07-31 19:24:16 +00:00
|
|
|
expect(window.confirm).not.toHaveBeenCalled();
|
|
|
|
|
|
|
|
component.handleCancelCommentForm(false, true);
|
2018-10-09 18:03:09 +00:00
|
|
|
|
2018-07-31 19:24:16 +00:00
|
|
|
expect(window.confirm).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should call cancelCommentForm with lineCode', done => {
|
|
|
|
spyOn(window, 'confirm');
|
2018-06-21 12:22:40 +00:00
|
|
|
spyOn(component, 'cancelCommentForm');
|
2018-07-31 19:24:16 +00:00
|
|
|
spyOn(component, 'resetAutoSave');
|
2018-06-21 12:22:40 +00:00
|
|
|
component.handleCancelCommentForm();
|
|
|
|
|
2018-07-31 19:24:16 +00:00
|
|
|
expect(window.confirm).not.toHaveBeenCalled();
|
|
|
|
component.$nextTick(() => {
|
|
|
|
expect(component.cancelCommentForm).toHaveBeenCalledWith({
|
2018-11-09 19:48:41 +00:00
|
|
|
lineCode: diffLines[0].line_code,
|
2018-07-31 19:24:16 +00:00
|
|
|
});
|
2018-10-09 18:03:09 +00:00
|
|
|
|
2018-07-31 19:24:16 +00:00
|
|
|
expect(component.resetAutoSave).toHaveBeenCalled();
|
|
|
|
|
|
|
|
done();
|
2018-06-21 12:22:40 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('saveNoteForm', () => {
|
|
|
|
it('should call saveNote action with proper params', done => {
|
2018-09-14 15:51:25 +00:00
|
|
|
const saveDiffDiscussionSpy = spyOn(component, 'saveDiffDiscussion').and.returnValue(
|
|
|
|
Promise.resolve(),
|
2018-06-21 12:22:40 +00:00
|
|
|
);
|
2018-09-14 15:51:25 +00:00
|
|
|
spyOnProperty(component, 'formData').and.returnValue('formData');
|
|
|
|
|
|
|
|
component
|
|
|
|
.handleSaveNote('note body')
|
|
|
|
.then(() => {
|
|
|
|
expect(saveDiffDiscussionSpy).toHaveBeenCalledWith({
|
|
|
|
note: 'note body',
|
|
|
|
formData: 'formData',
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
2018-06-21 12:22:40 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-06-22 20:16:46 +00:00
|
|
|
describe('mounted', () => {
|
|
|
|
it('should init autosave', () => {
|
2018-07-31 19:24:16 +00:00
|
|
|
const key = 'autosave/Note/Issue/98//DiffNote//1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_1';
|
2018-06-22 20:16:46 +00:00
|
|
|
|
|
|
|
expect(component.autosave).toBeDefined();
|
|
|
|
expect(component.autosave.key).toEqual(key);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-06-21 12:22:40 +00:00
|
|
|
describe('template', () => {
|
|
|
|
it('should have note form', () => {
|
|
|
|
const { $el } = component;
|
|
|
|
|
|
|
|
expect($el.querySelector('.js-vue-textarea')).toBeDefined();
|
|
|
|
expect($el.querySelector('.js-vue-issue-save')).toBeDefined();
|
|
|
|
expect($el.querySelector('.js-vue-markdown-field')).toBeDefined();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|