2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Nokia Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 require('./report-modal-request.controller');
22 const jestMock = require('jest-mock');
24 describe('Testing error report creation', () => {
30 let mockModalInstance;
32 let mockReportService;
41 angular.mock.module('app')
44 beforeEach(inject(function (_$controller_) {
45 $notNeeded = jestMock.fn();
46 mockHttp = jestMock.fn();
48 mockModalInstance = {};
51 createObjectURL: function (blob) {
57 correctResponse = {data:{report:"test-error-report",status:202}};
58 failResponse = {data:{report:"test-fail-report",status:404}};
62 getReportData: function(info) {
63 return Promise.resolve(correctResponse);
65 getReportTimeStamp: function () {
70 testErrorMsg = 'testing message';
72 $controller = _$controller_('reportModalInstanceController',{
73 $uibModalInstance: mockModalInstance,
76 ReportService: mockReportService,
77 errorMsg: testErrorMsg,
82 test('Verify close will call close in modal instance', () => {
83 mockModalInstance.close = jestMock.fn();
87 expect(mockModalInstance.close).toHaveBeenCalled();
90 test('Verify report was constructed properly', () => {
92 $controller.saveReportData(correctResponse);
94 expect($controller.report).toEqual(testErrorMsg + "\n\n Collected data from API:\n" + JSON.stringify(correctResponse.data, null, "\t"));
95 expect($controller.downloadEnable).toBeTruthy();
96 expect($controller.download).toEqual(new Blob([ $controller.report ], { type : 'text/plain' }));
99 test('Verify report contains error if API did not respond', () => {
101 $controller.printReportFail(failResponse);
103 expect($controller.report).toEqual(testErrorMsg + "\n\n API error:\n" + JSON.stringify(failResponse.data, null, "\t"));
104 expect($controller.downloadEnable).toBeFalsy();