2021-02-04 19:15:23 +01:00
|
|
|
import React from 'react';
|
|
|
|
import sinon from 'sinon';
|
|
|
|
import { mount } from 'enzyme';
|
2021-03-16 22:00:08 +01:00
|
|
|
import ConfirmDeleteNetwork from './confirm-delete-network.container';
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('Confirm Delete Network', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
let wrapper;
|
2020-01-30 20:34:45 +01:00
|
|
|
|
|
|
|
const props = {
|
|
|
|
hideModal: sinon.spy(),
|
|
|
|
delRpcTarget: sinon.stub().resolves(),
|
|
|
|
onConfirm: sinon.spy(),
|
|
|
|
target: '',
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
beforeEach(() => {
|
2020-11-03 00:41:28 +01:00
|
|
|
wrapper = mount(<ConfirmDeleteNetwork.WrappedComponent {...props} />, {
|
|
|
|
context: {
|
|
|
|
t: (str) => str,
|
2020-07-14 17:20:41 +02:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
afterEach(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
props.hideModal.resetHistory();
|
|
|
|
props.delRpcTarget.resetHistory();
|
|
|
|
props.onConfirm.resetHistory();
|
|
|
|
});
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('renders delete network modal title', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const modalTitle = wrapper.find('.modal-content__title');
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(modalTitle.text()).toStrictEqual('deleteNetwork');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('clicks cancel to hide modal', () => {
|
2020-11-03 00:41:28 +01:00
|
|
|
const cancelButton = wrapper.find(
|
2021-10-05 21:20:42 +02:00
|
|
|
'.button.btn-secondary.modal-container__footer-button',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
cancelButton.simulate('click');
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(props.hideModal.calledOnce).toStrictEqual(true);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('clicks delete to delete the target and hides modal', async () => {
|
2020-11-03 00:41:28 +01:00
|
|
|
const deleteButton = wrapper.find(
|
2021-10-05 21:20:42 +02:00
|
|
|
'.button.btn-danger-primary.modal-container__footer-button',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
deleteButton.simulate('click');
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(await props.delRpcTarget.calledOnce).toStrictEqual(true);
|
|
|
|
expect(props.hideModal.calledOnce).toStrictEqual(true);
|
|
|
|
expect(props.onConfirm.calledOnce).toStrictEqual(true);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|