diff options
Diffstat (limited to 'gui-editors')
13 files changed, 664 insertions, 64 deletions
diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexContextAlbumEditForm.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexContextAlbumEditForm.js index b6d0fe6..9534a99 100644 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexContextAlbumEditForm.js +++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexContextAlbumEditForm.js @@ -19,7 +19,7 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ - +import {keyInformationTab_reset} from "./ApexKeyInformationTab"; const {ajax_delete, ajax_getWithKeyInfo, ajax_get} = require("./ApexAjax"); const {contextAlbumTab_reset} = require("./ApexContextAlbumTab"); const {apexUtils_removeElement, apexUtils_emptyElement, scrollToTop, apexUtils_areYouSure} = require("./ApexUtils"); diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexContextSchemaEditForm.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexContextSchemaEditForm.js index 48b2c33..06c4402 100644 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexContextSchemaEditForm.js +++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexContextSchemaEditForm.js @@ -26,6 +26,7 @@ import { formUtils_generateUUID } from "./ApexFormUtils"; import {contextSchemaTab_reset} from "./ApexContextSchemaTab"; +import {keyInformationTab_reset} from "./ApexKeyInformationTab"; function editContextSchemaForm_createContextSchema(formParent) { return editContextSchemaForm_activate(formParent, "CREATE", null); diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexPageControl.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexPageControl.js index f2acf87..7b1b884 100644 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexPageControl.js +++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexPageControl.js @@ -1,7 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020-2021 Nordix Foundation. * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -63,17 +63,23 @@ function pageControl_modelMode(name, version, fileName) { direction : "left" }, 200); - $("#mainTabs").tabs({ - classes : { - "ui-tabs-tab" : "ui-tabs-tab-custom", - "ui-tabs-active" : "ui-tabs-active-custom", - "ui-tabs-anchor" : "ui-tabs-anchor-custom" - }, - disabled : false, - activate : function(event, ui) { - localStorage.setItem("apex_tab_index", ui.newTab.index()); - } - }); + try{ + $("#mainTabs").tabs({ + classes : { + "ui-tabs-tab" : "ui-tabs-tab-custom", + "ui-tabs-active" : "ui-tabs-active-custom", + "ui-tabs-anchor" : "ui-tabs-anchor-custom" + }, + disabled : false, + activate : function(event, ui) { + localStorage.setItem("apex_tab_index", ui.newTab.index()); + } + }); + } + catch(err){ + console.error('TypeError! Failed to get tabs function'); + } + contextSchemaTab_activate(); eventTab_activate(); @@ -116,15 +122,19 @@ function pageControl_noModelMode() { taskTab_deactivate(); policyTab_deactivate(); keyInformationTab_deactivate(); - - $("#mainTabs").tabs({ - classes : { - "ui-tabs-tab" : "ui-tabs-tab-custom", - "ui-tabs-active" : "ui-tabs-active-custom", - "ui-tabs-anchor" : "ui-tabs-anchor-custom" - }, - disabled : [ 0, 1, 2, 3, 4, 5 ] - }); + try{ + $("#mainTabs").tabs({ + classes : { + "ui-tabs-tab" : "ui-tabs-tab-custom", + "ui-tabs-active" : "ui-tabs-active-custom", + "ui-tabs-anchor" : "ui-tabs-anchor-custom" + }, + disabled : [ 0, 1, 2, 3, 4, 5 ] + }); + } + catch(err){ + console.error('TypeError! Failed to get tabs function'); + } showPlaceholder(true); } @@ -145,16 +155,19 @@ function pageControl_busyMode() { $("#menuConceptsTasks").addClass("disabled"); $("#menuConceptsPolicies").addClass("disabled"); $("#menuConceptsKeyInformation").addClass("disabled"); - - $("#mainTabs").tabs({ - classes : { - "ui-tabs-tab" : "ui-tabs-tab-custom", - "ui-tabs-active" : "ui-tabs-active-custom", - "ui-tabs-anchor" : "ui-tabs-anchor-custom" - }, - disabled : false - }); - + try{ + $("#mainTabs").tabs({ + classes : { + "ui-tabs-tab" : "ui-tabs-tab-custom", + "ui-tabs-active" : "ui-tabs-active-custom", + "ui-tabs-anchor" : "ui-tabs-anchor-custom" + }, + disabled : false + }); + } + catch(err){ + console.error('TypeError! Failed to get tabs function'); + } contextSchemaTab_activate(); eventTab_activate(); contextAlbumTab_activate(); @@ -188,15 +201,19 @@ function pageControl_readyMode() { taskTab_deactivate(); policyTab_deactivate(); keyInformationTab_deactivate(); - - $("#mainTabs").tabs({ - classes : { - "ui-tabs-tab" : "ui-tabs-tab-custom", - "ui-tabs-active" : "ui-tabs-active-custom", - "ui-tabs-anchor" : "ui-tabs-anchor-custom" - }, - disabled : [ 0, 1, 2, 3, 4, 5 ] - }); + try{ + $("#mainTabs").tabs({ + classes : { + "ui-tabs-tab" : "ui-tabs-tab-custom", + "ui-tabs-active" : "ui-tabs-active-custom", + "ui-tabs-anchor" : "ui-tabs-anchor-custom" + }, + disabled : [ 0, 1, 2, 3, 4, 5 ] + }); + } + catch(err){ + console.error('TypeError! Failed to get tabs function'); + } showPlaceholder(true); } diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexContextAlbumEditForm.test.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexContextAlbumEditForm.test.js index 728accd..a1aed28 100644 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexContextAlbumEditForm.test.js +++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexContextAlbumEditForm.test.js @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation + * Copyright (C) 2020-2021 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,21 @@ */ const mod = require('../ApexContextAlbumEditForm'); +const apexUtils = require('../ApexUtils'); +const contextAlbumTab_reset = require('../ApexContextAlbumTab'); +const keyInformationTab_reset = require('../ApexKeyInformationTab'); +const formUtils_generateDescription = require('../ApexFormUtils'); + +let data = { + messages: { + message: [ + '{"apexContextSchema": {"key":{"name": "name1", "version": "version1"}}, "apexTask":{"key":{"name": "name1", "version": "version1"}},' + + '"apexContextAlbum":{"key":{"name": "name1", "version": "version1"},"itemSchema":{}},"apexEvent":{"key":{"name": "name1", "version": "version1"}},' + + '"apexPolicy":{"policyKey":{"name": "name1", "version": "version1"}}, "apexKeyInfo":{"key":{"name": "name1", "version": "version1"}}}' + ] + }, + ok: true +}; test('Test mock_editContextAlbumForm_activate', () => { const mock_editContextAlbumForm_activate = jest.fn(mod.editContextAlbumForm_activate); @@ -41,4 +56,80 @@ test('Test mock_editContextAlbumForm_activate', () => { mock_editContextAlbumForm_activate('parentTest', 'CREATE', contextAlbum, contextSchema); expect(mock_editContextAlbumForm_activate).toHaveBeenCalledTimes(1); +}); + +test('Test Create Context Album', () => { + const jqXHR = { status: 200, responseText: "" }; + $.ajax = jest.fn().mockImplementation((args) => { + args.success(data, null, jqXHR); + }); + const mock_activate = jest.fn(mod.editContextAlbumForm_createContextAlbum); + mock_activate('parentTest'); + expect(mock_activate).toBeCalled(); +}); + +test('Test Delete Context Album', () => { + global.confirm = () => true + 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').mockReturnValueOnce(null); + jest.spyOn(contextAlbumTab_reset, 'contextAlbumTab_reset').mockReturnValueOnce(null); + const mock_activate = jest.fn(mod.editContextAlbumForm_deleteContextAlbum); + mock_activate('parentTest', 'name', 'version'); + expect(mock_activate).toBeCalled(); +}); + +test('Test View Context Album', () => { + global.window.restRootURL = () => 'http://localhost' + const jqXHR = { status: 200, responseText: "" }; + $.ajax = jest.fn().mockImplementation((args) => { + args.success(data, null, jqXHR); + }); + const mock_activate = jest.fn(mod.editContextAlbumForm_viewContextAlbum); + mock_activate('parentTest', 'name', 'version'); + expect(mock_activate).toBeCalled(); +}); + +test('Test Edit Context Album', () => { + global.window.restRootURL = () => 'http://localhost' + const jqXHR = { status: 200, responseText: "" }; + $.ajax = jest.fn().mockImplementation((args) => { + args.success(data, null, jqXHR); + }); + const mock_activate = jest.fn(mod.editContextAlbumForm_editContextAlbum); + mock_activate('parentTest', 'name', 'version'); + expect(mock_activate).toBeCalled(); +}); + +test('Test Submit Pressed', () => { + jest.spyOn(apexUtils, 'apexUtils_removeElement').mockReturnValueOnce(null); + jest.spyOn(contextAlbumTab_reset, 'contextAlbumTab_reset').mockReturnValueOnce(null); + const mock_activate = jest.fn(mod.editContextAlbumForm_submitPressed); + mock_activate(); + expect(mock_activate).toBeCalled(); +}); + +test('Test Generate UUID Pressed', () => { + let documentSpy = jest.spyOn(document, 'getElementById'); + let elementMock = document.createElement("editContextAlbumFormUuidInput"); + elementMock.value = 'one' + documentSpy.mockReturnValue(elementMock); + const mock_activate = jest.fn(mod.editContextAlbumForm_generateUUIDPressed); + mock_activate(); + expect(mock_activate).toBeCalled(); +}); + +test('Test Generate Description Pressed', () => { + jest.spyOn(formUtils_generateDescription, 'formUtils_generateDescription').mockReturnValueOnce(null); + let documentSpy = jest.spyOn(document, 'getElementById'); + let elementMock = document.createElement("editContextAlbumFormDescriptionTextArea"); + elementMock.value = 'one' + documentSpy.mockReturnValue(elementMock); + const mock_activate = jest.fn(mod.editContextAlbumForm_generateDescriptionPressed); + mock_activate(); + expect(mock_activate).toBeCalled(); });
\ No newline at end of file diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexContextSchemaEditForm.test.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexContextSchemaEditForm.test.js index 69505bb..87b4f82 100644 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexContextSchemaEditForm.test.js +++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexContextSchemaEditForm.test.js @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. + * Copyright (C) 2020-2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,18 +19,92 @@ */ const mod = require('../ApexContextSchemaEditForm'); +const apexUtils = require('../ApexUtils'); +const apexContextSchemaTab = require('../ApexContextSchemaTab'); +const keyInformationTab_reset = require('../ApexKeyInformationTab'); +const apexAjax = require('../ApexAjax'); +const formUtils_generateDescription = require('../ApexFormUtils'); -test('Test editContextSchemaForm_createContextSchema', () => { - const contextSchema = { - name: 'testName', - version: '0.0.1', - schemaFlavour: 'testFlav', - schemaDefinition: 'testDef', - uuid: 'testUUID', - description: 'testDesc' - } +let data = { + messages: { + message: [] + }, + ok: true +}; +const contextSchema = { + name: 'testName', + version: '0.0.1', + schemaFlavour: 'testFlav', + schemaDefinition: 'testDef', + uuid: 'testUUID', + description: 'testDesc' +} +test('Test editContextSchemaForm_createContextSchema', () => { const mock_editContextSchemaForm_createContextSchema = jest.fn(mod.editContextSchemaForm_createContextSchema); mock_editContextSchemaForm_createContextSchema('parentTest', 'CREATE', contextSchema); expect(mock_editContextSchemaForm_createContextSchema).toBeCalled(); +}); + +test('Test Delete Context Schema', () => { + global.confirm = () => true + 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(apexContextSchemaTab, 'contextSchemaTab_reset').mockReturnValueOnce(null); + const mock_activate = jest.fn(mod.editContextSchemaForm_deleteContextSchema); + mock_activate('parent', 'name', 'version'); + expect(mock_activate).toBeCalled(); +}); + +test('Test View Context Schema', () => { + jest.spyOn(apexAjax, 'ajax_getWithKeyInfo').mockReturnValueOnce(null); + const mock_activate = jest.fn(mod.editContextSchemaForm_viewContextSchema); + mock_activate('parent', 'name', 'version'); + expect(mock_activate).toBeCalled(); +}); + +test('Test Activate Context Schema', () => { + const mock_activate = jest.fn(mod.editContextSchemaForm_activate); + mock_activate('parent', 'operation', contextSchema); + expect(mock_activate).toBeCalled(); +}); + +test('Test Generate UUID Pressed', () => { + let documentSpy = jest.spyOn(document, 'getElementById'); + let elementMock = document.createElement("editContextSchemaFormUuidInput"); + elementMock.value = 'one' + documentSpy.mockReturnValue(elementMock); + const mock_activate = jest.fn(mod.editContextSchemaForm_generateUUIDPressed); + mock_activate(); + expect(mock_activate).toBeCalled(); +}); + +test('Test Generate Description Pressed', () => { + jest.spyOn(formUtils_generateDescription, 'formUtils_generateDescription').mockReturnValueOnce(null); + let documentSpy = jest.spyOn(document, 'getElementById'); + let elementMock = document.createElement("editContextSchemaFormDescriptionTextArea"); + elementMock.value = 'one' + documentSpy.mockReturnValue(elementMock); + const mock_activate = jest.fn(mod.editContextSchemaForm_generateDescriptionPressed); + mock_activate(); + expect(mock_activate).toBeCalled(); +}); + +test('Test Cancel Pressed', () => { + jest.spyOn(apexUtils, 'apexUtils_removeElement').mockReturnValueOnce(null); + jest.spyOn(apexContextSchemaTab, 'contextSchemaTab_reset').mockReturnValueOnce(null); + const mock_activate = jest.fn(mod.editContextSchemaForm_cancelPressed); + mock_activate(); + expect(mock_activate).toBeCalled(); +}); + +test('Test Submit Pressed', () => { + jest.spyOn(apexUtils, 'apexUtils_removeElement').mockReturnValueOnce(null); + jest.spyOn(apexContextSchemaTab, 'contextSchemaTab_reset').mockReturnValueOnce(null); + const mock_activate = jest.fn(mod.editContextSchemaForm_submitPressed); + mock_activate(); + expect(mock_activate).toBeCalled(); });
\ No newline at end of file diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexContextSchemaTab.test.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexContextSchemaTab.test.js index 552eb85..3883bd5 100644 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexContextSchemaTab.test.js +++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexContextSchemaTab.test.js @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. + * Copyright (C) 2020-2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,14 +20,35 @@ const mod = require('../ApexContextSchemaTab'); +let data = { + messages: { + message: [ + '{"apexContextSchema": {"key":{"name": "name1", "version": "version1"}}, "apexTask":{"key":{"name": "name1", "version": "version1"}},' + + '"apexContextAlbum":{"key":{"name": "name1", "version": "version1"}},"apexEvent":{"key":{"name": "name1", "version": "version1"}},' + + '"apexPolicy":{"policyKey":{"name": "name1", "version": "version1"}}, "apexKeyInfo":{"key":{"name": "name1", "version": "version1"}}}' + ] + }, + ok: true +}; + test('Test activateContextSchema', () => { + const jqXHR = { status: 200, responseText: "" }; + $.ajax = jest.fn().mockImplementation((args) => { + args.success(data, null, jqXHR); + }); const mock_activate = jest.fn(mod.contextSchemaTab_activate); mock_activate(); expect(mock_activate).toBeCalled(); }); test('Test deactivate', () => { - const mock_deactivate = jest.fn(mod.contextSchemaTab_deactivate); - mock_deactivate(); - expect(mock_deactivate).toBeCalledWith(); + const mock_deactivate = jest.fn(mod.contextSchemaTab_deactivate); + mock_deactivate(); + expect(mock_deactivate).toBeCalledWith(); +}); + +test('Test reset', () => { + const mock_deactivate = jest.fn(mod.contextSchemaTab_reset); + mock_deactivate(); + expect(mock_deactivate).toBeCalledWith(); });
\ No newline at end of file diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexEventEditForm.test.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexEventEditForm.test.js index 6363ae6..a203f06 100644 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexEventEditForm.test.js +++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexEventEditForm.test.js @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. + * Copyright (C) 2020-2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,21 @@ */ const mod = require('../ApexEventEditForm'); +const eventTab_reset = require('../ApexEventTab'); +const apexUtils = require('../ApexUtils'); +const keyInformationTab_reset = require('../ApexKeyInformationTab'); + +let data = { + messages: { + message: [ + '{"apexContextSchema": {"key":{"name": "name1", "version": "version1"}}, "apexTask":{"key":{"name": "name1", "version": "version1"}},' + + '"apexContextAlbum":{"key":{"name": "name1", "version": "version1"}},"apexEvent":{"key":{"name": "name1", "version": "version1"}},' + + '"apexPolicy":{"policyKey":{"name": "name1", "version": "version1"}}, "apexKeyInfo":{"key":{"name": "name1", "version": "version1"}}}' + ] + }, + ok: true +}; + const contextSchema = { name: 'testName', version: '0.0.1', @@ -70,4 +85,54 @@ test('Test Activate !=Create/Edit', () => { const mock_activate = jest.fn(mod.editEventForm_activate); mock_activate(null, 'TEST', event, contextSchema); expect(mock_activate).toBeCalled(); +}); + +test('Test Delete Event', () => { + global.confirm = () => true + 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').mockReturnValueOnce(null); + jest.spyOn(eventTab_reset, 'eventTab_reset').mockReturnValueOnce(null); + const mock_activate = jest.fn(mod.editEventForm_deleteEvent); + mock_activate('parentTest', 'name', 'version'); + expect(mock_activate).toBeCalled(); +}); + +test('Test Event Edit Form Inner', () => { + global.window.restRootURL = () => 'http://localhost' + const jqXHR = { status: 200, responseText: "" }; + $.ajax = jest.fn().mockImplementation((args) => { + args.success(data, null, jqXHR); + }); + jest.spyOn(apexUtils, 'apexUtils_removeElement').mockReturnValueOnce(null); + jest.spyOn(apexUtils, 'apexUtils_emptyElement').mockReturnValueOnce(null); + const mock_activate = jest.fn(mod.editEventForm_editEvent_inner); + mock_activate('parentTest', 'name', 'version', 'edit'); + expect(mock_activate).toBeCalled(); +}); + +test('Test View Event', () => { + const mock_activate = jest.fn(mod.editEventForm_viewEvent); + mock_activate('parentTest', 'name', 'version'); + expect(mock_activate).toBeCalled(); +}); + +test('Test Edit Event', () => { + const mock_activate = jest.fn(mod.editEventForm_editEvent); + mock_activate('parentTest', 'name', 'version'); + expect(mock_activate).toBeCalled(); +}); + +test('Test Create Event', () => { + const jqXHR = { status: 200, responseText: "" }; + $.ajax = jest.fn().mockImplementation((args) => { + args.success(data, null, jqXHR); + }); + const mock_activate = jest.fn(mod.editEventForm_createEvent); + mock_activate('parentTest'); + expect(mock_activate).toBeCalled(); });
\ No newline at end of file diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexFiles.test.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexFiles.test.js index 6fcaa4d..f5be3cc 100644 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexFiles.test.js +++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexFiles.test.js @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation + * Copyright (C) 2020-2021 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,18 @@ */ const mod = require('../ApexFiles'); +const resultForm_activate = require('../ApexResultForm'); + +let data = { + messages: { + message: [ + '{"apexContextSchema": {"key":{"name": "name1", "version": "version1"}}, "apexTask":{"key":{"name": "name1", "version": "version1"}},' + + '"apexContextAlbum":{"key":{"name": "name1", "version": "version1"},"itemSchema":{}},"apexEvent":{"key":{"name": "name1", "version": "version1"}},' + + '"apexPolicy":{"policyKey":{"name": "name1", "version": "version1"}}, "apexKeyInfo":{"key":{"name": "name1", "version": "version1"}}}' + ] + }, + ok: true + }; test('test files_open', () => { const open = jest.fn(mod.files_fileOpen); @@ -33,6 +45,12 @@ test('test files_download', () => { }); test('Test files_upload', () => { + global.window.restRootURL = () => 'http://localhost' + const jqXHR = { status: 200, responseText: "" }; + $.ajax = jest.fn().mockImplementation((args) => { + args.success(data, null, jqXHR); + }); + jest.spyOn(resultForm_activate, 'resultForm_activate').mockReturnValueOnce(null); const upload = jest.fn(mod.files_fileUpload); upload(); expect(upload).toBeCalled(); diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexPageControl.test.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexPageControl.test.js new file mode 100644 index 0000000..b414bb1 --- /dev/null +++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexPageControl.test.js @@ -0,0 +1,116 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +const mod = require('../ApexPageControl'); +const apexContextSchemaTab = require('../ApexContextSchemaTab'); +const apexEventTab = require('../ApexEventTab'); +const apexAlbumTab = require('../ApexContextAlbumTab'); +const apexTaskTab = require('../ApexTaskTab'); +const apexPolicyTab = require('../ApexPolicyTab'); +const keyInformationTab = require('../ApexKeyInformationTab'); + +test('Test showPlaceholder show', () => { + const mock_activate = jest.fn(mod.showPlaceholder); + mock_activate('show'); + expect(mock_activate).toBeCalled(); +}); + +test('Test showPlaceholder hide', () => { + const mock_activate = jest.fn(mod.showPlaceholder); + mock_activate(''); + expect(mock_activate).toBeCalled(); +}); + +test('Test pageControl_status', () => { + let data = { + messages: { + message: [] + }, + ok: true + }; + const mock_activate = jest.fn(mod.pageControl_status); + mock_activate(data); + expect(mock_activate).toBeCalled(); +}); + +test('Test pageControl_status when data is not present', () => { + let data = { + messages: { + message: [] + } + }; + const mock_activate = jest.fn(mod.pageControl_status); + mock_activate(data); + expect(mock_activate).toBeCalled(); +}); + +test('Test pageControl_restError', () => { + const mock_activate = jest.fn(mod.pageControl_restError); + mock_activate('', '', '', ''); + expect(mock_activate).toBeCalled(); +}); + +test('Test pageControl_modelMode', () => { + jest.spyOn(apexContextSchemaTab, 'contextSchemaTab_activate').mockReturnValueOnce(null); + jest.spyOn(apexEventTab, 'eventTab_activate').mockReturnValueOnce(null); + jest.spyOn(apexAlbumTab, 'contextAlbumTab_activate').mockReturnValueOnce(null); + jest.spyOn(apexTaskTab, 'taskTab_activate').mockReturnValueOnce(null); + jest.spyOn(apexPolicyTab, 'policyTab_activate').mockReturnValueOnce(null); + jest.spyOn(keyInformationTab, 'keyInformationTab_activate').mockReturnValueOnce(null); + const mock_activate = jest.fn(mod.pageControl_modelMode); + mock_activate('name', 'version', 'fileName'); + expect(mock_activate).toBeCalled(); +}); + +test('Test pageControl_noModelMode', () => { + jest.spyOn(apexContextSchemaTab, 'contextSchemaTab_activate').mockReturnValueOnce(null); + jest.spyOn(apexEventTab, 'eventTab_activate').mockReturnValueOnce(null); + jest.spyOn(apexAlbumTab, 'contextAlbumTab_activate').mockReturnValueOnce(null); + jest.spyOn(apexTaskTab, 'taskTab_activate').mockReturnValueOnce(null); + jest.spyOn(apexPolicyTab, 'policyTab_activate').mockReturnValueOnce(null); + jest.spyOn(keyInformationTab, 'keyInformationTab_activate').mockReturnValueOnce(null); + const mock_activate = jest.fn(mod.pageControl_noModelMode); + mock_activate(); + expect(mock_activate).toBeCalled(); +}); + +test('Test pageControl_busyMode', () => { + jest.spyOn(apexContextSchemaTab, 'contextSchemaTab_activate').mockReturnValueOnce(null); + jest.spyOn(apexEventTab, 'eventTab_activate').mockReturnValueOnce(null); + jest.spyOn(apexAlbumTab, 'contextAlbumTab_activate').mockReturnValueOnce(null); + jest.spyOn(apexTaskTab, 'taskTab_activate').mockReturnValueOnce(null); + jest.spyOn(apexPolicyTab, 'policyTab_activate').mockReturnValueOnce(null); + jest.spyOn(keyInformationTab, 'keyInformationTab_activate').mockReturnValueOnce(null); + const mock_activate = jest.fn(mod.pageControl_busyMode); + mock_activate(); + expect(mock_activate).toBeCalled(); +}); + +test('Test pageControl_readyMode', () => { + jest.spyOn(apexContextSchemaTab, 'contextSchemaTab_activate').mockReturnValueOnce(null); + jest.spyOn(apexEventTab, 'eventTab_activate').mockReturnValueOnce(null); + jest.spyOn(apexAlbumTab, 'contextAlbumTab_activate').mockReturnValueOnce(null); + jest.spyOn(apexTaskTab, 'taskTab_activate').mockReturnValueOnce(null); + jest.spyOn(apexPolicyTab, 'policyTab_activate').mockReturnValueOnce(null); + jest.spyOn(keyInformationTab, 'keyInformationTab_activate').mockReturnValueOnce(null); + const mock_activate = jest.fn(mod.pageControl_readyMode); + mock_activate(); + expect(mock_activate).toBeCalled(); +});
\ No newline at end of file diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexPolicyEditForm_State.test.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexPolicyEditForm_State.test.js index 1f1767a..8dd9fc4 100644 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexPolicyEditForm_State.test.js +++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexPolicyEditForm_State.test.js @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation + * Copyright (C) 2020-2021 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -117,6 +117,37 @@ test('Test editPolicyForm_State_addPolicyTask', () => { }); -test.todo('Test editPolicyForm_State_getDirectOutputMappingOptions'); -test.todo('Test editPolicyForm_State_getStateBean'); -test.todo('Test editPolicyForm_State_getLogicOutputMappingOptions');
\ No newline at end of file +test('Test editPolicyForm_State_getDirectOutputMappingOptions', () => { + let documentSpy = jest.spyOn(document, 'getElementById'); + let elementMock = document.createElement("editPolicyFormDirOutputsTable_stateName"); + elementMock.rows = '1' + documentSpy.mockReturnValue(elementMock); + const mock_activate = jest.fn(mod.editPolicyForm_State_getDirectOutputMappingOptions); + mock_activate('stateName'); + expect(mock_activate).toBeCalled(); + +}); + +test('Test editPolicyForm_State_getStateBean', () => { + let documentSpy = jest.spyOn(document, 'getElementById'); + let elementMock = document.createElement("editPolicyFormDirOutputsTable_stateName"); + elementMock.rows = '1' + documentSpy.mockReturnValue(elementMock); + const mock_activate = jest.fn(mod.editPolicyForm_State_getStateBean); + mock_activate('stateName'); + expect(mock_activate).toBeCalled(); + +}); + +test('Test editPolicyForm_State_getStateBean StateName is Null', () => { + const mock_activate = jest.fn(mod.editPolicyForm_State_getStateBean); + mock_activate(null); + expect(mock_activate).toBeCalled(); + +}); + +test('Test editPolicyForm_State_getLogicOutputMappingOptions', () => { + const mock_activate = jest.fn(mod.editPolicyForm_State_getLogicOutputMappingOptions); + mock_activate(null); + expect(mock_activate).toBeCalled(); +});
\ No newline at end of file diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/contextMenu.test.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/contextMenu.test.js new file mode 100644 index 0000000..d804b6d --- /dev/null +++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/contextMenu.test.js @@ -0,0 +1,118 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +const mod = require('../contextMenu'); +const apexContextEdit = require('../ApexContextSchemaEditForm'); +const apexEventEdit = require('../ApexEventEditForm'); +const apexTaskEdit = require('../ApexTaskEditForm'); +const apexPolicyEdit = require('../ApexPolicyEditForm'); +const apexContextAlbumEdit = require('../ApexContextAlbumEditForm'); + +test('Test rightClickMenu', () => { + let documentSpy = jest.spyOn(document, 'getElementById'); + let elementMock = document.createElement("rightClickMenu"); + documentSpy.mockReturnValue(elementMock); + const event = new MouseEvent('click'); + const mock_activate = jest.fn(mod.rightClickMenu); + mock_activate(event, 'type', 'name', 'version'); + expect(mock_activate).toBeCalled(); +}); + +test('Test rightClickMenuCreate when Type is CONTEXTSCHEMA', () => { + global.confirm = () => true + jest.spyOn(apexContextEdit, 'editContextSchemaForm_createContextSchema').mockReturnValueOnce(null); + const mock_activate = jest.fn(mod.rightClickMenuCreate); + mock_activate('parent', 'CONTEXTSCHEMA'); + expect(mock_activate).toBeCalled(); +}); + +test('Test rightClickMenuCreate when Type is EVENT or TASK or POLICY or CONTEXTALBUM or EMPTY', () => { + global.confirm = () => true + jest.spyOn(apexEventEdit, 'editEventForm_createEvent').mockReturnValueOnce(null); + const mock_activate = jest.fn(mod.rightClickMenuCreate); + mock_activate('parent', 'EVENT'); + expect(mock_activate).toBeCalled(); + mock_activate('parent', 'TASK'); + expect(mock_activate).toBeCalled(); + mock_activate('parent', 'POLICY'); + expect(mock_activate).toBeCalled(); + mock_activate('parent', 'CONTEXTALBUM'); + expect(mock_activate).toBeCalled(); + mock_activate('parent', ''); + expect(mock_activate).toBeCalled(); + +}); + +test('Test rightClickMenuView when Type is CONTEXTSCHEMA or EVENT or TASK or POLICY or CONTEXTALBUM or EMPTY', () => { + global.confirm = () => true + jest.spyOn(apexContextEdit, 'editContextSchemaForm_viewContextSchema').mockReturnValueOnce(null); + const mock_activate = jest.fn(mod.rightClickMenuView); + mock_activate('parent', 'CONTEXTSCHEMA'); + expect(mock_activate).toBeCalled(); + mock_activate('parent', 'EVENT'); + expect(mock_activate).toBeCalled(); + mock_activate('parent', 'TASK'); + expect(mock_activate).toBeCalled(); + mock_activate('parent', 'POLICY'); + expect(mock_activate).toBeCalled(); + mock_activate('parent', 'CONTEXTALBUM'); + expect(mock_activate).toBeCalled(); + mock_activate('parent', ''); + expect(mock_activate).toBeCalled(); +}); + +test('Test rightClickMenuEdit when Type is CONTEXTSCHEMA or EVENT or TASK or POLICY or CONTEXTALBUM or EMPTY', () => { + global.confirm = () => true + jest.spyOn(apexContextEdit, 'editContextSchemaForm_viewContextSchema').mockReturnValueOnce(null); + const mock_activate = jest.fn(mod.rightClickMenuEdit); + mock_activate('parent', 'CONTEXTSCHEMA'); + expect(mock_activate).toBeCalled(); + mock_activate('parent', 'EVENT'); + expect(mock_activate).toBeCalled(); + mock_activate('parent', 'TASK'); + expect(mock_activate).toBeCalled(); + mock_activate('parent', 'POLICY'); + expect(mock_activate).toBeCalled(); + mock_activate('parent', 'CONTEXTALBUM'); + expect(mock_activate).toBeCalled(); + mock_activate('parent', ''); + expect(mock_activate).toBeCalled(); +}); + +test('Test rightClickMenuDelete when Type is CONTEXTSCHEMA or EVENT or TASK or POLICY or CONTEXTALBUM or EMPTY', () => { + jest.spyOn(apexContextEdit, 'editContextSchemaForm_deleteContextSchema').mockReturnValueOnce(null); + jest.spyOn(apexEventEdit, 'editEventForm_deleteEvent').mockReturnValueOnce(null); + jest.spyOn(apexTaskEdit, 'editTaskForm_deleteTask').mockReturnValueOnce(null); + jest.spyOn(apexPolicyEdit, 'editPolicyForm_deletePolicy').mockReturnValueOnce(null); + jest.spyOn(apexContextAlbumEdit, 'editContextAlbumForm_deleteContextAlbum').mockReturnValueOnce(null); + const mock_activate = jest.fn(mod.rightClickMenuDelete); + mock_activate('parent', 'CONTEXTSCHEMA'); + expect(mock_activate).toBeCalled(); + mock_activate('parent', 'EVENT'); + expect(mock_activate).toBeCalled(); + mock_activate('parent', 'TASK'); + expect(mock_activate).toBeCalled(); + mock_activate('parent', 'POLICY'); + expect(mock_activate).toBeCalled(); + mock_activate('parent', 'CONTEXTALBUM'); + expect(mock_activate).toBeCalled(); + mock_activate('parent', ''); + expect(mock_activate).toBeCalled(); +});
\ No newline at end of file diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/showhideTextArea.test.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/showhideTextArea.test.js new file mode 100644 index 0000000..3a72037 --- /dev/null +++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/showhideTextArea.test.js @@ -0,0 +1,48 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +const mod = require('../showhideTextarea'); + +test('Test showHideTextarea_display_hide', () => { + let documentSpy = jest.spyOn(document, 'getElementById'); + let element_text = document.createElement("text_textarea"); + let element_showHide = document.createElement("text_showhide"); + documentSpy.mockReturnValue(element_text); + documentSpy.mockReturnValue(element_showHide); + const mock_activate = jest.fn(mod.showHideTextarea_display_hide); + mock_activate('text'); + expect(mock_activate).toBeCalled(); +}); + +test('Test showHideTextarea_display_show', () => { + let documentSpy = jest.spyOn(document, 'getElementById'); + let element_text = document.createElement("text_textarea"); + let element_showHide = document.createElement("text_showhide"); + documentSpy.mockReturnValue(element_text); + documentSpy.mockReturnValue(element_showHide); + const mock_activate = jest.fn(mod.showHideTextarea_display_show); + mock_activate('text'); + expect(mock_activate).toBeCalled(); +}); + + + + + diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/contextMenu.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/contextMenu.js index 1235cf1..8cd6a80 100644 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/contextMenu.js +++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/contextMenu.js @@ -1,7 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020-2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -231,5 +231,5 @@ function mouseY(evt) { } export { - rightClickMenu_scopePreserver + rightClickMenu_scopePreserver,rightClickMenu,rightClickMenuCreate,rightClickMenuView,rightClickMenuEdit,rightClickMenuDelete } |