diff options
author | Winnie Hellmann <winnie@gitlab.com> | 2019-03-23 17:52:35 +0100 |
---|---|---|
committer | Winnie Hellmann <winnie@gitlab.com> | 2019-03-23 17:53:46 +0100 |
commit | 514ee63826e47229bfd03bdbb740f2dd1eae1d03 (patch) | |
tree | 3f0d96a4402e8aa54c375084cc4c5e6cf546824b /spec/frontend/notes | |
parent | 6d330015dfdb1979a0773c87c53b84cc86b28a6d (diff) | |
download | gitlab-ce-514ee63826e47229bfd03bdbb740f2dd1eae1d03.tar.gz |
Move some tests from Karma to Jest
Diffstat (limited to 'spec/frontend/notes')
4 files changed, 178 insertions, 0 deletions
diff --git a/spec/frontend/notes/components/discussion_reply_placeholder_spec.js b/spec/frontend/notes/components/discussion_reply_placeholder_spec.js new file mode 100644 index 00000000000..07a366cf339 --- /dev/null +++ b/spec/frontend/notes/components/discussion_reply_placeholder_spec.js @@ -0,0 +1,34 @@ +import ReplyPlaceholder from '~/notes/components/discussion_reply_placeholder.vue'; +import { shallowMount, createLocalVue } from '@vue/test-utils'; + +const localVue = createLocalVue(); + +describe('ReplyPlaceholder', () => { + let wrapper; + + beforeEach(() => { + wrapper = shallowMount(ReplyPlaceholder, { + localVue, + }); + }); + + afterEach(() => { + wrapper.destroy(); + }); + + it('emits onClick even on button click', () => { + const button = wrapper.find({ ref: 'button' }); + + button.trigger('click'); + + expect(wrapper.emitted()).toEqual({ + onClick: [[]], + }); + }); + + it('should render reply button', () => { + const button = wrapper.find({ ref: 'button' }); + + expect(button.text()).toEqual('Reply...'); + }); +}); diff --git a/spec/frontend/notes/components/discussion_resolve_button_spec.js b/spec/frontend/notes/components/discussion_resolve_button_spec.js new file mode 100644 index 00000000000..5024f40ec5d --- /dev/null +++ b/spec/frontend/notes/components/discussion_resolve_button_spec.js @@ -0,0 +1,74 @@ +import resolveDiscussionButton from '~/notes/components/discussion_resolve_button.vue'; +import { createLocalVue, shallowMount } from '@vue/test-utils'; + +const buttonTitle = 'Resolve discussion'; + +describe('resolveDiscussionButton', () => { + let wrapper; + let localVue; + + const factory = options => { + localVue = createLocalVue(); + wrapper = shallowMount(resolveDiscussionButton, { + localVue, + ...options, + }); + }; + + beforeEach(() => { + factory({ + propsData: { + isResolving: false, + buttonTitle, + }, + }); + }); + + afterEach(() => { + wrapper.destroy(); + }); + + it('should emit a onClick event on button click', () => { + const button = wrapper.find({ ref: 'button' }); + + button.trigger('click'); + + expect(wrapper.emitted()).toEqual({ + onClick: [[]], + }); + }); + + it('should contain the provided button title', () => { + const button = wrapper.find({ ref: 'button' }); + + expect(button.text()).toContain(buttonTitle); + }); + + it('should show a loading spinner while resolving', () => { + factory({ + propsData: { + isResolving: true, + buttonTitle, + }, + }); + + const button = wrapper.find({ ref: 'isResolvingIcon' }); + + expect(button.exists()).toEqual(true); + }); + + it('should only show a loading spinner while resolving', () => { + factory({ + propsData: { + isResolving: false, + buttonTitle, + }, + }); + + const button = wrapper.find({ ref: 'isResolvingIcon' }); + + localVue.nextTick(() => { + expect(button.exists()).toEqual(false); + }); + }); +}); diff --git a/spec/frontend/notes/components/note_attachment_spec.js b/spec/frontend/notes/components/note_attachment_spec.js new file mode 100644 index 00000000000..b14a518b622 --- /dev/null +++ b/spec/frontend/notes/components/note_attachment_spec.js @@ -0,0 +1,23 @@ +import Vue from 'vue'; +import noteAttachment from '~/notes/components/note_attachment.vue'; + +describe('issue note attachment', () => { + it('should render properly', () => { + const props = { + attachment: { + filename: 'dk.png', + image: true, + url: '/dk.png', + }, + }; + + const Component = Vue.extend(noteAttachment); + const vm = new Component({ + propsData: props, + }).$mount(); + + expect(vm.$el.classList.contains('note-attachment')).toBeTruthy(); + expect(vm.$el.querySelector('img').src).toContain(props.attachment.url); + expect(vm.$el.querySelector('a').href).toContain(props.attachment.url); + }); +}); diff --git a/spec/frontend/notes/components/note_edited_text_spec.js b/spec/frontend/notes/components/note_edited_text_spec.js new file mode 100644 index 00000000000..e4c8d954d50 --- /dev/null +++ b/spec/frontend/notes/components/note_edited_text_spec.js @@ -0,0 +1,47 @@ +import Vue from 'vue'; +import noteEditedText from '~/notes/components/note_edited_text.vue'; + +describe('note_edited_text', () => { + let vm; + let props; + + beforeEach(() => { + const Component = Vue.extend(noteEditedText); + props = { + actionText: 'Edited', + className: 'foo-bar', + editedAt: '2017-08-04T09:52:31.062Z', + editedBy: { + avatar_url: 'path', + id: 1, + name: 'Root', + path: '/root', + state: 'active', + username: 'root', + }, + }; + + vm = new Component({ + propsData: props, + }).$mount(); + }); + + afterEach(() => { + vm.$destroy(); + }); + + it('should render block with provided className', () => { + expect(vm.$el.className).toEqual(props.className); + }); + + it('should render provided actionText', () => { + expect(vm.$el.textContent).toContain(props.actionText); + }); + + it('should render provided user information', () => { + const authorLink = vm.$el.querySelector('.js-user-link'); + + expect(authorLink.getAttribute('href')).toEqual(props.editedBy.path); + expect(authorLink.textContent.trim()).toEqual(props.editedBy.name); + }); +}); |