diff options
author | 2022-02-15 18:02:23 +0000 | |
---|---|---|
committer | 2022-02-16 15:26:38 +0000 | |
commit | 770049ea162573d5afa1aaefed6131fe5e0a77f7 (patch) | |
tree | f702a09afd7b18879a562674c760c682c78895c0 /gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__ | |
parent | 29df248caa234bc0dff3c20875bdaecfeba127e0 (diff) |
Refactor apex-editor frontend build
Moved frontend from src/main/resources/webapp to src/main/webapp
Moved static resources such as jquery-ui to webapp/dist folder
Configured jest to exclude webapp/dist from coverage report
Removed unused ZIP file assembly
Cleaned up POM
Issue-ID: POLICY-3896
Signed-off-by: danielhanrahan <daniel.hanrahan@est.tech>
Change-Id: Ia006eb94a39586219029866eef94aef38912ad65
Diffstat (limited to 'gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__')
28 files changed, 0 insertions, 2779 deletions
diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexAjax.test.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexAjax.test.js deleted file mode 100644 index dadbaa0..0000000 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexAjax.test.js +++ /dev/null @@ -1,207 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * 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. - * 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('../ApexAjax'); - -const requestURL = "http://localhost:7979"; -let data = {}; - -beforeEach(() => { - data = { - useHttps: 'useHttps', - hostname: 'hostname', - port: 'port', - username: 'username', - password: 'password', - messages: { - message: '' - }, - content: ['01', '02'], - result: 'ok', - ok: true - }; -}); - -test('Test ajax_get error', () => { - const callback = jest.fn(); - $.ajax = jest.fn().mockImplementation((args) => { - args.error(data, null, null); - }); - const mock_get_error = jest.fn(mod.ajax_get(requestURL, callback)); - mock_get_error(); - expect(mock_get_error).toHaveBeenCalled(); -}); - -test('Test ajax_get success', (done) => { - const callback = jest.fn((actualData) => { - expect(actualData).toEqual(data); - done(); - }); - const jqXHR = { status: 200, responseText: "" }; - $.ajax = jest.fn().mockImplementation((args) => { - args.success(data, null, jqXHR); - }); - mod.ajax_get(requestURL, callback); -}); - -test('Test ajax_getWithKeyInfo success', (done) => { - const myCallback = jest.fn((actual) => { - expect(actual).toEqual({ - key: { - name: "name1", - version: "version1" - }, - uuid: "UUID1", - description: "description1" - }); - done(); - }); - data.messages = { - message: [ - '{"apexKeyInfo": {"UUID": "UUID1", "description": "description1", "key":{"name": "name1", "version":' + - ' "version1"}}, "objectType": {"key": {"name": "name1", "version": "version1"}}}' - ] - }; - const jqXHR = {status: 200, responseText: ""}; - - $.ajax = jest.fn().mockImplementation((args) => { - args.success(data, null, jqXHR); - }); - mod.ajax_getWithKeyInfo("requestUrl", "objectType", myCallback, undefined); -}); - -test('Test ajax_getWithKeyInfo with custom key success', (done) => { - const myCallback = jest.fn((actual) => { - expect(actual).toEqual({ - customKey: { - name: "name1", - version: "version1" - }, - uuid: "UUID1", - description: "description1" - }); - done(); - }); - data.messages = { - message: [ - '{"apexKeyInfo": {"UUID": "UUID1", "description": "description1", "key":{"name": "name1",' + - ' "version": "version1"}}, "objectType": {"customKey": {"name": "name1", "version": "version1"}}}' - ] - }; - const jqXHR = {status: 200, responseText: ""}; - - $.ajax = jest.fn().mockImplementation((args) => { - args.success(data, null, jqXHR); - }); - mod.ajax_getWithKeyInfo("requestUrl", "objectType", myCallback, "customKey"); -}); - -test('Test ajax_delete error', () => { - const callback = jest.fn(); - const jqXHR = { status: 500, responseText: "" }; - $.ajax = jest.fn().mockImplementation((args) => { - args.error(jqXHR, null, null); - }); - const mock_delete_error = jest.fn(mod.ajax_delete(requestURL, callback)); - mock_delete_error(); - expect(mock_delete_error).toHaveBeenCalled(); -}); - -test('Test ajax_delete success', (done) => { - const callback = jest.fn((actualData) => { - expect(actualData).toEqual(data); - done(); - }); - const jqXHR = { status: 200, responseText: "" }; - $.ajax = jest.fn().mockImplementation((args) => { - args.success(data, null, jqXHR); - }); - mod.ajax_delete(requestURL, callback); -}); - -test('Test ajax_post error', () => { - const callback = jest.fn(); - const jqXHR = { status: 500, responseText: "" }; - $.ajax = jest.fn().mockImplementation((args) => { - args.error(jqXHR, null, null); - }); - const mock_post_error = jest.fn(mod.ajax_post(requestURL, data, callback)); - mock_post_error(); - expect(mock_post_error).toHaveBeenCalled(); -}); - -test('Test ajax_post success', (done) => { - const callback = jest.fn((actualData) => { - expect(actualData).toEqual(data); - done(); - }); - const jqXHR = { status: 200, responseText: "" }; - $.ajax = jest.fn().mockImplementation((args) => { - args.success(data, null, jqXHR); - }); - mod.ajax_post(requestURL, data, callback); -}); - -test('Test ajax_put error', () => { - const callback = jest.fn(); - const jqXHR = { status: 500, responseText: "" }; - $.ajax = jest.fn().mockImplementation((args) => { - args.error(jqXHR, null, null); - }); - const mock_put_error = jest.fn(mod.ajax_put(requestURL, callback)); - mock_put_error(); - expect(mock_put_error).toHaveBeenCalled(); -}); - -test('Test ajax_put success', (done) => { - const callback = jest.fn((actualData) => { - expect(actualData).toEqual(data); - done(); - }); - const jqXHR = { status: 200, responseText: "" }; - - $.ajax = jest.fn().mockImplementation((args) => { - args.success(data, null, jqXHR); - }); - mod.ajax_put(requestURL, data, callback); -}); - -test('Test ajax_getOKOrFail error', () => { - const callback = jest.fn(); - const jqXHR = { status: 500, responseText: "" }; - $.ajax = jest.fn().mockImplementation((args) => { - args.error(jqXHR, null, null); - }); - const mock_getOKOrFail_error = jest.fn(mod.ajax_getOKOrFail(requestURL, callback)); - mock_getOKOrFail_error(); - expect(mock_getOKOrFail_error).toHaveBeenCalled(); -}); - -test('Test ajax_getOKOrFail success', (done) => { - const callback = jest.fn((actualData) => { - expect(actualData).toEqual(data); - done(); - }); - const jqXHR = { status: 200, responseText: "" }; - - $.ajax = jest.fn().mockImplementation((args) => { - args.success(data, null, jqXHR); - }); - mod.ajax_getOKOrFail(requestURL, callback); -}); 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 deleted file mode 100644 index 8bc3ed0..0000000 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexContextAlbumEditForm.test.js +++ /dev/null @@ -1,144 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2020-2022 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('../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); - - const contextAlbum = { - name: 'testName', - version: '0.0.1', - scope: 'test', - uuid: 'testUUID', - description: 'testDesc', - writeable: true - }; - const contextSchema = { - name: 'testName', - version: '0.0.1', - schemaFlavour: 'testFlav', - schemaDefinition: 'testDef', - uuid: 'testUUID', - description: 'testDesc' - } - - 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(); -}); - -test('Test editContextAlbumForm_cancelPressed', () => { - jest.spyOn(apexUtils, 'apexUtils_removeElement').mockReturnValue(null); - 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(); -}); diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexContextAlbumTab.test.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexContextAlbumTab.test.js deleted file mode 100644 index e109174..0000000 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexContextAlbumTab.test.js +++ /dev/null @@ -1,27 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2020 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('../ApexContextAlbumTab'); -const utils = require('../ApexUtils'); - -test('Test contextAlbumTab_create', () => { - const mock_activate = jest.fn(mod.contextAlbumTab_activate); - mock_activate(); - expect(mock_activate).toBeCalled(); -}); 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 deleted file mode 100644 index 87b4f82..0000000 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexContextSchemaEditForm.test.js +++ /dev/null @@ -1,110 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * 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. - * 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('../ApexContextSchemaEditForm'); -const apexUtils = require('../ApexUtils'); -const apexContextSchemaTab = require('../ApexContextSchemaTab'); -const keyInformationTab_reset = require('../ApexKeyInformationTab'); -const apexAjax = require('../ApexAjax'); -const formUtils_generateDescription = require('../ApexFormUtils'); - -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 deleted file mode 100644 index 3883bd5..0000000 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexContextSchemaTab.test.js +++ /dev/null @@ -1,54 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * 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. - * 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('../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(); -}); - -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 deleted file mode 100644 index 48573e8..0000000 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexEventEditForm.test.js +++ /dev/null @@ -1,193 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2020-2022 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('../ApexEventEditForm'); -const eventTab_reset = require('../ApexEventTab'); -const apexUtils = require('../ApexUtils'); -const formUtils_generateDescription = require('../ApexFormUtils'); -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', - schemaFlavour: 'testFlav', - schemaDefinition: 'testDef', - uuid: 'testUUID', - description: 'testDesc' -} - -const parentTBody = document.createElement('table'); - -test('Test Activate', () => { - const mock_activate = jest.fn(mod.editEventForm_activate); - mock_activate(null, 'CREATE', null, contextSchema); - expect(mock_activate).toBeCalled(); -}); - -test('Test Activate Edit', () => { - - const event = { - key: { - name: 'testName', - version: '0.0.1', - }, - nameSpace: 'test', - source: 'test', - target: 'test', - uuid: 'test', - description: 'test', - } - - const mock_activate = jest.fn(mod.editEventForm_activate); - mock_activate(null, 'EDIT', event, contextSchema); - expect(mock_activate).toBeCalled(); -}); - -test('Test Activate !=Create/Edit', () => { - - const event = { - key: { - name: 'testName', - version: '0.0.1', - }, - nameSpace: 'test', - source: 'test', - target: 'test', - uuid: 'test', - description: 'test', - } - - 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(); -}); - -test('Test editEventForm_addEventParam', () => { - let contextSchemas = new Array(); - contextSchemas.push(contextSchema); - const mock_activate = jest.fn(mod.editEventForm_addEventParam); - mock_activate(parentTBody, false, 'name', null, contextSchema, contextSchemas); - expect(mock_activate).toBeCalled(); -}); - -test('Test Edit Event Generate UUID Pressed', () => { - let documentSpy = jest.spyOn(document, 'getElementById'); - let elementMock = document.createElement("editContextSchemaFormDescriptionTextArea"); - documentSpy.mockReturnValue(elementMock); - const mock_activate = jest.fn(mod.editEventForm_generateUUIDPressed); - mock_activate(); - expect(mock_activate).toBeCalled(); -}); - -test('Test Edit Event Generate Description Pressed', () => { - jest.spyOn(formUtils_generateDescription, 'formUtils_generateDescription').mockReturnValueOnce(null); - let documentSpy = jest.spyOn(document, 'getElementById'); - let elementMock = document.createElement("editContextSchemaFormDescriptionTextArea"); - documentSpy.mockReturnValue(elementMock); - const mock_activate = jest.fn(mod.editEventForm_generateDescriptionPressed); - mock_activate(); - expect(mock_activate).toBeCalled(); -}); -test('Test editEventForm_cancelPressed', () => { - 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_cancelPressed); - mock_activate(); - expect(mock_activate).toBeCalled(); -}); - -test('Test editTaskForm_submitPressed', () => { - jest.spyOn(keyInformationTab_reset, 'keyInformationTab_reset').mockReturnValueOnce(null); - jest.spyOn(apexUtils, 'apexUtils_removeElement').mockReturnValueOnce(null); - jest.spyOn(eventTab_reset, 'eventTab_reset').mockReturnValueOnce(null); - - let documentSpy = jest.spyOn(document, 'getElementById'); - let elementMock = document.createElement("editEventForm"); - elementMock.setAttribute("createEditOrView", "CREATE"); - elementMock.value = 'name_version' - elementMock.rows = 2 - documentSpy.mockReturnValue(elementMock); - - const mock_activate = jest.fn(mod.editEventForm_submitPressed); - mock_activate(); - expect(mock_activate).toBeCalled(); -}); diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexEventTab.test.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexEventTab.test.js deleted file mode 100644 index 16042af..0000000 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexEventTab.test.js +++ /dev/null @@ -1,119 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * 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. - * 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('../ApexEventTab'); -const ApexUtils = require('../ApexUtils'); - -afterEach(() => { - document.body.innerHTML = ''; -}); - -test('Test activate', () => { - document.body.innerHTML = '<div id="eventsTab"></div>'; - - const data = { - useHttps: 'useHttps', - hostname: 'hostname', - port: 'port', - username: 'username', - password: 'password', - messages: { - message: [ - '{"apexEvent" : {"key": {"name": "name1", "version":"version1"}, "nameSpace":"nameSpace1",' + - ' "source":"source1", "target":"target1", "parameter": ' + - '{"entry": [{"key": "key1", "value": {"optional":"optional", "fieldSchemaKey": ' + - '{"name": "name2", "version":"version2"}}}]}}}' - ] - }, - content: ['01', '02'], - result: 'ok', - ok: true - }; - - $.ajax = jest.fn().mockImplementation((args) => { - args.success(data, null, null); - }); - - const expected = '<div id="eventsTab"><eventtabcontent id="eventTabContent">' + - '<table id="eventTableBody" class="apexTable ebTable elTablelib-Table-table ebTable_striped">' + - '<thead id="eventTableHeader"><tr id="eventTableHeaderRow">' + - '<th id="eventTableKeyHeader">Event</th>' + - '<th id="eventTableNamespaceHeader">Name Space</th>' + - '<th id="eventTableSourceHeader">Source</th>' + - '<th id="eventTableTargetHeader">Target</th>' + - '<th id="eventTableParameterHeader">Parameters</th>' + - '</tr></thead>' + - '<tbody><tr>' + - '<td>name1:version1</td>' + - '<td>nameSpace1</td>' + - '<td>source1</td>' + - '<td>target1</td>' + - '<td><table class="ebTable">' + - '<thead><tr><th>Parameter</th><th>Parameter Type/Schema</th><th>Optional</th></tr></thead>' + - '<tbody><tr><td>key1</td><td>name2:version2</td><td>optional</td></tr></tbody></table></td></tr></tbody>' + - '</table></eventtabcontent></div>'; - - mod.eventTab_activate(); - expect(document.body.innerHTML).toBe(expected); -}); - -test('Test deactivate', (done) => { - ApexUtils.apexUtils_removeElement = jest.fn(id => { - expect(id).toBe('eventTabContent'); - done() - }); - mod.eventTab_deactivate(); -}); - - -test('Test create eventTabContent exists', () => { - document.body.innerHTML = '<div id="eventsTab"><div id="eventTabContent"></div></div>'; - mod.eventTab_create(); - expect(document.body.innerHTML).toBe('<div id="eventsTab"><div id="eventTabContent"></div></div>'); -}); - -test('Test create eventsTab does not exist', () => { - document.body.innerHTML = '<div></div>'; - mod.eventTab_create(); - expect(document.body.innerHTML).toBe('<div></div>'); -}); - -test('Test create', () => { - document.body.innerHTML = '<div id="eventsTab"></div>'; - - const expected = '<div id="eventsTab"><eventtabcontent id="eventTabContent">' + - '<table id="eventTableBody" class="apexTable ebTable elTablelib-Table-table ebTable_striped">' + - '<thead id="eventTableHeader"><tr id="eventTableHeaderRow">' + - '<th id="eventTableKeyHeader">Event</th>' + - '<th id="eventTableNamespaceHeader">Name Space</th>' + - '<th id="eventTableSourceHeader">Source</th>' + - '<th id="eventTableTargetHeader">Target</th>' + - '<th id="eventTableParameterHeader">Parameters</th>' + - '</tr></thead><tbody></tbody></table>' + - '</eventtabcontent></div>'; - - mod.eventTab_create(); - expect(document.body.innerHTML).toBe(expected); -}); - - -// These are being tested indirectly -// But could be tested individually here if needed -test.todo('Test reset'); 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 deleted file mode 100644 index f5be3cc..0000000 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexFiles.test.js +++ /dev/null @@ -1,57 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * 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. - * 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('../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); - open(); - expect(open).toBeCalledTimes(1); -}); - -test('test files_download', () => { - const download = jest.fn(mod.files_fileDownload); - download(); - expect(download).toHaveBeenCalledTimes(1); -}); - -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(); -});
\ No newline at end of file diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexFormUtils.test.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexFormUtils.test.js deleted file mode 100644 index 0df839d..0000000 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexFormUtils.test.js +++ /dev/null @@ -1,35 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2020 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('../ApexFormUtils'); - -test('test generate', () => { - const mock = jest.fn(mod.formUtils_generateUUID); - mock(); - expect(mock).toBeCalledTimes(1); -}) - -test('test edit', () => { - const mock = jest.fn(mod.formUtils_generateDescription); - mock(); - expect(mock(null, null, null)).toBe("Generated description for a concept called \"null\" with version \"null\" and UUID \"null\""); - expect(mock).toBeCalledTimes(2); - - -})
\ No newline at end of file diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexKeyInformationTab.test.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexKeyInformationTab.test.js deleted file mode 100644 index 2dcc7c2..0000000 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexKeyInformationTab.test.js +++ /dev/null @@ -1,76 +0,0 @@ -/* - * ============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 ApexUtils = require("../ApexUtils"); -const ApexKeyInformationTab = require("../ApexKeyInformationTab"); - -test("Test keyInformationTab_activate", () => { - document.body.innerHTML = '<div id ="keyInformationTab"></div>'; - const data = { - useHttps: 'useHttps', - hostname: 'hostname', - port: 'port', - username: 'username', - password: 'password', - messages: { - message: [ - '{"apexKeyInfo": {"UUID": "UUID1", "description": "description1", "key":{"name": "name1", "version":' + - ' "version1"}}, "objectType": {"key": {"name": "name1", "version": "version1"}}}' - ] - }, - content: ['01', '02'], - result: 'ok', - ok: true - }; - $.ajax = jest.fn().mockImplementation((args) => { - args.success(data, null, null); - }); - ApexKeyInformationTab.keyInformationTab_activate(); - - const actual = document.getElementById("keyInformationTabContent"); - const expected = /<td>name1:version1<\/td><td><uuid>UUID1<\/uuid><\/td><td><desc>description1<\/desc><\/td>/; - expect(actual.innerHTML).toMatch(expected); -}); - -test("Test keyInformationTab_deactivate", (done) => { - ApexUtils.apexUtils_removeElement = jest.fn((id) => { - expect(id).toBe("keyInformationTabContent"); - done(); - }); - ApexKeyInformationTab.keyInformationTab_deactivate() -}) - -test("Test keyInformationTab_create, key information tab exists", () => { - document.body.innerHTML = '<div id ="keyInformationTabContent"></div>'; - - ApexKeyInformationTab.keyInformationTab_create(); - const actual = document.getElementById("keyInformationTab"); - expect(actual).toBeNull(); -}); - -test("Test keyInformationTab_create, ", () => { - document.body.innerHTML = '<div id ="keyInformationTab"></div>'; - - ApexKeyInformationTab.keyInformationTab_create(); - const actual = document.getElementById("keyInformationTabContent"); - const expected = '<table id="keyInformationTableBody" class="apexTable ebTable elTablelib-Table-table ebTable_striped"><thead id="keyInformationTableHeader"><tr id="keyInformationTableHeaderRow"><th id="keyInformationTableKeyHeader">Key Information</th><th id="keyInformationTableUUIDHeader">UUID</th><th id="keyInformationTableDescriptionHeader">Description</th></tr></thead><tbody></tbody></table>' - expect(actual.innerHTML).toBe(expected); -}); - - diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexMain.test.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexMain.test.js deleted file mode 100644 index b582b35..0000000 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexMain.test.js +++ /dev/null @@ -1,103 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2022 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('../ApexMain'); -const $ = require('jquery'); -const apexPageControl = 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'); - -require('../jquery-ui-1.12.1/jquery-ui.js'); - -const data = { - messages: { - message: [ - '{' + - ' "apexArtifactKey": {' + - ' "key": {' + - ' "name": "name1",' + - ' "version": "version1"' + - ' }' + - ' }' + - '}' - ] - }, - content: ['01', '02'], - result: 'ok', - ok: true -}; - -const jqXHR = { status: 200, responseText: "" }; - -test('Test main_getRestRootURL', () => { - document.documentElement.innerHTML = '<html><head></head><body>' + - '<div id="mainTabs"><ul><li><a href="#mainTabs1">Tab 1</a></li></ul></div>' + - '</body></html>'; - $.ajax = jest.fn().mockImplementation((args) => { - args.success(data, null, jqXHR); - }); - jest.spyOn(window.localStorage.__proto__, 'getItem'); - window.localStorage.__proto__.getItem = jest.fn(() => true); - jest.spyOn(apexPageControl, 'pageControl_modelMode').mockReturnValueOnce(null); - 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_main_getRestRootURL = jest.fn(mod.main_getRestRootURL); - mock_main_getRestRootURL(); - const expected = '<head></head><body>'+ - '<div id="mainTabs" class="ui-tabs ui-corner-all ui-widget ui-widget-content"><ul role="tablist" class="ui-tabs-nav ui-corner-all ui-helper-reset ui-helper-clearfix ui-widget-header">' + - '<li role="tab" tabindex="0" class="ui-tabs-tab ui-corner-top ui-state-default ui-tab ui-tabs-active ui-state-active" aria-controls="mainTabs1" aria-labelledby="ui-id-1" aria-selected="true" aria-expanded="true">' + - '<a href="#mainTabs1" role="presentation" tabindex="-1" class="ui-tabs-anchor" id="ui-id-1">Tab 1</a></li></ul></div></body>' - expect(mock_main_getRestRootURL).toBeCalled(); - expect(document.documentElement.innerHTML).toEqual(expected); -}); - -test('Test main_getRestRootURL false', () => { - document.documentElement.innerHTML = '<html><head></head><body><div class="ebInlineMessage-description" id="statusMessageTable"></div></body></html>'; - $.ajax = jest.fn().mockImplementation((args) => { - args.success(data, null, jqXHR); - }); - jest.spyOn(window.localStorage.__proto__, 'getItem'); - window.localStorage.__proto__.getItem = jest.fn(() => false); - const mock_main_getRestRootURL = jest.fn(mod.main_getRestRootURL); - mock_main_getRestRootURL(); - expect(mock_main_getRestRootURL).toBeCalled(); - expect(document.documentElement.innerHTML).toEqual('<head></head><body><div class="ebInlineMessage-description" id="statusMessageTable"><tr><td> REST root URL set to: http://localhost/apexservices/editor/false</td></tr></div></body>'); -}); - -test('Test clearLocalStorage', () => { - const mock_clearLocalStorage = jest.fn(mod.clearLocalStorage); - mock_clearLocalStorage(); - expect(mock_clearLocalStorage).toBeCalled(); -}); - -test('test ready', () => { - document.documentElement.innerHTML = '<html><head></head><body><ul id="menu li"><li><div>menu</div><ul><li><div>FileNew</div></li></ul></li></ul></body></html>'; - window.$ = $; - $("#menu li").click(); - let h1 = document.querySelector('ul'); - expect(h1.textContent).toEqual('menuFileNew'); -});
\ No newline at end of file diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexModelHandling.test.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexModelHandling.test.js deleted file mode 100644 index 2144506..0000000 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexModelHandling.test.js +++ /dev/null @@ -1,96 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * 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. - * 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('../ApexModelHandling'); -const ApexResultForm = require("../ApexResultForm"); - -afterEach(() => { - document.body.innerHTML = ''; -}); - -test('Test modelHandling_analyse', (done) => { - const data = { - useHttps: 'useHttps', - hostname: 'hostname', - port: 'port', - username: 'username', - password: 'password', - messages: { - message: [ - '{"apexKeyInfo": null}' - ] - }, - content: ['01'], - result: 'ok', - ok: true - }; - const expectedMessage = '{"apexKeyInfo": null}'; - document.body.innerHTML = '<div id="mainArea"></div>'; - - $.ajax = jest.fn().mockImplementation((args) => { - args.success(data, null, null); - }); - - ApexResultForm.resultForm_activate = jest.fn((element, heading, message) => { - expect(element).not.toBeNull(); - expect(heading).toBe('Model Analysis Result'); - expect(message).toBe(expectedMessage); - done(); - }); - - mod.modelHandling_analyse(); -}); - -test('Test modelHandling_validate', (done) => { - const data = { - useHttps: 'useHttps', - hostname: 'hostname', - port: 'port', - username: 'username', - password: 'password', - messages: { - message: [ - '{"apexKeyInfo": null}', - '{"apexPolicy": null}', - '{"apexEvent": null}' - ] - }, - content: ['01'], - result: 'ok', - ok: true - }; - - const expectedMessage = '{"apexPolicy": null}\n{"apexEvent": null}\n'; - - document.body.innerHTML = '<div id="mainArea"></div>'; - - $.ajax = jest.fn().mockImplementation((args) => { - args.success(data, null, null); - }); - - ApexResultForm.resultForm_activate = jest.fn((element, heading, message) => { - expect(element).not.toBeNull(); - expect(heading).toBe('Model Validation Result'); - expect(message).toBe(expectedMessage); - done(); - }); - - mod.modelHandling_validate(); -}); diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexNewModelForm.test.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexNewModelForm.test.js deleted file mode 100644 index 5088988..0000000 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexNewModelForm.test.js +++ /dev/null @@ -1,46 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2020 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('../ApexNewModelForm'); - -test('test activate', () => { - document.innerHTML = - '<div id="newModelFormDiv">' + - '</div>' + - '<div id="elementTest">' + - '</div>'; - - const mock_activate = jest.fn(mod.newModelForm_activate); - mock_activate(document.createElement("elementTest")); - expect(mock_activate).toBeCalled(); -}); - -test('Test generateUUIDPressed', () => { - document.innerHTML = - '<div id="newModelFormUuidInput"></div>'; - - const mock_generateUuid = jest.fn(mod.newModelForm_generateUUIDPressed); - mock_generateUuid.mockImplementation(() => { - document.createElement("newModelFormUuidInput"); - document.getElementsByTagName("newModelFormUuidInput").value = 'test'; - }); - mock_generateUuid(); - expect(mock_generateUuid).toBeCalled(); -});
\ No newline at end of file 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 deleted file mode 100644 index b414bb1..0000000 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexPageControl.test.js +++ /dev/null @@ -1,116 +0,0 @@ -/* - * ============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.test.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexPolicyEditForm.test.js deleted file mode 100644 index b3153a9..0000000 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexPolicyEditForm.test.js +++ /dev/null @@ -1,174 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * 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. - * 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 apexUtils = require('../ApexUtils'); -const apexPageControl = require('../ApexPageControl'); -const apexPolicyTab = require('../ApexPolicyTab'); -const keyInformationTab_reset = require('../ApexKeyInformationTab'); -const mod = require('../ApexPolicyEditForm'); -const policy = { - policyKey: { - name: 'testName', - version: 'testVersion', - uuid: 'testUUID' - }, - 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'); - expect(mock_activate).toBeCalled(); -}); - -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'); - expect(mock_activate).toBeCalled(); -}); - -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'); - expect(mock_activate).toBeCalled(); -}); - -test('Test 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__/ApexPolicyEditForm_State.test.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexPolicyEditForm_State.test.js deleted file mode 100644 index 8b73319..0000000 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexPolicyEditForm_State.test.js +++ /dev/null @@ -1,174 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2020-2022 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('../ApexPolicyEditForm_State'); - -const contextAlbum = { - name: 'testName', - version: '0.0.1', - scope: 'test', - uuid: 'testUUID', - description: 'testDesc', - writeable: true -}; -const contextSchema = { - name: 'testName', - version: '0.0.1', - schemaFlavour: 'testFlav', - schemaDefinition: 'testDef', - uuid: 'testUUID', - description: 'testDesc' -} - -const task = { - key: { - name: 'testName', - version: 'testVersion' - }, - uuid: 'testUUID' -}; - -const event = { - key: { - name: 'testName', - version: '0.0.1', - }, - nameSpace: 'test', - source: 'test', - target: 'test', - uuid: 'test', - description: 'test', -} - -const policy = { - policyKey: { - name: 'testName', - version: 'testVersion', - uuid: 'testUUID' - }, - uuid: 'testUUID' -} - -const state = { - trigger: { - name: 'testName', - version: '0.0.1', - } -} - -const parentTBody = document.createElement('table'); - -test('Test editPolicyForm_State_generateStateDiv CREATE', () => { - const mock_editPolicyForm_State_generateStateDiv = jest.fn(mod.editPolicyForm_State_generateStateDiv); - mock_editPolicyForm_State_generateStateDiv('CREATE', policy, 'stateName', state, task, event, contextAlbum, contextSchema); - expect(mock_editPolicyForm_State_generateStateDiv).toBeCalledWith('CREATE', policy, 'stateName', state, task, event, contextAlbum, contextSchema); -}); - -test('Test editPolicyForm_State_generateStateDiv VIEW', () => { - const mock_editPolicyForm_State_generateStateDiv = jest.fn(mod.editPolicyForm_State_generateStateDiv); - mock_editPolicyForm_State_generateStateDiv('VIEW', policy, 'stateName', state, task, event, contextAlbum, contextSchema); - expect(mock_editPolicyForm_State_generateStateDiv).toBeCalledWith('VIEW', policy, 'stateName', state, task, event, contextAlbum, contextSchema); -}); - -test('Test editPolicyForm_State_generateStateDiv EDIT', () => { - const mock_editPolicyForm_State_generateStateDiv = jest.fn(mod.editPolicyForm_State_generateStateDiv); - mock_editPolicyForm_State_generateStateDiv('EDIT', policy, 'stateName', state, task, event, contextAlbum, contextSchema); - expect(mock_editPolicyForm_State_generateStateDiv).toBeCalledWith('EDIT', policy, 'stateName', state, task, event, contextAlbum, contextSchema); -}); - -test('Test editPolicyForm_State_addStateLogicOutput', () => { - const mock_editPolicyForm_State_addStateLogicOutput = jest.fn(mod.editPolicyForm_State_addStateLogicOutput); - mock_editPolicyForm_State_addStateLogicOutput(parentTBody, false, 'stateName', state, 'outputName', 'logic', 'flavour'); - expect(mock_editPolicyForm_State_addStateLogicOutput).toBeCalledWith(parentTBody, false, 'stateName', state, 'outputName', 'logic', 'flavour'); -}); - -test('Test editPolicyForm_State_addStateDirectOutput', () => { - const mock_editPolicyForm_State_addStateDirectOutput = jest.fn(mod.editPolicyForm_State_addStateDirectOutput); - mock_editPolicyForm_State_addStateDirectOutput(parentTBody, false, 'stateName', state, 'outputName', state, event, 'options', event); - expect(mock_editPolicyForm_State_addStateDirectOutput).toBeCalledWith(parentTBody, false, 'stateName', state, 'outputName', state, event, 'options', event); -}); - -test('Test editPolicyForm_State_addPolicyContext', () => { - const mock_editPolicyForm_State_addPolicyContext = jest.fn(mod.editPolicyForm_State_addPolicyContext); - mock_editPolicyForm_State_addPolicyContext(parentTBody, false, 'stateName', 'contextName', 'ref', contextAlbum); - expect(mock_editPolicyForm_State_addPolicyContext).toBeCalledWith(parentTBody, false, 'stateName', 'contextName', 'ref', contextAlbum); -}); - -test('Test editPolicyForm_State_addPolicyTask', () => { - const mock_editPolicyForm_State_addPolicyTask = jest.fn(mod.editPolicyForm_State_addPolicyTask); - mock_editPolicyForm_State_addPolicyTask(parentTBody, false, false, state, 'stateName', 'ref', task, 'options'); - expect(mock_editPolicyForm_State_addPolicyTask).toBeCalledWith(parentTBody, false, false, state, 'stateName', 'ref', task, 'options'); - -}); - -test('Test editPolicyForm_State_getStateBean StateName is Null', () => { - jest.spyOn(global.console, 'error').mockImplementation(() => {}); - mod.editPolicyForm_State_getStateBean(null); - expect(console.error).toHaveBeenCalledTimes(2); - mod.editPolicyForm_State_getStateBean('FakeState'); - expect(console.error).toHaveBeenCalledTimes(4); - global.console.error.mockRestore(); -}); - -test('Test editPolicyForm_State_getLogicOutputMappingOptions with page', () => { - document.documentElement.innerHTML = '<html><head></head><body>' + - '<table id="editPolicyFormLogicOutputsTable_stateName"context_id="a0">' + - '<tr class="table" context_id="a1" output_id="b1" finalizer_id="c1" task_id="d1"><td>cell 1</td><td>cell 2</td></tr>' + - '<tr class="table" context_id="a2" output_id="b2" finalizer_id="c2" task_id="d2"><td>cell 3</td><td>cell4</td></tr>' + - '<tr class="table" context_id="a3" output_id="b3" finalizer_id="c3" task_id="d3"><td>cell 5</td><td>cell6</td></tr>' + - '</table>' + - '</body></html>'; - let documentSpy = jest.spyOn(document, 'getElementById'); - let elementMock = document.createElement("editPolicyFormLogicOutputsTable_stateName"); - elementMock.value = "localName"; - elementMock.rows = document.getElementById("editPolicyFormLogicOutputsTable_stateName").rows; - documentSpy.mockReturnValue(elementMock); - const mock_activate = jest.fn(mod.editPolicyForm_State_getLogicOutputMappingOptions); - mock_activate('stateName'); - expect(mock_activate).toBeCalledWith('stateName'); -}); - -test('Test editPolicyForm_State_getStateBean with page', () => { - document.documentElement.innerHTML = '<html><head></head><body>' + - '<div id="editPolicyFormStateDiv_stateName"></div>' + - '<div id="editPolicyFormTrigger_stateName_dropdownList"></div>' + - '<table id="editPolicyFormContextsTable_stateName"context_id="a0">' + - '<tr class="table" context_id="a1" output_id="b1" finalizer_id="c1" task_id="d1"><td>cell 1</td><td>cell 2</td></tr>' + - '<tr class="table" context_id="a2" output_id="b2" finalizer_id="c2" task_id="d2"><td>cell 3</td><td>cell4</td></tr>' + - '<tr class="table" context_id="a3" output_id="b3" finalizer_id="c3" task_id="d3"><td>cell 5</td><td>cell6</td></tr>' + - '</table>' + - '<form id="test"><label><input type="radio" name="editPolicyFormTaskOutputType_stateName_d2" value="LOGIC" checked>LOGIC</label></form>' + - '</body></html>'; - let documentSpy = jest.spyOn(document, 'getElementById'); - let elementMock = document.createElement("editPolicyFormDirOutputsTable_stateName"); - elementMock.setAttribute("context_id", "a0"); - elementMock.setAttribute("task_id", "d0"); - elementMock.rows = document.getElementById("editPolicyFormContextsTable_stateName").rows; - elementMock.key = {"name": "name1", "version": "version1"}; - elementMock.selectedOption = - {"name": "name1", "version": "version1", - "album": { "key": { "name": 'testAlbumName', "version": '0.0.1'}}, - "event": { "key": { "name": 'testEventName', "version": '0.1.1'}}, - "task": { "key": { "name": 'tname', "version": '1.0.0'}}}; - elementMock.value = "localName"; - documentSpy.mockReturnValue(elementMock); - const mock_activate = jest.fn(mod.editPolicyForm_State_getStateBean); - mock_activate('stateName'); - expect(mock_activate).toBeCalledWith('stateName'); -}); diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexPolicyTab.test.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexPolicyTab.test.js deleted file mode 100644 index 4136fd6..0000000 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexPolicyTab.test.js +++ /dev/null @@ -1,305 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * 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. - * 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('../ApexPolicyTab'); -const ApexUtils = require('../ApexUtils'); - -afterEach(() => { - document.body.innerHTML = ''; -}); - -test('Test policyTab_activate', () => { - document.body.innerHTML = '<div id="policiesTab"></div>'; - - const data = { - useHttps: 'useHttps', - hostname: 'hostname', - port: 'port', - username: 'username', - password: 'password', - messages: { - message: [ - '{' + - ' "apexPolicy": {' + - ' "policyKey": {' + - ' "name": "name1",' + - ' "version": "version1"' + - ' },' + - ' "template": "template1",' + - ' "firstState": "key11",' + - ' "state": {' + - ' "entry": [' + - ' {' + - ' "key": "key1",' + - ' "value": {' + - ' "trigger": {' + - ' "name": "name2",' + - ' "version": "version2"' + - ' },' + - ' "taskReferences": {' + - ' "entry": [' + - ' {' + - ' "key": {' + - ' "name": "name3",' + - ' "version": "version3"' + - ' },' + - ' "version": "version2",' + - ' "value": {' + - ' "outputType": "outputType1",' + - ' "output": {' + - ' "localName": "localName1"' + - ' }' + - ' }' + - ' }' + - ' ]' + - ' },' + - ' "defaultTask": {' + - ' "name": "name4",' + - ' "version": "version4"' + - ' },' + - ' "taskSelectionLogic": {' + - ' "logicFlavour": "logicFlavour1"' + - ' },' + - ' "stateOutputs": {' + - ' "entry": [' + - ' {' + - ' "key": "key2",' + - ' "value": {' + - ' "nextState": {' + - ' "localName": "localName2"' + - ' },' + - ' "outgoingEvent": {' + - ' "name": "name4",' + - ' "version": "version4"' + - ' }' + - ' }' + - ' }' + - ' ]' + - ' },' + - ' "stateFinalizerLogicMap": {' + - ' "entry": [' + - ' {' + - ' "key": "key3",' + - ' "value": {' + - ' "logicFlavour": "logicFlavour2"' + - ' }' + - ' }' + - ' ]' + - ' },' + - ' "contextAlbumReference": [' + - ' {' + - ' "name": "name5",' + - ' "version": "version5"' + - ' }' + - ' ]' + - ' }' + - ' },' + - ' {' + - ' "key": "key11",' + - ' "value": {' + - ' "trigger": {' + - ' "name": "name12",' + - ' "version": "version12"' + - ' },' + - ' "taskReferences": {' + - ' "entry": [' + - ' {' + - ' "key": {' + - ' "name": "name13",' + - ' "version": "version13"' + - ' },' + - ' "version": "version12",' + - ' "value": {' + - ' "outputType": "outputType11",' + - ' "output": {' + - ' "localName": "localName11"' + - ' }' + - ' }' + - ' }' + - ' ]' + - ' },' + - ' "defaultTask": {' + - ' "name": "name14",' + - ' "version": "version14"' + - ' },' + - ' "taskSelectionLogic": {' + - ' "logicFlavour": "logicFlavour11"' + - ' },' + - ' "stateOutputs": {' + - ' "entry": [' + - ' {' + - ' "key": "key12",' + - ' "value": {' + - ' "nextState": {' + - ' "localName": "localName12"' + - ' },' + - ' "outgoingEvent": {' + - ' "name": "name14",' + - ' "version": "version14"' + - ' }' + - ' }' + - ' }' + - ' ]' + - ' },' + - ' "stateFinalizerLogicMap": {' + - ' "entry": [' + - ' {' + - ' "key": "key13",' + - ' "value": {' + - ' "logicFlavour": "logicFlavour12"' + - ' }' + - ' }' + - ' ]' + - ' },' + - ' "contextAlbumReference": [' + - ' {' + - ' "name": "name15",' + - ' "version": "version15"' + - ' }' + - ' ]' + - ' }' + - ' }' + - ' ]' + - ' }' + - ' }' + - '}' - ] - }, - content: ['01', '02'], - result: 'ok', - ok: true - }; - - $.ajax = jest.fn().mockImplementation((args) => { - args.success(data, null, null); - }); - - const expected = '<div id="policiesTab"><policytabcontent id="policyTabContent">' + - '<table id="policyTableBody" class="apexTable ebTable elTablelib-Table-table ebTable_striped">' + - '<thead id="policyTableHeader"><tr id="policyTableHeaderRow">' + - '<th id="policyTableKeyHeader">Policy</th>' + - '<th id="policyTableTemplateHeader">Template</th>' + - '<th id="policyTableFirstStateHeader">First State</th>' + - '<th id="policyTableStatesHeader">States</th>' + - '</tr></thead><tbody><tr>' + - '<td>name1:version1</td>' + - '<td>template1</td>' + - '<td>key11</td>' + - '<td><table class="ebTable"><thead><tr class="headerRow">' + - '<th>State</th>' + - '<th>Trigger</th>' + - '<th>Referenced Tasks</th>' + - '<th>Default Task</th>' + - '<th>TSL</th>' + - '<th>State Outputs</th>' + - '<th>State Finsalizer Logic</th>' + - '<th>Context Album References</th>' + - '</tr></thead><tbody><tr>' + - '<td>key11</td>' + - '<td>name12:version12</td>' + - '<td><table class="ebTable"><thead><tr class="headerRow">' + - '<th>Task Reference</th>' + - '<th>Output Type</th>' + - '<th>Output</th>' + - '</tr></thead><tbody><tr>' + - '<td>name13:version13</td>' + - '<td>outputType11</td>' + - '<td>localName11</td>' + - '</tr></tbody></table></td>' + - '<td>name14:version14</td>' + - '<td>logicFlavour11</td>' + - '<td><table class="ebTable"><thead><tr class="headerRow">' + - '<th>Name</th>' + - '<th>Next State</th>' + - '<th>Event</th>' + - '</tr></thead><tbody><tr>' + - '<td>key12</td>' + - '<td>localName12</td>' + - '<td>name14:version14</td>' + - '</tr></tbody></table></td>' + - '<td><table class="ebTable"><thead><tr class="headerRow"><th>Name</th><th>Type</th></tr></thead><tbody>' + - '<tr><td>key13</td><td>logicFlavour12</td></tr></tbody></table></td>' + - '<td><table class="ebTable"><tbody><tr><td>name15:version15</td></tr></tbody></table></td>' + - '</tr><tr>' + - '<td>key1</td>' + - '<td>name2:version2</td>' + - '<td><table class="ebTable"><thead><tr class="headerRow">' + - '<th>Task Reference</th>' + - '<th>Output Type</th>' + - '<th>Output</th>' + - '</tr></thead><tbody><tr>' + - '<td>name3:version3</td>' + - '<td>outputType1</td>' + - '<td>localName1</td>' + - '</tr></tbody></table></td>' + - '<td>name4:version4</td>' + - '<td>logicFlavour1</td>' + - '<td><table class="ebTable"><thead><tr class="headerRow"><th>Name</th><th>Next State</th><th>Event</th></tr></thead>' + - '<tbody><tr>' + - '<td>key2</td>' + - '<td>localName2</td>' + - '<td>name4:version4</td>' + - '</tr></tbody></table></td>' + - '<td><table class="ebTable"><thead><tr class="headerRow"><th>Name</th><th>Type</th></tr></thead>' + - '<tbody><tr><td>key3</td><td>logicFlavour2</td></tr></tbody></table></td>' + - '<td><table class="ebTable"><tbody><tr><td>name5:version5</td></tr></tbody></table></td>' + - '</tr></tbody></table></td></tr></tbody></table></policytabcontent></div>'; - - mod.policyTab_activate(); - expect(document.body.innerHTML).toBe(expected); -}); - -test('Test policyTab_deactivate', (done) => { - ApexUtils.apexUtils_removeElement = jest.fn(id => { - expect(id).toBe('policyTabContent'); - done(); - }); - - mod.policyTab_deactivate(); -}); - -test('Test policyTab_create policyTabContent exists', () => { - document.body.innerHTML = '<div id="policiesTab"><div id="policyTabContent"></div></div>'; - - mod.policyTab_create(); - expect(document.body.innerHTML).toBe('<div id="policiesTab"><div id="policyTabContent"></div></div>'); -}); - -test('Test policyTab_create policiesTab does not exists', () => { - document.body.innerHTML = '<div></div>'; - - mod.policyTab_create(); - expect(document.body.innerHTML).toBe('<div></div>'); -}); - -test('Test policyTab_create', () => { - document.body.innerHTML = '<div id="policiesTab"></div>'; - - const expected = '<div id="policiesTab"><policytabcontent id="policyTabContent">' + - '<table id="policyTableBody" class="apexTable ebTable elTablelib-Table-table ebTable_striped">' + - '<thead id="policyTableHeader"><tr id="policyTableHeaderRow">' + - '<th id="policyTableKeyHeader">Policy</th>' + - '<th id="policyTableTemplateHeader">Template</th>' + - '<th id="policyTableFirstStateHeader">First State</th>' + - '<th id="policyTableStatesHeader">States</th>' + - '</tr></thead><tbody></tbody></table></policytabcontent></div>'; - - mod.policyTab_create(); - expect(document.body.innerHTML).toBe(expected); -}); diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexResultForm.test.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexResultForm.test.js deleted file mode 100644 index a219ac9..0000000 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexResultForm.test.js +++ /dev/null @@ -1,37 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2020 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('../ApexResultForm'); - -test('resultForm test', () => { - document.innerHTML = - '<div id="newModelDivBackground">' + - '</div>' + - '<div id="elementTest">' + - '</div>'; - - const content = document.getElementById("elementTest"); - const mock_activate = jest.fn(mod.resultForm_activate); - mock_activate(document.createElement("elementTest"), 'heading', 'text'); - expect(mock_activate).toBeCalled(); - - const mock_pressedOK = jest.fn(mod.resultForm_okPressed); - mock_pressedOK(); -});
\ No newline at end of file diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexTable.test.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexTable.test.js deleted file mode 100644 index 864b0c9..0000000 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexTable.test.js +++ /dev/null @@ -1,43 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * 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. - * 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 ApexTable = require("../ApexTable"); - -test("Test createTable", () => { - const expected = document.createElement("table"); - expected.id = "my-id"; - expected.className = "apexTable ebTable elTablelib-Table-table ebTable_striped"; - - const actual = ApexTable.createTable(expected.id); - expect(actual).toEqual(expected); -}); - -test("Test setRowHover", () => { - const element = { - className: null, - onmouseover: null, - onmouseout: null - }; - - ApexTable.setRowHover(element); - - expect(element.className).toBe("ebTableRow"); - expect(typeof element.onmouseover).toBe("function"); - expect(typeof element.onmouseout).toBe("function"); -}); 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 deleted file mode 100644 index b9982f5..0000000 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexTaskEditForm.test.js +++ /dev/null @@ -1,179 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2020-2022 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('../ApexTaskEditForm'); -const apexUtils = require('../ApexUtils'); -const apexTaskTab = require('../ApexTaskTab'); -const keyInformationTab_reset = require('../ApexKeyInformationTab'); - -const contextSchema = { - name: 'testName', - version: '0.0.1', - schemaFlavour: 'testFlav', - schemaDefinition: 'testDef', - uuid: 'testUUID', - description: 'testDesc' -}; - -const task = { - key: { - name: 'testName', - version: 'testVersion' - }, - 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 -}; - - let contextAlbumReference = { - "name" : "TestAlbum", - "version" : "0.0.1" -}; - -const parentTBody = document.createElement('table'); - -test('Test editTaskForm_activate CREATE', () => { - const mock_activate = jest.fn(mod.editTaskForm_activate); - mock_activate('test', 'CREATE', 'task', contextSchema, 'album'); - expect(mock_activate).toBeCalled(); -}); - -test('Test editTaskForm_activate EDIT', () => { - const mock_activate = jest.fn(mod.editTaskForm_activate); - 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(); -}); - -test('Test editTaskForm_addTaskInputField', () => { - const mock_activate = jest.fn(mod.editTaskForm_addTaskInputField); - let contextSchemas = new Array(); - contextSchemas.push(contextSchema); - mock_activate(parentTBody, true, 'name', null, contextSchema, contextSchemas); - expect(mock_activate).toBeCalled(); -}); - -test('Test editTaskForm_addTaskOutputField', () => { - const mock_activate = jest.fn(mod.editTaskForm_addTaskOutputField); - let contextSchemas = new Array(); - contextSchemas.push(contextSchema); - mock_activate(parentTBody, true, 'name', null, contextSchema, contextSchemas); - expect(mock_activate).toBeCalled(); -}); - -test('Test editTaskForm_addTaskParameter', () => { - const mock_activate = jest.fn(mod.editTaskForm_addTaskParameter); - mock_activate(parentTBody, true, 'name', null); - expect(mock_activate).toBeCalled(); -}); - -test('Test editTaskForm_addTaskContext', () => { - const mock_activate = jest.fn(mod.editTaskForm_addTaskContext); - let contextAlbums = new Array(); - contextAlbums.push(contextAlbumReference); - mock_activate(parentTBody, true, 'name', null, contextAlbumReference, contextAlbums); - expect(mock_activate).toBeCalled(); -}); - -test('Test editTaskForm_generateUUIDPressed', () => { - let documentSpy = jest.spyOn(document, 'getElementById'); - let editTaskFormUuidInput = document.createElement("editTaskFormUuidInput"); - documentSpy.mockReturnValue(editTaskFormUuidInput); - const mock_activate = jest.fn(mod.editTaskForm_generateUUIDPressed); - mock_activate(); - expect(mock_activate).toBeCalled(); -}); - -test('Test editTaskForm_generateDescriptionPressed', () => { - let documentSpy = jest.spyOn(document, 'getElementById'); - let editTaskFormDescriptionTextArea = document.createElement("editTaskFormDescriptionTextArea"); - documentSpy.mockReturnValue(editTaskFormDescriptionTextArea); - const mock_activate = jest.fn(mod.editTaskForm_generateDescriptionPressed); - mock_activate(); - expect(mock_activate).toBeCalled(); -}); - -test('Test editTaskForm_cancelPressed', () => { - 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_cancelPressed); - mock_activate(); - expect(mock_activate).toBeCalled(); -}); - -test('Test editTaskForm_submitPressed', () => { - jest.spyOn(apexTaskTab, 'taskTab_reset').mockReturnValueOnce(null); - jest.spyOn(keyInformationTab_reset, 'keyInformationTab_reset').mockReturnValueOnce(null); - jest.spyOn(apexUtils, 'apexUtils_removeElement').mockReturnValueOnce(null); - - let documentSpy = jest.spyOn(document, 'getElementById'); - let elementMock = document.createElement("editTaskForm"); - elementMock.setAttribute("createEditOrView", "CREATE"); - elementMock.value = 'logictype' - documentSpy.mockReturnValue(elementMock); - - const mock_activate = jest.fn(mod.editTaskForm_submitPressed); - mock_activate(); - 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 deleted file mode 100644 index f593bd8..0000000 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexTaskTab.test.js +++ /dev/null @@ -1,52 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * 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. - * 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('../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(); -}); - -test('test reset', () => { - const reset_mock = jest.fn(mod.taskTab_reset); - reset_mock(); - expect(reset_mock).toBeCalled(); -});
\ No newline at end of file diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexUtils.test.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexUtils.test.js deleted file mode 100644 index d00327e..0000000 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexUtils.test.js +++ /dev/null @@ -1,116 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2021-2022 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 ApexUtils = require('../ApexUtils'); - -afterEach(() => { - delete global.confirm; - - document.body.innerHTML = ''; -}); - -test('test apexUtils_areYouSure', () => { - const errorMsg = 'My message'; - const returned = {}; - global.confirm = jest - .fn() - .mockImplementation((message) => { - expect(message).toBe(errorMsg); - return returned; - }); - - const actual = ApexUtils.apexUtils_areYouSure(errorMsg); - expect(actual).toBe(returned); -}); - -test('apexUtils_emptyElement found', () => { - document.body.innerHTML = - '<div id="tested">' + - ' <span id="username"></span>' + - ' <button id="button"></button>' + - '</div>'; - - ApexUtils.apexUtils_emptyElement('tested'); - - expect(document.body.innerHTML).toBe('<div id="tested"></div>') -}); - -test('apexUtils_emptyElement found', () => { - const text = - '<div id="other">' + - ' <span id="username"></span>' + - ' <button id="button"></button>' + - '</div>'; - document.body.innerHTML = text; - ApexUtils.apexUtils_emptyElement('tested'); - - expect(document.body.innerHTML).toBe(text) -}); - -test('apexUtils_removeElement not found', () => { - const expected = /<div>\s*<button id="button"><\/button>\s*<\/div>/; - - document.body.innerHTML = - '<div>' + - ' <span id="tested"></span>' + - ' <button id="button"></button>' + - '</div>'; - - ApexUtils.apexUtils_removeElement('tested'); - expect(document.body.innerHTML).toMatch(expected); -}); - -test('apexUtils_escapeHtml', () => { - const actual = ApexUtils.apexUtils_escapeHtml('&<ab>"\'/`=\n\t d'); - expect(actual).toBe('&<ab>"'/`=<br> d') -}); - -test('createAddFormButton no text', () => { - const expected = document.createElement('div'); - expected.setAttribute('class','add-field'); - expected.innerHTML = '<i class="form-add-icon ebIcon ebIcon_add"></i><span class="form-add-text">Add</span>'; - const actual = ApexUtils.createAddFormButton(); - expect(actual).toEqual(expected); -}); - -test('createAddFormButton with text', () => { - const expected = document.createElement('div'); - expected.setAttribute('class','add-field'); - expected.innerHTML = '<i class="form-add-icon ebIcon ebIcon_add"></i><span class="form-add-text">My_text</span>'; - const actual = ApexUtils.createAddFormButton('My_text'); - expect(actual).toEqual(expected); -}); - -test('test EMPTY createEditArea', () => { - const mock_activate = jest.fn(ApexUtils.createEditArea); - mock_activate('id', 'options', ''); - expect(mock_activate).toBeCalled(); -}); - -test('test getHomepageURL', () => { - const mock_activate = jest.fn(ApexUtils.getHomepageURL); - mock_activate(); - expect(mock_activate).toBeCalled(); -}); - -test('test isFirefox', () => { - const mock_activate = jest.fn(ApexUtils.isFirefox); - 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__/contextMenu.test.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/contextMenu.test.js deleted file mode 100644 index d804b6d..0000000 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/contextMenu.test.js +++ /dev/null @@ -1,118 +0,0 @@ -/* - * ============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__/dropdownList.test.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/dropdownList.test.js deleted file mode 100644 index 1c314af..0000000 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/dropdownList.test.js +++ /dev/null @@ -1,68 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2022 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('../dropdownList'); - -let selectedOption = { - displaytext : 'displaytext' -}; - -const page = '<html><head></head><body>' + -'<div id="divName_display"><ul><li><a href="divName">Delete this</a><li>Second</li></li></ul></div>' + -'<div id="divName"><ul><li><a href="divName">Just a Div</a><li>Second</li></li></ul></div>' + -'<div id="divName_options"><ul><li><a href="dropdownList_show">Show</a><li>Second</li></li></ul></div>' + -'</body></html>'; - -test('test dropdownList option select', () => { - document.documentElement.innerHTML = page; - mod.dropdownList_option_select('divName',selectedOption, false); - let expected = '<head></head><body>' + - '<div id="divName_display">displaytext</div>' + - '<div id="divName"><ul><li><a href="divName">Just a Div</a></li><li>Second</li></ul></div>' + - '<div id="divName_options"><ul><li><a href="dropdownList_show">Show</a></li><li>Second</li></ul></div>' + - '</body>'; - expect(document.documentElement.innerHTML).toBe(expected); -}); - -test('test dropdownList display click', () => { - document.documentElement.innerHTML = page; - mod.dropdownList_display_click('divName',selectedOption, false, false); - const expected = '<head></head><body>' + - '<div id=\"divName_display\"><ul><li><a href=\"divName\">Delete this</a></li><li>Second</li></ul></div>' + - '<div id=\"divName\"><ul><li><a href=\"divName\">Just a Div</a></li><li>Second</li></ul></div>' + - '<div id=\"divName_options\" class=\"dropdownList_show dropdownList_display_clicked\"><ul><li><a href=\"dropdownList_show\">Show</a></li><li>Second</li></ul></div></body>'; - expect(document.documentElement.innerHTML).toBe(expected); - mod.dropdownList_display_click('divName',selectedOption, true, false); -}); - -test('test dropdownList filter', () => { - document.documentElement.innerHTML = '<html><head></head><body>' + - '<p id="optionDiv_search">tosearch</p>' + - '<div id="optionDiv_options_list_ul"><div id="#divName"><li>test</li></div></div>' + - '</body></html>'; - let documentSpy = jest.spyOn(document, 'getElementById'); - let elementMock = document.createElement("optionDiv_search"); - elementMock.value = '1' - elementMock.id = 'divName' - documentSpy.mockReturnValue(elementMock); - mod.dropdownList_filter('optionDiv','optionUl'); - const expected = '<head></head><body><p id=\"optionDiv_search\">tosearch</p><div id=\"optionDiv_options_list_ul\"><div id=\"#divName\"><li>test</li></div></div></body>'; - expect(document.documentElement.innerHTML).toBe(expected); -});
\ No newline at end of file diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/fileMenu.test.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/fileMenu.test.js deleted file mode 100644 index ffc9e2c..0000000 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/fileMenu.test.js +++ /dev/null @@ -1,31 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2022 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('../fileMenu'); - -test('test hideMenu', () => { - document.documentElement.innerHTML = '<html><head></head><body><ul id="menu">Hello world!</ul></body></html>'; - $ = require('jquery'); - window.$ = $; - $('#menu').fileMenu(); - $('#menu').click(); - let h1 = document.querySelector('ul'); - expect(h1.textContent).toEqual('Hello world!'); -}); 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 deleted file mode 100644 index 6b2bfa5..0000000 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/showhideElement.test.js +++ /dev/null @@ -1,49 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2021-2022 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(); -}); - -test('Test editTaskForm_activate NO CHECKBOX', () => { - const mock_activate = jest.fn(mod.showHideElement_display); - spyOn($.fn, "find").and.returnValue(false); - const mockedElementDOM = { classList: { contains: jest.fn(), remove: jest.fn(), add: jest.fn() } }; - mockedElementDOM.classList.contains.mockReturnValueOnce(true); - mockedElementDOM.classList.remove.mockReturnValueOnce(true); - mock_activate(mockedElementDOM, 'element', 'style', 'hidestyle', 'buttonshowStyle','buttonhideStyle'); - expect(mock_activate).toBeCalled(); -}); - -test('Test editTaskForm', () => { - const mock_activate = jest.fn(mod.showHideElement); - var element = document.createElement("div"); - mock_activate("id_prefix", element, true, "showText", "hideText", "style", "hidestyle", "buttonshowStyle", "buttonhideStyle"); - expect(mock_activate).toBeCalled(); -}); - - - - 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 deleted file mode 100644 index 3a72037..0000000 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/showhideTextArea.test.js +++ /dev/null @@ -1,48 +0,0 @@ -/* - * ============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/__test__/test-env.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/test-env.js deleted file mode 100644 index 8fd788a..0000000 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/test-env.js +++ /dev/null @@ -1,2 +0,0 @@ -import $ from 'jquery'; -global.$ = global.jQuery = $;
\ No newline at end of file |