mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
Fix Jest warnings for ConfirmModal. (#14892)
This commit is contained in:
parent
30238e8744
commit
3bde84393c
1 changed files with 48 additions and 24 deletions
|
@ -34,10 +34,14 @@ test('renders KuiConfirmModal', () => {
|
|||
});
|
||||
|
||||
test('onConfirm', () => {
|
||||
const component = mount(<KuiConfirmModal
|
||||
onCancel={onCancel}
|
||||
onConfirm={onConfirm}
|
||||
/>);
|
||||
const component = mount(
|
||||
<KuiConfirmModal
|
||||
onCancel={onCancel}
|
||||
onConfirm={onConfirm}
|
||||
cancelButtonText="Cancel Button Text"
|
||||
confirmButtonText="Confirm Button Text"
|
||||
/>
|
||||
);
|
||||
component.find('[data-test-subj="confirmModalConfirmButton"]').simulate('click');
|
||||
sinon.assert.calledOnce(onConfirm);
|
||||
sinon.assert.notCalled(onCancel);
|
||||
|
@ -45,21 +49,29 @@ test('onConfirm', () => {
|
|||
|
||||
describe('onCancel', () => {
|
||||
test('triggerd by click', () => {
|
||||
const component = mount(<KuiConfirmModal
|
||||
onCancel={onCancel}
|
||||
onConfirm={onConfirm}
|
||||
/>);
|
||||
const component = mount(
|
||||
<KuiConfirmModal
|
||||
onCancel={onCancel}
|
||||
onConfirm={onConfirm}
|
||||
cancelButtonText="Cancel Button Text"
|
||||
confirmButtonText="Confirm Button Text"
|
||||
/>
|
||||
);
|
||||
component.find('[data-test-subj="confirmModalCancelButton"]').simulate('click');
|
||||
sinon.assert.notCalled(onConfirm);
|
||||
sinon.assert.calledOnce(onCancel);
|
||||
});
|
||||
|
||||
test('triggered by esc key', () => {
|
||||
const component = mount(<KuiConfirmModal
|
||||
onCancel={onCancel}
|
||||
onConfirm={onConfirm}
|
||||
data-test-subj="modal"
|
||||
/>);
|
||||
const component = mount(
|
||||
<KuiConfirmModal
|
||||
onCancel={onCancel}
|
||||
onConfirm={onConfirm}
|
||||
cancelButtonText="Cancel Button Text"
|
||||
confirmButtonText="Confirm Button Text"
|
||||
data-test-subj="modal"
|
||||
/>
|
||||
);
|
||||
component.find('[data-test-subj="modal"]').simulate('keydown', { keyCode: keyCodes.ESCAPE });
|
||||
sinon.assert.notCalled(onConfirm);
|
||||
sinon.assert.calledOnce(onCancel);
|
||||
|
@ -68,27 +80,39 @@ describe('onCancel', () => {
|
|||
|
||||
describe('defaultFocusedButton', () => {
|
||||
test('is cancel', () => {
|
||||
const component = mount(<KuiConfirmModal
|
||||
onCancel={onCancel}
|
||||
defaultFocusedButton={CANCEL_BUTTON}
|
||||
/>);
|
||||
const component = mount(
|
||||
<KuiConfirmModal
|
||||
onCancel={onCancel}
|
||||
defaultFocusedButton={CANCEL_BUTTON}
|
||||
cancelButtonText="Cancel Button Text"
|
||||
confirmButtonText="Confirm Button Text"
|
||||
/>
|
||||
);
|
||||
const button = component.find('[data-test-subj="confirmModalCancelButton"]').getDOMNode();
|
||||
expect(document.activeElement).toEqual(button);
|
||||
});
|
||||
|
||||
test('is confirm', () => {
|
||||
const component = mount(<KuiConfirmModal
|
||||
onCancel={onCancel}
|
||||
defaultFocusedButton={CONFIRM_BUTTON}
|
||||
/>);
|
||||
const component = mount(
|
||||
<KuiConfirmModal
|
||||
onCancel={onCancel}
|
||||
defaultFocusedButton={CONFIRM_BUTTON}
|
||||
cancelButtonText="Cancel Button Text"
|
||||
confirmButtonText="Confirm Button Text"
|
||||
/>
|
||||
);
|
||||
const button = component.find('[data-test-subj="confirmModalConfirmButton"]').getDOMNode();
|
||||
expect(document.activeElement).toEqual(button);
|
||||
});
|
||||
|
||||
test('when not given gives focus to the modal', () => {
|
||||
const component = mount(<KuiConfirmModal
|
||||
onCancel={onCancel}
|
||||
/>);
|
||||
const component = mount(
|
||||
<KuiConfirmModal
|
||||
onCancel={onCancel}
|
||||
cancelButtonText="Cancel Button Text"
|
||||
confirmButtonText="Confirm Button Text"
|
||||
/>
|
||||
);
|
||||
expect(document.activeElement).toEqual(component.getDOMNode().firstChild);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue