summaryrefslogtreecommitdiff
path: root/spec/frontend/diffs/components/diff_line_note_form_spec.js
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-20 15:09:17 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-20 15:09:17 +0000
commit194b499aa8e26df26ff70a1e1ce0396587bd5243 (patch)
treec873ac9c3096faf4a5da43d6670107461da2a7d7 /spec/frontend/diffs/components/diff_line_note_form_spec.js
parent43b4b3e2d2ddebc0a89b94a8251c162ec5719780 (diff)
downloadgitlab-ce-194b499aa8e26df26ff70a1e1ce0396587bd5243.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/diffs/components/diff_line_note_form_spec.js')
-rw-r--r--spec/frontend/diffs/components/diff_line_note_form_spec.js108
1 files changed, 108 insertions, 0 deletions
diff --git a/spec/frontend/diffs/components/diff_line_note_form_spec.js b/spec/frontend/diffs/components/diff_line_note_form_spec.js
new file mode 100644
index 00000000000..9b032d10fdc
--- /dev/null
+++ b/spec/frontend/diffs/components/diff_line_note_form_spec.js
@@ -0,0 +1,108 @@
+import { shallowMount } from '@vue/test-utils';
+import DiffLineNoteForm from '~/diffs/components/diff_line_note_form.vue';
+import NoteForm from '~/notes/components/note_form.vue';
+import { createStore } from '~/mr_notes/stores';
+import diffFileMockData from '../mock_data/diff_file';
+import { noteableDataMock } from '../../notes/mock_data';
+
+describe('DiffLineNoteForm', () => {
+ let wrapper;
+ let diffFile;
+ let diffLines;
+ const getDiffFileMock = () => Object.assign({}, diffFileMockData);
+
+ beforeEach(() => {
+ diffFile = getDiffFileMock();
+ diffLines = diffFile.highlighted_diff_lines;
+ const store = createStore();
+ store.state.notes.userData.id = 1;
+ store.state.notes.noteableData = noteableDataMock;
+
+ wrapper = shallowMount(DiffLineNoteForm, {
+ store,
+ propsData: {
+ diffFileHash: diffFile.file_hash,
+ diffLines,
+ line: diffLines[0],
+ noteTargetLine: diffLines[0],
+ },
+ });
+ });
+
+ describe('methods', () => {
+ describe('handleCancelCommentForm', () => {
+ it('should ask for confirmation when shouldConfirm and isDirty passed as truthy', () => {
+ jest.spyOn(window, 'confirm').mockReturnValue(false);
+
+ wrapper.vm.handleCancelCommentForm(true, true);
+
+ expect(window.confirm).toHaveBeenCalled();
+ });
+
+ it('should ask for confirmation when one of the params false', () => {
+ jest.spyOn(window, 'confirm').mockReturnValue(false);
+
+ wrapper.vm.handleCancelCommentForm(true, false);
+
+ expect(window.confirm).not.toHaveBeenCalled();
+
+ wrapper.vm.handleCancelCommentForm(false, true);
+
+ expect(window.confirm).not.toHaveBeenCalled();
+ });
+
+ it('should call cancelCommentForm with lineCode', done => {
+ jest.spyOn(window, 'confirm').mockImplementation(() => {});
+ jest.spyOn(wrapper.vm, 'cancelCommentForm').mockImplementation(() => {});
+ jest.spyOn(wrapper.vm, 'resetAutoSave').mockImplementation(() => {});
+ wrapper.vm.handleCancelCommentForm();
+
+ expect(window.confirm).not.toHaveBeenCalled();
+ wrapper.vm.$nextTick(() => {
+ expect(wrapper.vm.cancelCommentForm).toHaveBeenCalledWith({
+ lineCode: diffLines[0].line_code,
+ fileHash: wrapper.vm.diffFileHash,
+ });
+
+ expect(wrapper.vm.resetAutoSave).toHaveBeenCalled();
+
+ done();
+ });
+ });
+ });
+
+ describe('saveNoteForm', () => {
+ it('should call saveNote action with proper params', done => {
+ const saveDiffDiscussionSpy = jest
+ .spyOn(wrapper.vm, 'saveDiffDiscussion')
+ .mockReturnValue(Promise.resolve());
+
+ wrapper.vm
+ .handleSaveNote('note body')
+ .then(() => {
+ expect(saveDiffDiscussionSpy).toHaveBeenCalledWith({
+ note: 'note body',
+ formData: wrapper.vm.formData,
+ });
+ })
+ .then(done)
+ .catch(done.fail);
+ });
+ });
+ });
+
+ describe('mounted', () => {
+ it('should init autosave', () => {
+ const key = 'autosave/Note/Issue/98//DiffNote//1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_1';
+
+ expect(wrapper.vm.autosave).toBeDefined();
+ expect(wrapper.vm.autosave.key).toEqual(key);
+ });
+ });
+
+ describe('template', () => {
+ it('should have note form', () => {
+ expect(wrapper.find(NoteForm).exists()).toBe(true);
+ });
+ });
+});