2017-12-19 05:12:32 -05:00
|
|
|
import _ from 'underscore';
|
2019-02-12 15:55:56 -05:00
|
|
|
import { shallowMount, createLocalVue } from '@vue/test-utils';
|
2018-06-21 08:22:40 -04:00
|
|
|
import createStore from '~/notes/stores';
|
2017-12-08 15:24:52 -05:00
|
|
|
import issueNote from '~/notes/components/noteable_note.vue';
|
2019-02-12 15:55:56 -05:00
|
|
|
import NoteHeader from '~/notes/components/note_header.vue';
|
|
|
|
import UserAvatarLink from '~/vue_shared/components/user_avatar/user_avatar_link.vue';
|
|
|
|
import NoteActions from '~/notes/components/note_actions.vue';
|
|
|
|
import NoteBody from '~/notes/components/note_body.vue';
|
2017-11-30 17:44:41 -05:00
|
|
|
import { noteableDataMock, notesDataMock, note } from '../mock_data';
|
2017-08-11 12:36:59 -04:00
|
|
|
|
2017-08-04 11:51:35 -04:00
|
|
|
describe('issue_note', () => {
|
2018-06-21 08:22:40 -04:00
|
|
|
let store;
|
2019-02-12 15:55:56 -05:00
|
|
|
let wrapper;
|
2017-08-11 12:36:59 -04:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2019-02-12 15:55:56 -05:00
|
|
|
const localVue = createLocalVue();
|
|
|
|
wrapper = shallowMount(issueNote, {
|
2017-08-11 12:36:59 -04:00
|
|
|
store,
|
|
|
|
propsData: {
|
|
|
|
note,
|
|
|
|
},
|
2019-02-12 15:55:56 -05:00
|
|
|
sync: false,
|
|
|
|
localVue,
|
|
|
|
});
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
|
|
|
|
2017-08-11 12:36:59 -04:00
|
|
|
afterEach(() => {
|
2019-02-12 15:55:56 -05:00
|
|
|
wrapper.destroy();
|
2017-08-11 12:36:59 -04:00
|
|
|
});
|
2017-08-04 11:51:35 -04:00
|
|
|
|
2017-08-11 12:36:59 -04:00
|
|
|
it('should render user information', () => {
|
2019-02-12 15:55:56 -05:00
|
|
|
const { author } = note;
|
|
|
|
const avatar = wrapper.find(UserAvatarLink);
|
|
|
|
const avatarProps = avatar.props();
|
|
|
|
|
|
|
|
expect(avatarProps.linkHref).toBe(author.path);
|
|
|
|
expect(avatarProps.imgSrc).toBe(author.avatar_url);
|
|
|
|
expect(avatarProps.imgAlt).toBe(author.name);
|
|
|
|
expect(avatarProps.imgSize).toBe(40);
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
|
|
|
|
2017-08-11 12:36:59 -04:00
|
|
|
it('should render note header content', () => {
|
2019-02-12 15:55:56 -05:00
|
|
|
const noteHeader = wrapper.find(NoteHeader);
|
|
|
|
const noteHeaderProps = noteHeader.props();
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2019-02-12 15:55:56 -05:00
|
|
|
expect(noteHeaderProps.author).toEqual(note.author);
|
|
|
|
expect(noteHeaderProps.createdAt).toEqual(note.created_at);
|
|
|
|
expect(noteHeaderProps.noteId).toEqual(note.id);
|
2017-08-11 12:36:59 -04:00
|
|
|
});
|
2017-08-04 11:51:35 -04:00
|
|
|
|
2017-08-11 12:36:59 -04:00
|
|
|
it('should render note actions', () => {
|
2019-02-12 15:55:56 -05:00
|
|
|
const { author } = note;
|
|
|
|
const noteActions = wrapper.find(NoteActions);
|
|
|
|
const noteActionsProps = noteActions.props();
|
|
|
|
|
|
|
|
expect(noteActionsProps.authorId).toBe(author.id);
|
|
|
|
expect(noteActionsProps.noteId).toBe(note.id);
|
|
|
|
expect(noteActionsProps.noteUrl).toBe(note.noteable_note_url);
|
|
|
|
expect(noteActionsProps.accessLevel).toBe(note.human_access);
|
|
|
|
expect(noteActionsProps.canEdit).toBe(note.current_user.can_edit);
|
|
|
|
expect(noteActionsProps.canAwardEmoji).toBe(note.current_user.can_award_emoji);
|
|
|
|
expect(noteActionsProps.canDelete).toBe(note.current_user.can_edit);
|
|
|
|
expect(noteActionsProps.canReportAsAbuse).toBe(true);
|
|
|
|
expect(noteActionsProps.canResolve).toBe(false);
|
|
|
|
expect(noteActionsProps.reportAbusePath).toBe(note.report_abuse_path);
|
|
|
|
expect(noteActionsProps.resolvable).toBe(false);
|
|
|
|
expect(noteActionsProps.isResolved).toBe(false);
|
|
|
|
expect(noteActionsProps.isResolving).toBe(false);
|
|
|
|
expect(noteActionsProps.resolvedBy).toEqual({});
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render issue body', () => {
|
2019-02-12 15:55:56 -05:00
|
|
|
const noteBody = wrapper.find(NoteBody);
|
|
|
|
const noteBodyProps = noteBody.props();
|
|
|
|
|
|
|
|
expect(noteBodyProps.note).toEqual(note);
|
|
|
|
expect(noteBodyProps.line).toBe(null);
|
|
|
|
expect(noteBodyProps.canEdit).toBe(note.current_user.can_edit);
|
|
|
|
expect(noteBodyProps.isEditing).toBe(false);
|
|
|
|
expect(noteBodyProps.helpPagePath).toBe('');
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
2017-12-06 15:10:32 -05:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
it('prevents note preview xss', done => {
|
2017-12-06 15:10:32 -05:00
|
|
|
const imgSrc = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';
|
|
|
|
const noteBody = `<img src="${imgSrc}" onload="alert(1)" />`;
|
|
|
|
const alertSpy = spyOn(window, 'alert');
|
2019-02-12 15:55:56 -05:00
|
|
|
store.hotUpdate({
|
|
|
|
actions: {
|
|
|
|
updateNote() {},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
const noteBodyComponent = wrapper.find(NoteBody);
|
2017-12-06 15:10:32 -05:00
|
|
|
|
2019-02-12 15:55:56 -05:00
|
|
|
noteBodyComponent.vm.$emit('handleFormUpdate', noteBody, null, () => {});
|
2017-12-06 15:10:32 -05:00
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(alertSpy).not.toHaveBeenCalled();
|
2019-02-12 15:55:56 -05:00
|
|
|
expect(wrapper.vm.note.note_html).toEqual(_.escape(noteBody));
|
2017-12-06 15:10:32 -05:00
|
|
|
done();
|
|
|
|
}, 0);
|
|
|
|
});
|
2018-02-07 16:45:53 -05:00
|
|
|
|
|
|
|
describe('cancel edit', () => {
|
2018-06-21 08:22:40 -04:00
|
|
|
it('restores content of updated note', done => {
|
2019-02-12 15:55:56 -05:00
|
|
|
const updatedText = 'updated note text';
|
|
|
|
store.hotUpdate({
|
|
|
|
actions: {
|
|
|
|
updateNote() {},
|
|
|
|
},
|
2018-02-07 16:45:53 -05:00
|
|
|
});
|
2019-02-12 15:55:56 -05:00
|
|
|
const noteBody = wrapper.find(NoteBody);
|
|
|
|
noteBody.vm.resetAutoSave = () => {};
|
|
|
|
|
|
|
|
noteBody.vm.$emit('handleFormUpdate', updatedText, null, () => {});
|
|
|
|
|
|
|
|
wrapper.vm
|
|
|
|
.$nextTick()
|
|
|
|
.then(() => {
|
|
|
|
const noteBodyProps = noteBody.props();
|
|
|
|
|
|
|
|
expect(noteBodyProps.note.note_html).toBe(updatedText);
|
|
|
|
noteBody.vm.$emit('cancelForm');
|
|
|
|
})
|
|
|
|
.then(() => wrapper.vm.$nextTick())
|
|
|
|
.then(() => {
|
|
|
|
const noteBodyProps = noteBody.props();
|
|
|
|
|
|
|
|
expect(noteBodyProps.note.note_html).toBe(note.note_html);
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
2018-02-07 16:45:53 -05:00
|
|
|
});
|
|
|
|
});
|
2017-08-09 15:13:00 -04:00
|
|
|
});
|