diff options
author | 2021-10-27 09:35:15 +0000 | |
---|---|---|
committer | 2021-10-27 09:35:15 +0000 | |
commit | 5bd5e5a0e64afff9c285860f1f5069e6acc25d67 (patch) | |
tree | ce4d9f84435f9d43645d55106f16622405f7794b /gui-editors/gui-editor-apex/src | |
parent | a8140d3db5264bbc9dfd513c51d78951b42c6c37 (diff) | |
parent | e433e7621b8c0f235a3e4c67e528afe426e161f4 (diff) |
Merge "Improved Test Coverage in gui-editor-apex"
Diffstat (limited to 'gui-editors/gui-editor-apex/src')
7 files changed, 235 insertions, 5 deletions
diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexPolicyEditForm.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexPolicyEditForm.js index df0ddf0..4c53959 100644 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexPolicyEditForm.js +++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexPolicyEditForm.js @@ -27,6 +27,7 @@ import {policyTab_reset} from "./ApexPolicyTab"; import { editPolicyForm_State_generateStateDiv, editPolicyForm_State_getStateBean } from "./ApexPolicyEditForm_State"; import { formUtils_generateDescription, formUtils_generateUUID } from "./ApexFormUtils"; import {keyInformationTab_reset} from "./ApexKeyInformationTab"; +import {showHideElement} from "./showhideElement" function editPolicyForm_createPolicy(formParent) { editPolicyForm_editPolicy_inner(formParent, null, "CREATE"); diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexTaskEditForm.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexTaskEditForm.js index 5503064..4932de6 100644 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexTaskEditForm.js +++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexTaskEditForm.js @@ -26,6 +26,7 @@ import { ajax_delete, ajax_getWithKeyInfo, ajax_post, ajax_put, ajax_get } from import { formUtils_generateDescription, formUtils_generateUUID } from "./ApexFormUtils"; import { apexUtils_removeElement, apexUtils_emptyElement, apexUtils_areYouSure, createAddFormButton, scrollToTop } from "./ApexUtils"; import { showHideTextarea } from "./showhideTextarea"; +import {keyInformationTab_reset} from "./ApexKeyInformationTab"; function editTaskForm_createTask(formParent) { // Get all contextSchemas too for task input/outputfields diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexPolicyEditForm.test.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexPolicyEditForm.test.js index f438305..b3153a9 100644 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexPolicyEditForm.test.js +++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexPolicyEditForm.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. @@ -16,7 +16,10 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ - +const apexUtils = require('../ApexUtils'); +const apexPageControl = require('../ApexPageControl'); +const apexPolicyTab = require('../ApexPolicyTab'); +const keyInformationTab_reset = require('../ApexKeyInformationTab'); const mod = require('../ApexPolicyEditForm'); const policy = { policyKey: { @@ -26,8 +29,121 @@ const policy = { }, uuid: 'testUUID' } +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 Create Policy', () => { + const mock_activate = jest.fn(mod.editPolicyForm_createPolicy); + mock_activate('test'); + expect(mock_activate).toBeCalled(); +}); + +test('Test Delete Policy', () => { + 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(apexPageControl, 'pageControl_successStatus').mockReturnValueOnce(policy); + jest.spyOn(apexPolicyTab, 'policyTab_reset').mockReturnValueOnce(null); + jest.spyOn(keyInformationTab_reset, 'keyInformationTab_reset').mockReturnValueOnce(null); + jest.spyOn(apexUtils, 'apexUtils_removeElement').mockReturnValueOnce(null); + const mock_activate = jest.fn(mod.editPolicyForm_deletePolicy); + mock_activate('test', policy.policyKey.name, policy.policyKey.version); + expect(mock_activate).toBeCalled(); +}); + +test('Test View Policy', () => { + const jqXHR = { status: 200, responseText: "" }; + $.ajax = jest.fn().mockImplementation((args) => { + args.success(data, null, jqXHR); + }); + jest.spyOn(apexPageControl, 'pageControl_successStatus').mockReturnValueOnce(policy); + const mock_activate = jest.fn(mod.editPolicyForm_viewPolicy); + mock_activate('test', policy.policyKey.name, policy.policyKey.version); + expect(mock_activate).toBeCalled(); +}); + +test('Test Edit Policy', () => { + const jqXHR = { status: 200, responseText: "" }; + $.ajax = jest.fn().mockImplementation((args) => { + args.success(data, null, jqXHR); + }); + const mock_activate = jest.fn(mod.editPolicyForm_editPolicy); + mock_activate('test', policy.policyKey.name, policy.policyKey.version); + expect(mock_activate).toBeCalled(); +}); + +test('Test Edit Policy Inner', () => { + const jqXHR = { status: 200, responseText: "" }; + $.ajax = jest.fn().mockImplementation((args) => { + args.success(data, null, jqXHR); + }); + jest.spyOn(apexPageControl, 'pageControl_successStatus').mockReturnValueOnce(policy); + jest.spyOn(apexUtils, 'apexUtils_removeElement').mockReturnValueOnce(null); + const mock_activate = jest.fn(mod.editPolicyForm_editPolicy_inner); + mock_activate('test', policy, 'view'); + expect(mock_activate).toBeCalled(); +}); + +test('Test Add New State Policy', () => { + let documentSpy = jest.spyOn(document, 'getElementById'); + let elementMock = document.createElement("editEventFormNewStateInput"); + elementMock.value = 'one' + documentSpy.mockReturnValue(elementMock); + const mock_activate = jest.fn(mod.editPolicyForm_addNewState); + const node = document.body.parentNode; + mock_activate(node, 'New State', policy, 'tasks', 'events', 'contextS', 'contextI'); + expect(mock_activate).toBeCalled(); +}); + +test('Test Add State Policy', () => { + const mock_activate = jest.fn(mod.editPolicyForm_addState); + mock_activate('state','test', 'CREATE', policy, 'tasks', 'events', 'contextS', 'contextI'); + expect(mock_activate).toBeCalled(); +}); + +test('Test Generate Description', () => { + const mock_activate = jest.fn(mod.editPolicyForm_generateDescriptionPressed); + mock_activate(); + expect(mock_activate).toBeCalled(); +}); + +test('Test Submit Pressed', () => { + jest.spyOn(apexUtils, 'apexUtils_removeElement').mockReturnValueOnce(null); + jest.spyOn(apexPolicyTab, 'policyTab_reset').mockReturnValueOnce(null); + const mock_activate = jest.fn(mod.editPolicyForm_submitPressed); + mock_activate(); + expect(mock_activate).toBeCalled(); +}); + +test('Test Submit Pressed When createEditOrView is CREATE', () => { + let documentSpy = jest.spyOn(document, 'getElementById'); + let editPolicyFormElementMock = document.createElement("editPolicyForm"); + editPolicyFormElementMock.setAttribute("createEditOrView", "CREATE") + documentSpy.mockReturnValue(editPolicyFormElementMock) + const mock_activate = jest.fn(mod.editPolicyForm_submitPressed); + mock_activate(); + expect(mock_activate).toBeCalled(); +}); + +test('Test Update Trigger Event', () => { + const mock_activate = jest.fn(mod.editPolicyForm_updateTriggerEventOptions); + mock_activate('events'); + expect(mock_activate).toBeCalled(); +}); test('Test activate CREATE', () => { + jest.spyOn(apexUtils, 'apexUtils_removeElement').mockReturnValueOnce(null); const mock_activate = jest.fn(mod.editPolicyForm_activate); mock_activate('test', 'CREATE', policy, 'tasks', 'events', 'contextS', 'contextI'); @@ -35,6 +151,7 @@ test('Test activate CREATE', () => { }); test('Test activate EDIT', () => { + jest.spyOn(apexUtils, 'apexUtils_removeElement').mockReturnValueOnce(null); const mock_activate = jest.fn(mod.editPolicyForm_activate); mock_activate('test', 'EDIT', policy, 'tasks', 'events', 'contextS', 'contextI'); @@ -42,6 +159,7 @@ test('Test activate EDIT', () => { }); test('Test activate !CREATE/EDIT', () => { + jest.spyOn(apexUtils, 'apexUtils_removeElement').mockReturnValueOnce(null); const mock_activate = jest.fn(mod.editPolicyForm_activate); mock_activate('test', 'TEST', policy, 'tasks', 'events', 'contextS', 'contextI'); @@ -49,7 +167,8 @@ test('Test activate !CREATE/EDIT', () => { }); test('Test editPolicyForm_editPolicy_inner', () => { - const mock_editPolicyForm_editPolicy_inner = jest.fn(mod.editPolicyForm_editPolicy_inner); + jest.spyOn(apexUtils, 'apexUtils_removeElement').mockReturnValueOnce(null); + const mock_editPolicyForm_editPolicy_inner = jest.fn(mod.editPolicyForm_editPolicy_inner); mock_editPolicyForm_editPolicy_inner('formParent', policy, 'VIEW'); expect(mock_editPolicyForm_editPolicy_inner).toBeCalled(); })
\ No newline at end of file diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexTaskEditForm.test.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexTaskEditForm.test.js index f914645..ee90136 100644 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexTaskEditForm.test.js +++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexTaskEditForm.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,9 @@ */ const mod = require('../ApexTaskEditForm'); +const apexUtils = require('../ApexUtils'); +const apexTaskTab = require('../ApexTaskTab'); +const keyInformationTab_reset = require('../ApexKeyInformationTab'); const contextSchema = { name: 'testName', @@ -37,6 +40,17 @@ const task = { uuid: 'testUUID' }; +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 editTaskForm_activate CREATE', () => { const mock_activate = jest.fn(mod.editTaskForm_activate); mock_activate('test', 'CREATE', 'task', contextSchema, 'album'); @@ -48,3 +62,42 @@ test('Test editTaskForm_activate EDIT', () => { mock_activate('test', 'EDIT', task, contextSchema, 'album'); expect(mock_activate).toBeCalled(); }); + +test('Test Create Task', () => { + const jqXHR = { status: 200, responseText: "" }; + $.ajax = jest.fn().mockImplementation((args) => { + args.success(data, null, jqXHR); + }); + const mock_activate = jest.fn(mod.editTaskForm_createTask); + mock_activate('test'); + expect(mock_activate).toBeCalled(); +}); + +test('Test Delete Task', () => { + 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(apexTaskTab, 'taskTab_reset').mockReturnValueOnce(null); + jest.spyOn(keyInformationTab_reset, 'keyInformationTab_reset').mockReturnValueOnce(null); + jest.spyOn(apexUtils, 'apexUtils_removeElement').mockReturnValueOnce(null); + const mock_activate = jest.fn(mod.editTaskForm_deleteTask); + mock_activate('test'); + expect(mock_activate).toBeCalled(); +}); + +test('Test Edit Task Inner', () => { + const jqXHR = { status: 200, responseText: "" }; + $.ajax = jest.fn().mockImplementation((args) => { + args.success(data, null, jqXHR); + }); + const mock_activate = jest.fn(mod.editTaskForm_editTask_inner); + mock_activate('test', 'name', 'version', 'Edit'); + expect(mock_activate).toBeCalled(); +}); + + + + diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexTaskTab.test.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexTaskTab.test.js index 784c644..f593bd8 100644 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexTaskTab.test.js +++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexTaskTab.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,7 +20,26 @@ const mod = require('../ApexTaskTab'); +let data = { + messages: { + message: [ + '{"apexContextSchema": {"key":{"name": "name1", "version": "version1"}}, "apexTask":{"key":{"name": "name1", "version": "version1"},' + + '"taskLogic":{"logicFlavour":"logicFlavour"},"inputFields":{"entry": [{"key":"","value":{"fieldSchemaKey":{"name":"name"}}}]},' + + '"outputFields":{"entry": [{"key":"","value":{"fieldSchemaKey":{"name":"name"}}}]},' + + '"taskParameters":{"entry": [{"key":"","value":{"fieldSchemaKey":{"name":"name"}}}]},'+ + '"contextAlbumReference":[{"name":"name", "version":"version"}]},'+ + '"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 dom : taskTab_activate', () => { + const jqXHR = { status: 200, responseText: "" }; + $.ajax = jest.fn().mockImplementation((args) => { + args.success(data, null, jqXHR); + }); const activate_mock = jest.fn(mod.taskTab_activate); activate_mock(); expect(activate_mock).toBeCalled(); diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/showhideElement.test.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/showhideElement.test.js new file mode 100644 index 0000000..4e4e811 --- /dev/null +++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/showhideElement.test.js @@ -0,0 +1,32 @@ +/* + * ============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('../showhideElement'); + +test('Test editTaskForm_activate CREATE', () => { + const mock_activate = jest.fn(mod.showHideElement_display); + let documentSpy = jest.spyOn(document, 'getElementById'); + mock_activate(documentSpy, 'element', 'style', 'hidestyle', 'buttonshowStyle','buttonhideStyle'); + expect(mock_activate).toBeCalled(); +}); + + + + diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/showhideElement.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/showhideElement.js index d7259b1..8d9afa8 100644 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/showhideElement.js +++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/showhideElement.js @@ -59,3 +59,8 @@ function showHideElement(id_prefix, element, _initialhide, _showText, _hideText, return retdiv; } +export { + showHideElement_display, + showHideElement +} + |