const component = shallow(<LoopUI />)
component.setState({
loopName: "testLoopName",
- showAlert: false
+ showSucAlert: false,
+ showFailAlert: false
});
await flushPromises();
expect(component).toMatchSnapshot();
expect(historyMock.push.mock.calls[0]).toEqual([ '/']);
})
- test('Test logout method', async () => {
- const flushPromises = () => new Promise(setImmediate);
- const component = shallow(<LoopUI />)
- const instance = component.instance();
- instance.logout();
- await flushPromises();
- expect(component.state('userName')).toEqual("testUser");
- })
-
test('Test loadLoop method refresh suc', async () => {
const historyMock = { push: jest.fn() };
LoopService.getLoop = jest.fn().mockImplementation(() => {
test('Test alert methods', () => {
const component = shallow(<LoopUI />)
- expect(component.state('showAlert')).toEqual(false);
+ expect(component.state('showSucAlert')).toEqual(false);
const instance = component.instance();
- instance.showAlert("testAlert");
- expect(component.state('showAlert')).toEqual(true);
+ instance.showSucAlert("testAlert");
+ expect(component.state('showSucAlert')).toEqual(true);
+ expect(component.state('showFailAlert')).toEqual(false);
expect(component.state('showMessage')).toEqual("testAlert");
instance.disableAlert();
- expect(component.state('showAlert')).toEqual(false);
+ expect(component.state('showSucAlert')).toEqual(false);
+ expect(component.state('showFailAlert')).toEqual(false);
+
+ instance.showFailAlert("testAlert2");
+ expect(component.state('showSucAlert')).toEqual(false);
+ expect(component.state('showFailAlert')).toEqual(true);
+ expect(component.state('showMessage')).toEqual("testAlert2");
})
});