debian-mirror-gitlab/spec/frontend/admin/users/components/actions/actions_spec.js

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

74 lines
2 KiB
JavaScript
Raw Normal View History

2021-03-11 19:13:27 +05:30
import { GlDropdownItem } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import Actions from '~/admin/users/components/actions';
2023-01-13 00:05:48 +05:30
import Delete from '~/admin/users/components/actions/delete.vue';
2022-06-21 17:19:12 +05:30
import eventHub, {
EVENT_OPEN_DELETE_USER_MODAL,
} from '~/admin/users/components/modals/delete_user_modal_event_hub';
2021-03-11 19:13:27 +05:30
import { capitalizeFirstCharacter } from '~/lib/utils/text_utility';
2023-01-13 00:05:48 +05:30
import { CONFIRMATION_ACTIONS } from '../../constants';
import { paths, userDeletionObstacles } from '../../mock_data';
2021-03-11 19:13:27 +05:30
describe('Action components', () => {
let wrapper;
2022-08-27 11:52:29 +05:30
const findDropdownItem = () => wrapper.findComponent(GlDropdownItem);
2021-03-11 19:13:27 +05:30
2022-06-21 17:19:12 +05:30
const initComponent = ({ component, props } = {}) => {
2021-03-11 19:13:27 +05:30
wrapper = shallowMount(component, {
propsData: {
...props,
},
});
};
afterEach(() => {
wrapper.destroy();
wrapper = null;
});
describe('CONFIRMATION_ACTIONS', () => {
2022-06-21 17:19:12 +05:30
it.each(CONFIRMATION_ACTIONS)('renders a dropdown item for "%s"', (action) => {
2021-03-11 19:13:27 +05:30
initComponent({
component: Actions[capitalizeFirstCharacter(action)],
props: {
username: 'John Doe',
path: '/test',
},
});
expect(findDropdownItem().exists()).toBe(true);
});
});
2023-01-13 00:05:48 +05:30
describe('DELETE', () => {
2022-06-21 17:19:12 +05:30
beforeEach(() => {
jest.spyOn(eventHub, '$emit').mockImplementation();
});
2023-01-13 00:05:48 +05:30
it('renders a dropdown item that opens the delete user modal when Delete is clicked', async () => {
initComponent({
component: Delete,
props: {
username: 'John Doe',
userId: 1,
paths,
userDeletionObstacles,
},
});
2021-03-11 19:13:27 +05:30
2023-01-13 00:05:48 +05:30
await findDropdownItem().vm.$emit('click');
2021-03-11 19:13:27 +05:30
2023-01-13 00:05:48 +05:30
expect(eventHub.$emit).toHaveBeenCalledWith(
EVENT_OPEN_DELETE_USER_MODAL,
expect.objectContaining({
username: 'John Doe',
blockPath: paths.block,
deletePath: paths.delete,
userDeletionObstacles,
}),
);
});
2021-03-11 19:13:27 +05:30
});
});