Skip to content

Commit

Permalink
Simplify deleting spaces (#99960) (#100258)
Browse files Browse the repository at this point in the history
* Simplify deleting spaces

* Fixed i18n

* Fix functional tests

* Update x-pack/plugins/spaces/public/management/spaces_management_app.tsx

Co-authored-by: Larry Gregory <[email protected]>

* Fix snapshots

Co-authored-by: Larry Gregory <[email protected]>
Co-authored-by: Kibana Machine <[email protected]>
# Conflicts:
#	x-pack/plugins/spaces/public/management/spaces_management_app.tsx
  • Loading branch information
thomheymann authored May 18, 2021
1 parent 60ef805 commit d033f41
Show file tree
Hide file tree
Showing 13 changed files with 201 additions and 469 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.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

0 comments on commit d033f41

Please sign in to comment.