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.

81 lines
2.3 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';
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';
2021-11-18 22:05:49 +05:30
import { OBSTACLE_TYPES } from '~/vue_shared/components/user_deletion_obstacles/constants';
2021-03-11 19:13:27 +05:30
import { CONFIRMATION_ACTIONS, DELETE_ACTIONS } from '../../constants';
2021-10-27 15:23:28 +05:30
import { paths } 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);
});
});
describe('DELETE_ACTION_COMPONENTS', () => {
2022-06-21 17:19:12 +05:30
beforeEach(() => {
jest.spyOn(eventHub, '$emit').mockImplementation();
});
2021-11-18 22:05:49 +05:30
const userDeletionObstacles = [
{ name: 'schedule1', type: OBSTACLE_TYPES.oncallSchedules },
{ name: 'policy1', type: OBSTACLE_TYPES.escalationPolicies },
];
2021-10-27 15:23:28 +05:30
2022-06-21 17:19:12 +05:30
it.each(DELETE_ACTIONS)(
'renders a dropdown item that opens the delete user modal when clicked for "%s"',
async (action) => {
2021-10-27 15:23:28 +05:30
initComponent({
component: Actions[capitalizeFirstCharacter(action)],
props: {
username: 'John Doe',
paths,
2021-11-18 22:05:49 +05:30
userDeletionObstacles,
2021-03-11 19:13:27 +05:30
},
2021-10-27 15:23:28 +05:30
});
2021-03-11 19:13:27 +05:30
2022-06-21 17:19:12 +05:30
await findDropdownItem().vm.$emit('click');
2021-03-11 19:13:27 +05:30
2022-06-21 17:19:12 +05:30
expect(eventHub.$emit).toHaveBeenCalledWith(
EVENT_OPEN_DELETE_USER_MODAL,
expect.objectContaining({
username: 'John Doe',
blockPath: paths.block,
deletePath: paths[action],
userDeletionObstacles,
}),
2021-10-27 15:23:28 +05:30
);
},
);
2021-03-11 19:13:27 +05:30
});
});