From 6e3d850c1b6efda12a70a111c8734972c99e3db5 Mon Sep 17 00:00:00 2001 From: lapentafd Date: Fri, 18 Feb 2022 12:56:12 +0000 Subject: Code Coverage policy gui Edit Forms Issue-ID: POLICY-3351 Signed-off-by: lapentafd Change-Id: Ifea662ee9575dd73c738dd6a93998af0a19d6599 --- .../src/main/webapp/js/ApexContextAlbumEditForm.js | 4 +-- .../js/__test__/ApexContextAlbumEditForm.test.js | 28 ++++++++++++++++++++- .../webapp/js/__test__/ApexTaskEditForm.test.js | 29 ++++++++++++++++++++++ 3 files changed, 58 insertions(+), 3 deletions(-) diff --git a/gui-editors/gui-editor-apex/src/main/webapp/js/ApexContextAlbumEditForm.js b/gui-editors/gui-editor-apex/src/main/webapp/js/ApexContextAlbumEditForm.js index 9534a99..23d138d 100644 --- a/gui-editors/gui-editor-apex/src/main/webapp/js/ApexContextAlbumEditForm.js +++ b/gui-editors/gui-editor-apex/src/main/webapp/js/ApexContextAlbumEditForm.js @@ -1,7 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020-2021 Nordix Foundation. + * Modifications Copyright (C) 2020-2022 Nordix Foundation. * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ * ============LICENSE_END========================================================= */ import {keyInformationTab_reset} from "./ApexKeyInformationTab"; -const {ajax_delete, ajax_getWithKeyInfo, ajax_get} = require("./ApexAjax"); +const {ajax_delete, ajax_getWithKeyInfo, ajax_get, ajax_post, ajax_put} = require("./ApexAjax"); const {contextAlbumTab_reset} = require("./ApexContextAlbumTab"); const {apexUtils_removeElement, apexUtils_emptyElement, scrollToTop, apexUtils_areYouSure} = require("./ApexUtils"); const {dropdownList} = require("./dropdownList"); diff --git a/gui-editors/gui-editor-apex/src/main/webapp/js/__test__/ApexContextAlbumEditForm.test.js b/gui-editors/gui-editor-apex/src/main/webapp/js/__test__/ApexContextAlbumEditForm.test.js index 8bc3ed0..8d2976d 100644 --- a/gui-editors/gui-editor-apex/src/main/webapp/js/__test__/ApexContextAlbumEditForm.test.js +++ b/gui-editors/gui-editor-apex/src/main/webapp/js/__test__/ApexContextAlbumEditForm.test.js @@ -136,9 +136,35 @@ test('Test Generate Description Pressed', () => { test('Test editContextAlbumForm_cancelPressed', () => { jest.spyOn(apexUtils, 'apexUtils_removeElement').mockReturnValue(null); - jest.spyOn(document, 'getElementById').mockReturnValue(null); + const mock = jest.spyOn(document, 'getElementById').mockReturnValue(null); jest.spyOn(contextAlbumTab_reset, 'contextAlbumTab_reset').mockReturnValue(null); const mock_activate = jest.fn(mod.editContextAlbumForm_cancelPressed); mock_activate(); expect(mock_activate).toBeCalled(); + mock.mockRestore(); }); + +test('Test Submit Pressed with page', () => { + global.window.restRootURL = () => 'http://localhost' + const jqXHR = { status: 200, responseText: "" }; + $.ajax = jest.fn().mockImplementation((args) => { + args.success(data, null, jqXHR); + }); + jest.spyOn(keyInformationTab_reset, 'keyInformationTab_reset').mockReturnValueOnce(null); + jest.spyOn(apexUtils, 'apexUtils_removeElement').mockReturnValue(null); + jest.spyOn(contextAlbumTab_reset, 'contextAlbumTab_reset').mockReturnValueOnce(null); + + document.documentElement.innerHTML = '' + + '
' + + ''; + let documentSpy = jest.spyOn(document, 'getElementById'); + let elementMock = document.getElementById("editContextAlbumFormDiv"); + elementMock.value = 'APPLICATION'; + elementMock.selectedOption = {"name": "schemaName", "version": "schemaVers"}; + elementMock.checked = false; + elementMock.setAttribute("createEditOrView", "CREATE"); + documentSpy.mockReturnValue(elementMock); + const mock_activate = jest.fn(mod.editContextAlbumForm_submitPressed); + mock_activate(); + expect(mock_activate).toBeCalled(); +}); \ No newline at end of file diff --git a/gui-editors/gui-editor-apex/src/main/webapp/js/__test__/ApexTaskEditForm.test.js b/gui-editors/gui-editor-apex/src/main/webapp/js/__test__/ApexTaskEditForm.test.js index b9982f5..e9fcc9b 100644 --- a/gui-editors/gui-editor-apex/src/main/webapp/js/__test__/ApexTaskEditForm.test.js +++ b/gui-editors/gui-editor-apex/src/main/webapp/js/__test__/ApexTaskEditForm.test.js @@ -177,3 +177,32 @@ test('Test editTaskForm_submitPressed', () => { mock_activate(); expect(mock_activate).toBeCalled(); }); + +test('Test editTaskForm_submitPressed with page', () => { + const jqXHR = { status: 200, responseText: "" }; + $.ajax = jest.fn().mockImplementation((args) => { + args.success(data, null, jqXHR); + }); + jest.spyOn(apexTaskTab, 'taskTab_reset').mockReturnValueOnce(null); + jest.spyOn(keyInformationTab_reset, 'keyInformationTab_reset').mockReturnValueOnce(null); + jest.spyOn(apexUtils, 'apexUtils_removeElement').mockReturnValueOnce(null); + + document.documentElement.innerHTML = '' + + '' + + '' + + '' + + '' + + '
cell1cell2
cell3cell4
cell5cell6
' + + ''; + let documentSpy = jest.spyOn(document, 'getElementById'); + let elementMock = document.getElementById("editTaskFormInputFieldsTable"); + elementMock.value = 'notNullValue'; + elementMock.selectedOption = {"name": "name1", "version": "version1"}; + elementMock.checked = {"name": "nameOpt", "version": "versionOpt"}; + elementMock.setAttribute("createEditOrView", "EDIT") + documentSpy.mockReturnValue(elementMock); + + const mock_activate = jest.fn(mod.editTaskForm_submitPressed); + mock_activate(); + expect(mock_activate).toBeCalled(); +}); -- cgit 1.2.3-korg