Skip to content
代码片段 群组 项目
未验证 提交 8266ca47 编辑于 作者: Artur Fedorov's avatar Artur Fedorov
浏览文件

This MR removes direct data manipulation

As part of Vue 3 migration
overriding method behavior and
direct data manipulation
should be avoided
上级 00939da2
No related branches found
No related tags found
无相关合并请求
import { GlDisclosureDropdown } from '@gitlab/ui'; import { GlDisclosureDropdown } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import Vue from 'vue'; import Vue from 'vue';
import VueApollo from 'vue-apollo'; import VueApollo from 'vue-apollo';
import createMockApollo from 'helpers/mock_apollo_helper'; import createMockApollo from 'helpers/mock_apollo_helper';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import { createMockDirective } from 'helpers/vue_mock_directive'; import { createMockDirective } from 'helpers/vue_mock_directive';
import { stubComponent } from 'helpers/stub_component';
import EmojiPicker from '~/emoji/components/picker.vue'; import EmojiPicker from '~/emoji/components/picker.vue';
import waitForPromises from 'helpers/wait_for_promises'; import waitForPromises from 'helpers/wait_for_promises';
import ReplyButton from '~/notes/components/note_actions/reply_button.vue'; import ReplyButton from '~/notes/components/note_actions/reply_button.vue';
...@@ -15,18 +16,19 @@ Vue.use(VueApollo); ...@@ -15,18 +16,19 @@ Vue.use(VueApollo);
describe('Work Item Note Actions', () => { describe('Work Item Note Actions', () => {
let wrapper; let wrapper;
const noteId = '1'; const noteId = '1';
const showSpy = jest.fn();
const findReplyButton = () => wrapper.findComponent(ReplyButton); const findReplyButton = () => wrapper.findComponent(ReplyButton);
const findEditButton = () => wrapper.find('[data-testid="edit-work-item-note"]'); const findEditButton = () => wrapper.findByTestId('edit-work-item-note');
const findEmojiButton = () => wrapper.find('[data-testid="note-emoji-button"]'); const findEmojiButton = () => wrapper.findByTestId('note-emoji-button');
const findDropdown = () => wrapper.findComponent(GlDisclosureDropdown); const findDropdown = () => wrapper.findComponent(GlDisclosureDropdown);
const findDeleteNoteButton = () => wrapper.find('[data-testid="delete-note-action"]'); const findDeleteNoteButton = () => wrapper.findByTestId('delete-note-action');
const findCopyLinkButton = () => wrapper.find('[data-testid="copy-link-action"]'); const findCopyLinkButton = () => wrapper.findByTestId('copy-link-action');
const findAssignUnassignButton = () => wrapper.find('[data-testid="assign-note-action"]'); const findAssignUnassignButton = () => wrapper.findByTestId('assign-note-action');
const findReportAbuseToAdminButton = () => wrapper.find('[data-testid="abuse-note-action"]'); const findReportAbuseToAdminButton = () => wrapper.findByTestId('abuse-note-action');
const findAuthorBadge = () => wrapper.find('[data-testid="author-badge"]'); const findAuthorBadge = () => wrapper.findByTestId('author-badge');
const findMaxAccessLevelBadge = () => wrapper.find('[data-testid="max-access-level-badge"]'); const findMaxAccessLevelBadge = () => wrapper.findByTestId('max-access-level-badge');
const findContributorBadge = () => wrapper.find('[data-testid="contributor-badge"]'); const findContributorBadge = () => wrapper.findByTestId('contributor-badge');
const addEmojiMutationResolver = jest.fn().mockResolvedValue({ const addEmojiMutationResolver = jest.fn().mockResolvedValue({
data: { data: {
...@@ -51,7 +53,7 @@ describe('Work Item Note Actions', () => { ...@@ -51,7 +53,7 @@ describe('Work Item Note Actions', () => {
maxAccessLevelOfAuthor = '', maxAccessLevelOfAuthor = '',
projectName = 'Project name', projectName = 'Project name',
} = {}) => { } = {}) => {
wrapper = shallowMount(WorkItemNoteActions, { wrapper = shallowMountExtended(WorkItemNoteActions, {
propsData: { propsData: {
showReply, showReply,
showEdit, showEdit,
...@@ -72,15 +74,21 @@ describe('Work Item Note Actions', () => { ...@@ -72,15 +74,21 @@ describe('Work Item Note Actions', () => {
}, },
stubs: { stubs: {
EmojiPicker: EmojiPickerStub, EmojiPicker: EmojiPickerStub,
GlDisclosureDropdown: stubComponent(GlDisclosureDropdown, {
methods: { close: showSpy },
}),
}, },
apolloProvider: createMockApollo([[addAwardEmojiMutation, addEmojiMutationResolver]]), apolloProvider: createMockApollo([[addAwardEmojiMutation, addEmojiMutationResolver]]),
directives: { directives: {
GlTooltip: createMockDirective('gl-tooltip'), GlTooltip: createMockDirective('gl-tooltip'),
}, },
}); });
wrapper.vm.$refs.dropdown.close = jest.fn();
}; };
afterEach(() => {
showSpy.mockClear();
});
describe('reply button', () => { describe('reply button', () => {
it('is visible by default', () => { it('is visible by default', () => {
createComponent(); createComponent();
...@@ -173,6 +181,7 @@ describe('Work Item Note Actions', () => { ...@@ -173,6 +181,7 @@ describe('Work Item Note Actions', () => {
findDeleteNoteButton().vm.$emit('action'); findDeleteNoteButton().vm.$emit('action');
expect(wrapper.emitted('deleteNote')).toEqual([[]]); expect(wrapper.emitted('deleteNote')).toEqual([[]]);
expect(showSpy).toHaveBeenCalled();
}); });
}); });
...@@ -188,6 +197,7 @@ describe('Work Item Note Actions', () => { ...@@ -188,6 +197,7 @@ describe('Work Item Note Actions', () => {
findCopyLinkButton().vm.$emit('action'); findCopyLinkButton().vm.$emit('action');
expect(wrapper.emitted('notifyCopyDone')).toEqual([[]]); expect(wrapper.emitted('notifyCopyDone')).toEqual([[]]);
expect(showSpy).toHaveBeenCalled();
}); });
}); });
...@@ -214,6 +224,7 @@ describe('Work Item Note Actions', () => { ...@@ -214,6 +224,7 @@ describe('Work Item Note Actions', () => {
findAssignUnassignButton().vm.$emit('action'); findAssignUnassignButton().vm.$emit('action');
expect(wrapper.emitted('assignUser')).toEqual([[]]); expect(wrapper.emitted('assignUser')).toEqual([[]]);
expect(showSpy).toHaveBeenCalled();
}); });
}); });
...@@ -240,6 +251,7 @@ describe('Work Item Note Actions', () => { ...@@ -240,6 +251,7 @@ describe('Work Item Note Actions', () => {
findReportAbuseToAdminButton().vm.$emit('action'); findReportAbuseToAdminButton().vm.$emit('action');
expect(wrapper.emitted('reportAbuse')).toEqual([[]]); expect(wrapper.emitted('reportAbuse')).toEqual([[]]);
expect(showSpy).toHaveBeenCalled();
}); });
}); });
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册