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.

102 lines
2.6 KiB
JavaScript
Raw Normal View History

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;
2022-10-11 01:57:18 +05:30
function factory({ canApprove = true } = {}) {
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,
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');
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);
});
2022-07-23 23:45:48 +05:30
});