debian-mirror-gitlab/spec/frontend/batch_comments/components/submit_dropdown_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

120 lines
3.4 KiB
JavaScript
Raw Normal View History

2023-07-09 08:55:56 +05:30
import { GlDropdown } from '@gitlab/ui';
2022-07-23 23:45:48 +05:30
import Vue from 'vue';
import Vuex from 'vuex';
import { mountExtended } from 'helpers/vue_test_utils_helper';
import SubmitDropdown from '~/batch_comments/components/submit_dropdown.vue';
2023-03-17 16:20:25 +05:30
jest.mock('~/autosave');
2022-07-23 23:45:48 +05:30
Vue.use(Vuex);
let wrapper;
let publishReview;
2023-07-09 08:55:56 +05:30
function factory({ canApprove = true, shouldAnimateReviewButton = false } = {}) {
2022-07-23 23:45:48 +05:30
publishReview = jest.fn();
const store = new Vuex.Store({
getters: {
getNotesData: () => ({
markdownDocsPath: '/markdown/docs',
quickActionsDocsPath: '/quickactions/docs',
}),
2022-10-11 01:57:18 +05:30
getNoteableData: () => ({
id: 1,
preview_note_path: '/preview',
current_user: { can_approve: canApprove },
}),
2022-07-23 23:45:48 +05:30
noteableType: () => 'merge_request',
2022-10-11 01:57:18 +05:30
getCurrentUserLastNote: () => ({ id: 1 }),
2022-07-23 23:45:48 +05:30
},
modules: {
batchComments: {
namespaced: true,
2023-07-09 08:55:56 +05:30
state: { shouldAnimateReviewButton },
2022-07-23 23:45:48 +05:30
actions: {
publishReview,
},
},
},
});
wrapper = mountExtended(SubmitDropdown, {
store,
});
}
const findCommentTextarea = () => wrapper.findByTestId('comment-textarea');
const findSubmitButton = () => wrapper.findByTestId('submit-review-button');
const findForm = () => wrapper.findByTestId('submit-gl-form');
2023-07-09 08:55:56 +05:30
const findSubmitDropdown = () => wrapper.findComponent(GlDropdown);
2022-07-23 23:45:48 +05:30
describe('Batch comments submit dropdown', () => {
afterEach(() => {
2022-10-11 01:57:18 +05:30
window.mrTabs = null;
2022-07-23 23:45:48 +05:30
});
it('calls publishReview with note data', async () => {
factory();
findCommentTextarea().setValue('Hello world');
await findForm().vm.$emit('submit', { preventDefault: jest.fn() });
expect(publishReview).toHaveBeenCalledWith(expect.anything(), {
noteable_type: 'merge_request',
noteable_id: 1,
note: 'Hello world',
2022-10-11 01:57:18 +05:30
approve: false,
approval_password: '',
2022-07-23 23:45:48 +05:30
});
});
2022-10-11 01:57:18 +05:30
it('switches to the overview tab after submit', async () => {
window.mrTabs = { tabShown: jest.fn() };
factory();
findCommentTextarea().setValue('Hello world');
await findForm().vm.$emit('submit', { preventDefault: jest.fn() });
await Vue.nextTick();
expect(window.mrTabs.tabShown).toHaveBeenCalledWith('show');
});
2022-07-23 23:45:48 +05:30
it('sets submit dropdown to loading', async () => {
factory();
findCommentTextarea().setValue('Hello world');
await findForm().vm.$emit('submit', { preventDefault: jest.fn() });
expect(findSubmitButton().props('loading')).toBe(true);
});
2022-10-11 01:57:18 +05:30
it.each`
canApprove | exists | existsText
${true} | ${true} | ${'shows'}
${false} | ${false} | ${'hides'}
`('$existsText approve checkbox if can_approve is $canApprove', ({ canApprove, exists }) => {
factory({ canApprove });
expect(wrapper.findByTestId('approve_merge_request').exists()).toBe(exists);
});
2023-07-09 08:55:56 +05:30
it.each`
shouldAnimateReviewButton | animationClassApplied | classText
${true} | ${true} | ${'applies'}
${false} | ${false} | ${'does not apply'}
`(
'$classText animation class to `Finish review` button if `shouldAnimateReviewButton` is $shouldAnimateReviewButton',
({ shouldAnimateReviewButton, animationClassApplied }) => {
factory({ shouldAnimateReviewButton });
expect(findSubmitDropdown().classes('submit-review-dropdown-animated')).toBe(
animationClassApplied,
);
},
);
2022-07-23 23:45:48 +05:30
});