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', () => {
25 const mockAPI = "testAPI";
32 let mockModalInstance;
34 let mockReportService;
44 angular.mock.module('app')
47 beforeEach(inject(function (_$controller_) {
48 $notNeeded = jestMock.fn();
49 mockHttp = jestMock.fn();
50 mockDataService = jestMock.fn();
52 mockDataService.getMsoRequestParametersTestApi = function() {
56 mockModalInstance = {};
59 createObjectURL: function (blob) {
65 correctResponse = {data:{report:"test-error-report",status:202}};
66 failResponse = {data:{report:"test-fail-report",status:404}};
70 getReportData: function(info) {
71 return Promise.resolve(correctResponse);
73 getReportTimeStamp: function () {
78 testErrorMsg = 'testing message';
80 $controller = _$controller_('reportModalInstanceController',{
81 $uibModalInstance: mockModalInstance,
84 ReportService: mockReportService,
85 DataService: mockDataService,
86 errorMsg: testErrorMsg,
91 test('Verify close will call close in modal instance', () => {
92 mockModalInstance.close = jestMock.fn();
96 expect(mockModalInstance.close).toHaveBeenCalled();
99 test('Verify report was constructed properly', () => {
101 $controller.saveReportData(correctResponse);
103 expect($controller.report).toEqual(
104 "Selected test API: \n" + mockAPI
105 + "\n\n Data from GUI:\n" + testErrorMsg
106 + "\n\n Collected data from API:\n" + JSON.stringify(correctResponse.data, null, "\t"));
107 expect($controller.downloadEnable).toBeTruthy();
108 expect($controller.download).toEqual(new Blob([ $controller.report ], { type : 'text/plain' }));
111 test('Verify report contains error if API did not respond', () => {
113 $controller.printReportFail(failResponse);
115 expect($controller.report).toEqual(testErrorMsg + "\n\n API error:\n" + JSON.stringify(failResponse.data, null, "\t"));
116 expect($controller.downloadEnable).toBeFalsy();