import React from 'react';
import { shallow } from 'enzyme';
import LoopUI from './LoopUI';
+import OnapConstants from './utils/OnapConstants';
import LoopCache from './api/LoopCache';
import LoopActionService from './api/LoopActionService';
const component = shallow(<LoopUI />)
component.setState({
loopName: "testLoopName",
- showAlert: false
+ showSucAlert: false,
+ showFailAlert: false
});
await flushPromises();
expect(component).toMatchSnapshot();
const instance = component.instance();
instance.closeLoop();
- expect(component.state('loopName')).toEqual("Empty (NO loop loaded yet)");
+ expect(component.state('loopName')).toEqual(OnapConstants.defaultLoopName);
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");
})
});