Commit 2ab083ab authored by Winnie Hellmann's avatar Winnie Hellmann

Revert "Convert noteable_note_spec.js to Vue test utils"

parent 3f3067fc
import $ from 'jquery';
import _ from 'underscore'; import _ from 'underscore';
import { shallowMount, createLocalVue } from '@vue/test-utils'; import Vue from 'vue';
import createStore from '~/notes/stores'; import createStore from '~/notes/stores';
import issueNote from '~/notes/components/noteable_note.vue'; import issueNote from '~/notes/components/noteable_note.vue';
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';
import { noteableDataMock, notesDataMock, note } from '../mock_data'; import { noteableDataMock, notesDataMock, note } from '../mock_data';
describe('issue_note', () => { describe('issue_note', () => {
let store; let store;
let wrapper; let vm;
beforeEach(() => { beforeEach(() => {
const Component = Vue.extend(issueNote);
store = createStore(); store = createStore();
store.dispatch('setNoteableData', noteableDataMock); store.dispatch('setNoteableData', noteableDataMock);
store.dispatch('setNotesData', notesDataMock); store.dispatch('setNotesData', notesDataMock);
const localVue = createLocalVue(); vm = new Component({
wrapper = shallowMount(issueNote, {
store, store,
propsData: { propsData: {
note, note,
}, },
sync: false, }).$mount();
localVue,
});
}); });
afterEach(() => { afterEach(() => {
wrapper.destroy(); vm.$destroy();
}); });
it('should render user information', () => { it('should render user information', () => {
const { author } = note; expect(vm.$el.querySelector('.user-avatar-link img').getAttribute('src')).toEqual(
const avatar = wrapper.find(UserAvatarLink); note.author.avatar_url,
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);
}); });
it('should render note header content', () => { it('should render note header content', () => {
const noteHeader = wrapper.find(NoteHeader); const el = vm.$el.querySelector('.note-header .note-header-author-name');
const noteHeaderProps = noteHeader.props();
expect(noteHeaderProps.author).toEqual(note.author); expect(el.textContent.trim()).toEqual(note.author.name);
expect(noteHeaderProps.createdAt).toEqual(note.created_at);
expect(noteHeaderProps.noteId).toEqual(note.id);
}); });
it('should render note actions', () => { it('should render note actions', () => {
const { author } = note; expect(vm.$el.querySelector('.note-actions')).toBeDefined();
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({});
}); });
it('should render issue body', () => { it('should render issue body', () => {
const noteBody = wrapper.find(NoteBody); expect(vm.$el.querySelector('.note-text').innerHTML).toEqual(note.note_html);
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('');
}); });
it('prevents note preview xss', done => { it('prevents note preview xss', done => {
const imgSrc = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'; const imgSrc = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';
const noteBody = `<img src="${imgSrc}" onload="alert(1)" />`; const noteBody = `<img src="${imgSrc}" onload="alert(1)" />`;
const alertSpy = spyOn(window, 'alert'); const alertSpy = spyOn(window, 'alert');
store.hotUpdate({ vm.updateNote = () => new Promise($.noop);
actions: {
updateNote() {},
},
});
const noteBodyComponent = wrapper.find(NoteBody);
noteBodyComponent.vm.$emit('handleFormUpdate', noteBody, null, () => {}); vm.formUpdateHandler(noteBody, null, $.noop);
setTimeout(() => { setTimeout(() => {
expect(alertSpy).not.toHaveBeenCalled(); expect(alertSpy).not.toHaveBeenCalled();
expect(wrapper.vm.note.note_html).toEqual(_.escape(noteBody)); expect(vm.note.note_html).toEqual(_.escape(noteBody));
done(); done();
}, 0); }, 0);
}); });
...@@ -107,23 +66,17 @@ describe('issue_note', () => { ...@@ -107,23 +66,17 @@ describe('issue_note', () => {
describe('cancel edit', () => { describe('cancel edit', () => {
it('restores content of updated note', done => { it('restores content of updated note', done => {
const noteBody = 'updated note text'; const noteBody = 'updated note text';
store.hotUpdate({ vm.updateNote = () => Promise.resolve();
actions: {
updateNote() {},
},
});
const noteBodyComponent = wrapper.find(NoteBody);
noteBodyComponent.vm.resetAutoSave = () => {};
noteBodyComponent.vm.$emit('handleFormUpdate', noteBody, null, () => {}); vm.formUpdateHandler(noteBody, null, $.noop);
setTimeout(() => { setTimeout(() => {
expect(wrapper.vm.note.note_html).toEqual(noteBody); expect(vm.note.note_html).toEqual(noteBody);
noteBodyComponent.vm.$emit('cancelForm'); vm.formCancelHandler();
setTimeout(() => { setTimeout(() => {
expect(wrapper.vm.note.note_html).toEqual(noteBody); expect(vm.note.note_html).toEqual(noteBody);
done(); done();
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment