From 483f0f8457f8b10d426e8135ab66000d3a3ff7a9 Mon Sep 17 00:00:00 2001 From: waynedunican Date: Mon, 7 Sep 2020 12:21:03 +0100 Subject: JavaScript tests for apex-editor JavaScript tests added to improve code coverage for policy-gui Issue-ID: POLICY-2783 Change-Id: Ie12fb6089b872842bb5c668a8126675f89772d79 Signed-off-by: waynedunican --- .../src/main/resources/webapp/js/ApexAjax.js | 8 ++- .../src/main/resources/webapp/js/ApexConfig.js | 10 +++- .../resources/webapp/js/ApexContextAlbumTab.js | 4 +- .../webapp/js/ApexContextSchemaEditForm.js | 9 +++ .../src/main/resources/webapp/js/ApexEventTab.js | 4 +- .../src/main/resources/webapp/js/ApexFiles.js | 7 ++- .../src/main/resources/webapp/js/ApexFormUtils.js | 2 + .../src/main/resources/webapp/js/ApexMain.js | 2 + .../main/resources/webapp/js/ApexPageControl.js | 2 + .../src/main/resources/webapp/js/ApexTable.js | 2 + .../src/main/resources/webapp/js/ApexUser.js | 2 + .../resources/webapp/js/__test__/ApexAjax.test.js | 69 ++++++++++++++++++++++ .../webapp/js/__test__/ApexConfig.test.js | 43 ++++++++++++++ .../webapp/js/__test__/ApexContextAlbumTab.test.js | 32 ++++++++++ .../resources/webapp/js/__test__/ApexFiles.test.js | 41 +++++++++++++ .../webapp/js/__test__/ApexFormUtils.test.js | 32 ++++++++++ .../webapp/js/__test__/ApexPageControl.test.js | 30 ++++++++++ .../resources/webapp/js/__test__/ApexTable.test.js | 37 ++++++++++++ .../resources/webapp/js/__test__/ApexUser.test.js | 31 ++++++++++ .../main/resources/webapp/js/__test__/test-env.js | 2 + 20 files changed, 360 insertions(+), 9 deletions(-) create mode 100644 gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexAjax.test.js create mode 100644 gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexConfig.test.js create mode 100644 gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexContextAlbumTab.test.js create mode 100644 gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexFiles.test.js create mode 100644 gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexFormUtils.test.js create mode 100644 gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexPageControl.test.js create mode 100644 gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexTable.test.js create mode 100644 gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexUser.test.js create mode 100644 gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/test-env.js (limited to 'gui-editors/gui-editor-apex/src/main/resources/webapp/js') diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexAjax.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexAjax.js index c241a44..2a75b72 100644 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexAjax.js +++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexAjax.js @@ -34,9 +34,9 @@ function ajax_get(requestURL, callback) { }); } -function ajax_getWithKeyInfo(requestURL, objectType, callback, keyName) { - var keyName = keyName || "key"; - var keyInfoURL = restRootURL + "/KeyInformation/Get?name=&version="; +function ajax_getWithKeyInfo(requestURL, objectType, callback, keyNam) { + let keyName = keyNam || "key"; + let keyInfoURL = restRootURL + "/KeyInformation/Get?name=&version="; ajax_get(keyInfoURL, function(dataKeyInfos) { ajax_get(requestURL, function(data) { var keyInfos = []; @@ -121,3 +121,5 @@ function ajax_delete(requestURL, callback) { } }); } + +module.exports = {ajax_get, ajax_delete, ajax_post, ajax_put, ajax_getOKOrFail, ajax_getWithKeyInfo}; \ No newline at end of file diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexConfig.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexConfig.js index a7f41d2..9a842c2 100644 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexConfig.js +++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexConfig.js @@ -31,6 +31,10 @@ const configObj = { } $(document).ready(function () { + load(); +}); + +const load = function(){ $("#menuFileUpload").hide(); const rootUrl = location.protocol @@ -51,8 +55,8 @@ $(document).ready(function () { configObj.readySignal(); }); } - loadConfiguration(); -}); - +} +module.exports = { configObj, load }; +module.exports.rootUrl = load.rootUrl; diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexContextAlbumTab.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexContextAlbumTab.js index f1aca66..f0af49f 100644 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexContextAlbumTab.js +++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexContextAlbumTab.js @@ -113,4 +113,6 @@ function contextAlbumTab_create() { var contextAlbumTableBody = document.createElement("tbody"); contextAlbumTable.appendChild(contextAlbumTableBody); contextAlbumTable.setAttribute("id", "contextAlbumTableBody"); -} \ No newline at end of file +} + +module.exports = {contextAlbumTab_reset, contextAlbumTab_create, contextAlbumTab_activate, contextAlbumTab_deactivate}; \ No newline at end of file diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexContextSchemaEditForm.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexContextSchemaEditForm.js index 52dcff8..dac2e50 100644 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexContextSchemaEditForm.js +++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexContextSchemaEditForm.js @@ -19,6 +19,11 @@ * ============LICENSE_END========================================================= */ +const {ajax_put} = require("../../../../../target/classes/webapp/js/ApexAjax"); +const {ajax_post} = require("../../../../../target/classes/webapp/js/ApexAjax"); +const {ajax_delete} = require("../../../../../target/classes/webapp/js/ApexAjax"); +const {ajax_getWithKeyInfo} = require("../../../../../target/classes/webapp/js/ApexAjax"); + function editContextSchemaForm_createContextSchema(formParent) { return editContextSchemaForm_activate(formParent, "CREATE", null); } @@ -367,3 +372,7 @@ function editContextSchemaForm_submitPressed() { } } + +module.exports = {editContextSchemaForm_activate, editContextSchemaForm_cancelPressed, editContextSchemaForm_createContextSchema, + editContextSchemaForm_deleteContextSchema, editContextSchemaForm_editContextSchema, editContextSchemaForm_generateDescriptionPressed, + editContextSchemaForm_generateUUIDPressed, editContextSchemaForm_submitPressed, editContextSchemaForm_viewContextSchema}; diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexEventTab.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexEventTab.js index a5e0126..699f460 100644 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexEventTab.js +++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexEventTab.js @@ -136,4 +136,6 @@ function eventTab_create() { var eventTableBody = document.createElement("tbody"); eventTable.appendChild(eventTableBody); eventTable.setAttribute("id", "eventTableBody"); -} \ No newline at end of file +} + +exports = {eventTab_reset, eventTab_activate, eventTab_deactivate, eventTab_create} diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexFiles.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexFiles.js index 89a0f86..9171fd3 100644 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexFiles.js +++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexFiles.js @@ -19,10 +19,13 @@ * ============LICENSE_END========================================================= */ +const {ajax_get} = require("../../../../../target/classes/webapp/js/ApexAjax"); +const {ajax_put} = require("../../../../../target/classes/webapp/js/ApexAjax"); + function files_fileOpen() { $('').on('change', function() { var reader = new FileReader(); - modelFileName = this.files[0].name; + var modelFileName = this.files[0].name; reader.readAsText(this.files[0]); reader.onload = function(event) { @@ -49,3 +52,5 @@ function files_fileDownload() { downloadLink.click(); document.body.removeChild(downloadLink); } + +module.exports = {files_fileDownload, files_fileOpen}; diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexFormUtils.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexFormUtils.js index c7bf242..93f0f68 100644 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexFormUtils.js +++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexFormUtils.js @@ -46,3 +46,5 @@ function formUtils_generateDescription(name, version, uuid) { + "\" and UUID \"" + uuid + "\""; return description; } + +module.exports = {formUtils_generateDescription, formUtils_generateUUID}; diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexMain.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexMain.js index 57433d6..46d8398 100644 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexMain.js +++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexMain.js @@ -169,3 +169,5 @@ $(".ebInlineMessage").mouseleave(function(e) { $(document).ready(function() { $(".content").fadeIn(); }); + +exports.restRootURL = { restRootURL }; diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexPageControl.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexPageControl.js index c2cb45c..133f511 100644 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexPageControl.js +++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexPageControl.js @@ -253,3 +253,5 @@ function showPlaceholder(show) { $(".placeholder").hide(); } } + +module.exports = {showPlaceholder, pageControl_busyMode, pageControl_modelMode, pageControl_noModelMode, pageControl_readyMode, pageControl_recursiveDisable, pageControl_restError, pageControl_status, pageControl_successStatus} diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexTable.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexTable.js index 0b6aaac..3e9fe3d 100644 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexTable.js +++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexTable.js @@ -35,3 +35,5 @@ function setRowHover(rowElement) { this.className = "ebTableRow"; }; } + +module.exports = {createTable, setRowHover}; \ No newline at end of file diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexUser.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexUser.js index 684fdf7..e30f5dd 100644 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexUser.js +++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexUser.js @@ -28,3 +28,5 @@ const userManager = { const urlParams = new URLSearchParams(window.location.search); userManager.userId = urlParams.get('userId'); })(); + +exports = {userManager}; \ No newline at end of file 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 new file mode 100644 index 0000000..ebf79c9 --- /dev/null +++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexAjax.test.js @@ -0,0 +1,69 @@ +/* + * ============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('../ApexAjax'); + +test('Test ajax_get', () => { + const mockGet = jest.fn(mod.ajax_get).mockImplementation(() => { + const val = { + type : 'GET', + url : 'requestURL', + dataType : "json", // data type of response + success : function(data) { + return 'Success' + }, + error : function(jqXHR, textStatus, errorThrown) { + return 'Error' + } + } + }); + mockGet('Called'); + expect(mockGet).toBeCalledTimes(1); + expect(mockGet).toHaveBeenCalledWith('Called'); +}); + +test('Test ajax_delete', () => { + const mockDelete = jest.fn(mod.ajax_delete); + mockDelete(); + expect(mockDelete).toBeCalledTimes(1); +}); + +test('Test ajax_post', () => { + const mockAjaxPost = jest.fn(mod.ajax_post); + mockAjaxPost(); + expect(mockAjaxPost).toBeCalledTimes(1); +}); + +test('Test ajax_put', () => { + const mockAjaxPut = jest.fn(mod.ajax_put); + mockAjaxPut(); + expect(mockAjaxPut).toBeCalledTimes(1); +}); + +test('Test ajax_getOKOrFail', () => { + const mockAjaxGetOkOrFail = jest.fn(mod.ajax_getOKOrFail); + mockAjaxGetOkOrFail(); + expect(mockAjaxGetOkOrFail).toBeCalledTimes(1); +}); + +test('Test ajax_getWithKeyInfo', () => { + const mockGetWKey = jest.fn(mod.ajax_getWithKeyInfo); + const kName = mod.ajax_getWithKeyInfo.keyName; + expect(kName).not.toBe(null); +}); \ No newline at end of file diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexConfig.test.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexConfig.test.js new file mode 100644 index 0000000..02d8406 --- /dev/null +++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexConfig.test.js @@ -0,0 +1,43 @@ +/* + * ============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 apexConfig = require('../ApexConfig'); + +test('configObj called successfully', () => { + expect(apexConfig.configObj.getConfig()).not.toBeNull(); + expect(apexConfig.configObj.setConfig()).not.toBeNull(); + expect(apexConfig.configObj).toHaveProperty('configMap'); +}); + +test('load called successfully', () => { + expect(apexConfig.rootUrl).not.toBe(null); + const mock = jest.fn(apexConfig.load).mockImplementation(() => { + function test (data) { + for (let i = 0; i < data.messages.message.length; i++) { + const configEntry = JSON.parse(data.messages.message[i]); + Object.keys(configEntry).forEach(key => { + configObj.setConfig(key, configEntry[key]); + }); + } + configObj.readySignal(); + }; + }); + mock(); + expect(mock).toHaveBeenCalledTimes(1); +}); \ No newline at end of file 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 new file mode 100644 index 0000000..5932a6d --- /dev/null +++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexContextAlbumTab.test.js @@ -0,0 +1,32 @@ +/* + * ============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'); + +test('call deactivate', () => { + const deactivate = jest.fn(mod.contextAlbumTab_deactivate).mockReturnValueOnce('success'); + deactivate(); + expect(deactivate).toHaveBeenCalledTimes(1); +}); + +test('call create', () => { + const create = jest.fn(mod.contextAlbumTab_create).mockReturnValueOnce('success'); + create(); + expect(create).toHaveBeenCalledTimes(1); +}) \ No newline at end of file diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexFiles.test.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexFiles.test.js new file mode 100644 index 0000000..d6d3c40 --- /dev/null +++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexFiles.test.js @@ -0,0 +1,41 @@ +/* + * ============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('../ApexFiles'); + +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).mockImplementation(() => { + var requestURL = "/Model/Download"; + + var downloadLink = document.createElement("a"); + document.body.appendChild(downloadLink); + downloadLink.download = 'modelFileName'; + downloadLink.href = requestURL; + downloadLink.click(); + document.body.removeChild(downloadLink); + }); + download(); + expect(download).toHaveBeenCalledTimes(1); +}) \ 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 new file mode 100644 index 0000000..046c43e --- /dev/null +++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexFormUtils.test.js @@ -0,0 +1,32 @@ +/* + * ============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).toBeCalledTimes(1); +}) \ 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 new file mode 100644 index 0000000..abdb1a9 --- /dev/null +++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexPageControl.test.js @@ -0,0 +1,30 @@ +/* + * ============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('../ApexPageControl'); + +test('test show placeholder', () => { + const mock = jest.fn(mod.showPlaceholder); + mock(); + expect(mock).toBeCalledTimes(1); +}) + +test('test busyMode', () => { + +}) \ 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 new file mode 100644 index 0000000..504f84f --- /dev/null +++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexTable.test.js @@ -0,0 +1,37 @@ +/* + * ============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('../ApexTable'); + +let wrapper = document.createElement("example"); +wrapper.setAttribute("id", "engineSummary_wrapper"); +wrapper.setAttribute("class", "wrapper_borderless"); + +test('call createTable', () => { + const createTable = mod.createTable('01'); + expect(createTable.getAttribute('id')).toBeDefined(); + expect(createTable.getAttribute('class')).toBeDefined(); + expect(createTable.getAttribute('id').valueOf()).toBe('01'); +}); + +test('test setRowHover', () => { + const mock = jest.fn(mod.setRowHover(wrapper)); + mock(); + expect(mock).toBeCalledTimes(1); +}) \ No newline at end of file diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexUser.test.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexUser.test.js new file mode 100644 index 0000000..1d445c4 --- /dev/null +++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexUser.test.js @@ -0,0 +1,31 @@ +/* + * ============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 user = require('../ApexUser'); + +test('userManager test', () => { + const userMock = { + userId: u => { + return `userId: ${u}`; + }, + } + const spy = jest.spyOn(userMock, 'userId'); + expect(userMock.userId('userTest')).toBe('userId: userTest'); + expect(spy).toHaveBeenCalledWith('userTest'); +}); \ No newline at end of file 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 new file mode 100644 index 0000000..8fd788a --- /dev/null +++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/test-env.js @@ -0,0 +1,2 @@ +import $ from 'jquery'; +global.$ = global.jQuery = $; \ No newline at end of file -- cgit 1.2.3-korg