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.controller');
22 const jestMock = require('jest-mock');
24 describe('Testing error report creation', () => {
30 let mockModalInstance;
32 let mockReportService;
39 angular.mock.module('app')
42 beforeEach(inject(function (_$controller_) {
43 $notNeeded = jestMock.fn();
44 mockHttp = jestMock.fn();
46 mockModalInstance = {};
49 createObjectURL: function (blob) {
55 correctResponse = {data:{report:"test-error-report",status:202}};
56 failResponse = {data:{report:"test-fail-report",status:404}};
60 getReportData: function() {
61 return Promise.resolve(correctResponse);
63 getReportTimeStamp: function () {
68 testErrorMsg = 'testing message';
70 $controller = _$controller_('reportModalController',{
71 $uibModalInstance: mockModalInstance,
74 ReportService: mockReportService,
75 errorMsg: testErrorMsg
79 test('Verify close will call close in modal instance', () => {
80 mockModalInstance.close = jestMock.fn();
84 expect(mockModalInstance.close).toHaveBeenCalled();
87 test('Verify report was constructed properly', () => {
89 $controller.saveReportData(correctResponse);
91 expect($controller.report).toEqual(testErrorMsg + "\n\n Collected data from API:\n" + JSON.stringify(correctResponse.data, null, "\t"));
92 expect($controller.downloadEnable).toBeTruthy();
93 expect($controller.download).toEqual(new Blob([ $controller.report ], { type : 'text/plain' }));
96 test('Verify report contains error if API did not respond', () => {
98 $controller.printReportFail(failResponse);
100 expect($controller.report).toEqual(testErrorMsg + "\n\n API error:\n" + JSON.stringify(failResponse.data, null, "\t"));
101 expect($controller.downloadEnable).toBeFalsy();