Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify deleting spaces #99960

Merged
merged 7 commits into from
May 18, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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.spaces.management.confirmDeleteModal.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