2021-03-11 19:13:27 +05:30
|
|
|
import { GlDropdownItem } from '@gitlab/ui';
|
|
|
|
import { shallowMount } from '@vue/test-utils';
|
|
|
|
import { kebabCase } from 'lodash';
|
|
|
|
import { nextTick } from 'vue';
|
|
|
|
import Actions from '~/admin/users/components/actions';
|
|
|
|
import SharedDeleteAction from '~/admin/users/components/actions/shared/shared_delete_action.vue';
|
|
|
|
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;
|
|
|
|
|
|
|
|
const findDropdownItem = () => wrapper.find(GlDropdownItem);
|
|
|
|
|
|
|
|
const initComponent = ({ component, props, stubs = {} } = {}) => {
|
|
|
|
wrapper = shallowMount(component, {
|
|
|
|
propsData: {
|
|
|
|
...props,
|
|
|
|
},
|
|
|
|
stubs,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('CONFIRMATION_ACTIONS', () => {
|
|
|
|
it.each(CONFIRMATION_ACTIONS)('renders a dropdown item for "%s"', async (action) => {
|
|
|
|
initComponent({
|
|
|
|
component: Actions[capitalizeFirstCharacter(action)],
|
|
|
|
props: {
|
|
|
|
username: 'John Doe',
|
|
|
|
path: '/test',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
await nextTick();
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
expect(wrapper.attributes('data-path')).toBe('/test');
|
|
|
|
expect(wrapper.attributes('data-modal-attributes')).toContain('John Doe');
|
2021-03-11 19:13:27 +05:30
|
|
|
expect(findDropdownItem().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('DELETE_ACTION_COMPONENTS', () => {
|
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
|
|
|
|
|
|
|
it.each(DELETE_ACTIONS.map((action) => [action, paths[action]]))(
|
|
|
|
'renders a dropdown item for "%s"',
|
|
|
|
async (action, expectedPath) => {
|
|
|
|
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
|
|
|
stubs: { SharedDeleteAction },
|
|
|
|
});
|
2021-03-11 19:13:27 +05:30
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
await nextTick();
|
2021-03-11 19:13:27 +05:30
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
const sharedAction = wrapper.find(SharedDeleteAction);
|
2021-03-11 19:13:27 +05:30
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
expect(sharedAction.attributes('data-block-user-url')).toBe(paths.block);
|
|
|
|
expect(sharedAction.attributes('data-delete-user-url')).toBe(expectedPath);
|
|
|
|
expect(sharedAction.attributes('data-gl-modal-action')).toBe(kebabCase(action));
|
|
|
|
expect(sharedAction.attributes('data-username')).toBe('John Doe');
|
2021-11-18 22:05:49 +05:30
|
|
|
expect(sharedAction.attributes('data-user-deletion-obstacles')).toBe(
|
|
|
|
JSON.stringify(userDeletionObstacles),
|
2021-10-27 15:23:28 +05:30
|
|
|
);
|
|
|
|
expect(findDropdownItem().exists()).toBe(true);
|
|
|
|
},
|
|
|
|
);
|
2021-03-11 19:13:27 +05:30
|
|
|
});
|
|
|
|
});
|