debian-mirror-gitlab/spec/javascripts/diffs/components/diff_line_note_form_spec.js

115 lines
3.5 KiB
JavaScript
Raw Normal View History

2018-11-08 19:23:39 +05:30
import Vue from 'vue';
2020-01-01 13:55:28 +05:30
import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
2018-11-08 19:23:39 +05:30
import DiffLineNoteForm from '~/diffs/components/diff_line_note_form.vue';
2019-10-12 21:52:04 +05:30
import { createStore } from '~/mr_notes/stores';
2018-11-08 19:23:39 +05:30
import diffFileMockData from '../mock_data/diff_file';
2018-11-18 11:00:15 +05:30
import { noteableDataMock } from '../../notes/mock_data';
2018-11-08 19:23:39 +05:30
describe('DiffLineNoteForm', () => {
let component;
let diffFile;
let diffLines;
const getDiffFileMock = () => Object.assign({}, diffFileMockData);
beforeEach(() => {
diffFile = getDiffFileMock();
2019-02-15 15:39:39 +05:30
diffLines = diffFile.highlighted_diff_lines;
2018-11-08 19:23:39 +05:30
2019-10-12 21:52:04 +05:30
component = createComponentWithStore(Vue.extend(DiffLineNoteForm), createStore(), {
2019-02-15 15:39:39 +05:30
diffFileHash: diffFile.file_hash,
2018-11-08 19:23:39 +05:30
diffLines,
line: diffLines[0],
noteTargetLine: diffLines[0],
});
2018-11-18 11:00:15 +05:30
Object.defineProperties(component, {
noteableData: { value: noteableDataMock },
isLoggedIn: { value: true },
2018-11-08 19:23:39 +05:30
});
component.$mount();
});
describe('methods', () => {
describe('handleCancelCommentForm', () => {
2018-11-18 11:00:15 +05:30
it('should ask for confirmation when shouldConfirm and isDirty passed as truthy', () => {
spyOn(window, 'confirm').and.returnValue(false);
component.handleCancelCommentForm(true, true);
2018-12-13 13:39:08 +05:30
2018-11-18 11:00:15 +05:30
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-12-13 13:39:08 +05:30
2018-11-18 11:00:15 +05:30
expect(window.confirm).not.toHaveBeenCalled();
component.handleCancelCommentForm(false, true);
2018-12-13 13:39:08 +05:30
2018-11-18 11:00:15 +05:30
expect(window.confirm).not.toHaveBeenCalled();
});
it('should call cancelCommentForm with lineCode', done => {
spyOn(window, 'confirm');
2018-11-08 19:23:39 +05:30
spyOn(component, 'cancelCommentForm');
2018-11-18 11:00:15 +05:30
spyOn(component, 'resetAutoSave');
2018-11-08 19:23:39 +05:30
component.handleCancelCommentForm();
2018-11-18 11:00:15 +05:30
expect(window.confirm).not.toHaveBeenCalled();
component.$nextTick(() => {
expect(component.cancelCommentForm).toHaveBeenCalledWith({
2019-02-15 15:39:39 +05:30
lineCode: diffLines[0].line_code,
fileHash: component.diffFileHash,
2018-11-18 11:00:15 +05:30
});
2018-12-13 13:39:08 +05:30
2018-11-18 11:00:15 +05:30
expect(component.resetAutoSave).toHaveBeenCalled();
done();
2018-11-08 19:23:39 +05:30
});
});
});
describe('saveNoteForm', () => {
it('should call saveNote action with proper params', done => {
2018-12-05 23:21:45 +05:30
const saveDiffDiscussionSpy = spyOn(component, 'saveDiffDiscussion').and.returnValue(
Promise.resolve(),
2018-11-08 19:23:39 +05:30
);
2018-12-05 23:21:45 +05:30
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-11-08 19:23:39 +05:30
});
});
});
describe('mounted', () => {
it('should init autosave', () => {
2018-11-18 11:00:15 +05:30
const key = 'autosave/Note/Issue/98//DiffNote//1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_1';
2018-11-08 19:23:39 +05:30
expect(component.autosave).toBeDefined();
expect(component.autosave.key).toEqual(key);
});
});
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();
});
});
});