2018-03-09 15:18:59 -05:00
|
|
|
import $ from 'jquery';
|
2017-12-19 05:12:32 -05:00
|
|
|
import _ from 'underscore';
|
2017-08-11 12:36:59 -04:00
|
|
|
import Vue from 'vue';
|
|
|
|
import store from '~/notes/stores';
|
2017-12-08 15:24:52 -05:00
|
|
|
import issueNote from '~/notes/components/noteable_note.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', () => {
|
2017-08-11 12:36:59 -04:00
|
|
|
let vm;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
const Component = Vue.extend(issueNote);
|
2017-08-04 11:51:35 -04:00
|
|
|
|
2017-11-30 17:44:41 -05:00
|
|
|
store.dispatch('setNoteableData', noteableDataMock);
|
2017-08-11 12:36:59 -04:00
|
|
|
store.dispatch('setNotesData', notesDataMock);
|
|
|
|
|
|
|
|
vm = new Component({
|
|
|
|
store,
|
|
|
|
propsData: {
|
|
|
|
note,
|
|
|
|
},
|
|
|
|
}).$mount();
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
|
|
|
|
2017-08-11 12:36:59 -04:00
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
|
|
|
});
|
2017-08-04 11:51:35 -04:00
|
|
|
|
2017-08-11 12:36:59 -04:00
|
|
|
it('should render user information', () => {
|
|
|
|
expect(vm.$el.querySelector('.user-avatar-link img').getAttribute('src')).toEqual(note.author.avatar_url);
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
|
|
|
|
2017-08-11 12:36:59 -04:00
|
|
|
it('should render note header content', () => {
|
|
|
|
expect(vm.$el.querySelector('.note-header .note-header-author-name').textContent.trim()).toEqual(note.author.name);
|
|
|
|
});
|
2017-08-04 11:51:35 -04:00
|
|
|
|
2017-08-11 12:36:59 -04:00
|
|
|
it('should render note actions', () => {
|
|
|
|
expect(vm.$el.querySelector('.note-actions')).toBeDefined();
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render issue body', () => {
|
2017-08-11 12:36:59 -04:00
|
|
|
expect(vm.$el.querySelector('.note-text').innerHTML).toEqual(note.note_html);
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
2017-12-06 15:10:32 -05:00
|
|
|
|
|
|
|
it('prevents note preview xss', (done) => {
|
|
|
|
const imgSrc = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';
|
|
|
|
const noteBody = `<img src="${imgSrc}" onload="alert(1)" />`;
|
|
|
|
const alertSpy = spyOn(window, 'alert');
|
|
|
|
vm.updateNote = () => new Promise($.noop);
|
|
|
|
|
|
|
|
vm.formUpdateHandler(noteBody, null, $.noop);
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(alertSpy).not.toHaveBeenCalled();
|
|
|
|
expect(vm.note.note_html).toEqual(_.escape(noteBody));
|
|
|
|
done();
|
|
|
|
}, 0);
|
|
|
|
});
|
2018-02-07 16:45:53 -05:00
|
|
|
|
|
|
|
describe('cancel edit', () => {
|
|
|
|
it('restores content of updated note', (done) => {
|
|
|
|
const noteBody = 'updated note text';
|
|
|
|
vm.updateNote = () => Promise.resolve();
|
|
|
|
|
|
|
|
vm.formUpdateHandler(noteBody, null, $.noop);
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(vm.note.note_html).toEqual(noteBody);
|
|
|
|
|
|
|
|
vm.formCancelHandler();
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(vm.note.note_html).toEqual(noteBody);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-08-09 15:13:00 -04:00
|
|
|
});
|