Skip to content

Commit

Permalink
Simplify deleting spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
thomheymann committed May 12, 2021
1 parent dffa143 commit 757db8d
Show file tree
Hide file tree
Showing 10 changed files with 204 additions and 439 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
*/

import React from 'react';
import { act } from 'react-dom/test-utils';

import { mountWithIntl, shallowWithIntl } from '@kbn/test/jest';

import type { SpacesManager } from '../../../spaces_manager';
import { spacesManagerMock } from '../../../spaces_manager/mocks';
import { ConfirmDeleteModal } from './confirm_delete_modal';

Expand All @@ -22,60 +22,77 @@ describe('ConfirmDeleteModal', () => {
};

const spacesManager = spacesManagerMock.create();
spacesManager.getActiveSpace.mockResolvedValue(space);

const onCancel = jest.fn();
const onConfirm = jest.fn();

expect(
shallowWithIntl(
<ConfirmDeleteModal.WrappedComponent
space={space}
spacesManager={(spacesManager as unknown) as SpacesManager}
onCancel={onCancel}
onConfirm={onConfirm}
intl={null as any}
/>
<ConfirmDeleteModal space={space} spacesManager={spacesManager} onCancel={onCancel} />
)
).toMatchSnapshot();
).toMatchInlineSnapshot(`
<EuiConfirmModal
buttonColor="danger"
cancelButtonText="Cancel"
confirmButtonText="Delete space and all contents"
isLoading={false}
onCancel={[MockFunction]}
onConfirm={[Function]}
title="Delete space 'My Space'?"
>
<EuiText>
<p>
<FormattedMessage
defaultMessage="This space and {allContents} will be permanently deleted."
id="xpack.spaces.management.confirmDeleteModal.description"
values={
Object {
"allContents": <strong>
<FormattedMessage
defaultMessage="all contents"
id="xpack.spaces.management.confirmDeleteModal.allContents"
values={Object {}}
/>
</strong>,
}
}
/>
</p>
<p>
<FormattedMessage
defaultMessage="You can't recover deleted spaces."
id="xpack.security.management.users.confirmDelete.cannotUndoWarning"
values={Object {}}
/>
</p>
</EuiText>
</EuiConfirmModal>
`);
});

it(`requires the space name to be typed before confirming`, () => {
it('deletes the space when confirmed', async () => {
const space = {
id: 'my-space',
name: 'My Space',
disabledFeatures: [],
};

const spacesManager = spacesManagerMock.create();
spacesManager.getActiveSpace.mockResolvedValue(space);

const onCancel = jest.fn();
const onConfirm = jest.fn();
const onSuccess = jest.fn();

const wrapper = mountWithIntl(
<ConfirmDeleteModal.WrappedComponent
<ConfirmDeleteModal
space={space}
spacesManager={(spacesManager as unknown) as SpacesManager}
spacesManager={spacesManager}
onCancel={onCancel}
onConfirm={onConfirm}
intl={null as any}
onSuccess={onSuccess}
/>
);

const input = wrapper.find('input');
expect(input).toHaveLength(1);

input.simulate('change', { target: { value: 'My Invalid Space Name ' } });

const confirmButton = wrapper.find('button[data-test-subj="confirmModalConfirmButton"]');
confirmButton.simulate('click');

expect(onConfirm).not.toHaveBeenCalled();

input.simulate('change', { target: { value: 'My Space' } });
confirmButton.simulate('click');
await act(async () => {
wrapper.find('EuiButton[data-test-subj="confirmModalConfirmButton"]').simulate('click');
await spacesManager.deleteSpace.mock.results[0];
});

expect(onConfirm).toHaveBeenCalledTimes(1);
expect(spacesManager.deleteSpace).toHaveBeenLastCalledWith(space);
});
});
Loading

0 comments on commit 757db8d

Please sign in to comment.