debian-mirror-gitlab/spec/javascripts/notes/components/noteable_note_spec.js

87 lines
2.2 KiB
JavaScript
Raw Normal View History

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