blob: e08c50d2e5d428958a7f9e7b822a2580074f6314 [file] [log] [blame]
xuegao564fdb02019-10-02 11:18:10 +02001/*-
2 * ============LICENSE_START=======================================================
3 * ONAP CLAMP
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights
6 * reserved.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END============================================
20 * ===================================================================
21 *
22 */
23import React from 'react';
24import { shallow } from 'enzyme';
25import RefreshStatus from './RefreshStatus';
26import LoopCache from '../../api/LoopCache';
27import LoopActionService from '../../api/LoopActionService';
28
29describe('Verify RefreshStatus', () => {
30
31 const loopCache = new LoopCache({
32 "name": "LOOP_Jbv1z_v1_0_ResourceInstanceName1_tca"
33 });
34
35 it('Test refresh status failed', async () => {
36 const flushPromises = () => new Promise(setImmediate);
37 const historyMock = { push: jest.fn() };
xuegaocc5fe512020-04-06 13:13:52 +020038 const showSucAlert = jest.fn();
39 const showFailAlert = jest.fn();
xuegao564fdb02019-10-02 11:18:10 +020040
xuegaocc5fe512020-04-06 13:13:52 +020041 const component = shallow(<RefreshStatus loopCache={loopCache} history={historyMock} showSucAlert={showSucAlert} showFailAlert={showFailAlert} />)
xuegao564fdb02019-10-02 11:18:10 +020042 await flushPromises();
43 component.update();
44
45 expect(historyMock.push.mock.calls[0]).toEqual([ '/']);
xuegao564fdb02019-10-02 11:18:10 +020046 });
47
48 it('Test refresh status successful', async () => {
49 const flushPromises = () => new Promise(setImmediate);
50 const historyMock = { push: jest.fn() };
51 const updateLoopFunction = jest.fn();
xuegaocc5fe512020-04-06 13:13:52 +020052 const showSucAlert = jest.fn();
53 const showFailAlert = jest.fn();
xuegao564fdb02019-10-02 11:18:10 +020054
55 LoopActionService.refreshStatus = jest.fn().mockImplementation(() => {
56 return Promise.resolve({
57 ok: true,
58 status: 200,
59 json: () => {}
60 });
61 });
xuegao0efeb6b2019-10-07 14:36:34 +020062
xuegao564fdb02019-10-02 11:18:10 +020063 const component = shallow(<RefreshStatus loopCache={loopCache}
xuegaocc5fe512020-04-06 13:13:52 +020064 loopAction="submit" history={historyMock} updateLoopFunction={updateLoopFunction} showSucAlert={showSucAlert} showFailAlert={showFailAlert} />)
xuegao564fdb02019-10-02 11:18:10 +020065 await flushPromises();
66 component.update();
67
68 expect(historyMock.push.mock.calls[0]).toEqual([ '/']);
xuegao564fdb02019-10-02 11:18:10 +020069 });
70
71});