diff options
Diffstat (limited to 'gui-editors')
4 files changed, 451 insertions, 27 deletions
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 index 23f4edc..16042af 100644 --- 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 @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. + * Copyright (C) 2020-2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,15 +19,101 @@ */ const mod = require('../ApexEventTab'); +const ApexUtils = require('../ApexUtils'); + +afterEach(() => { + document.body.innerHTML = ''; +}); test('Test activate', () => { - const mock_activate = jest.fn(mod.eventTab_activate); - mock_activate() - expect(mock_activate).toBeCalled(); + 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 create'); -test.todo('Test deactivate'); -test.todo('Test reset');
\ No newline at end of file +test.todo('Test reset'); 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 index b9315c2..2144506 100644 --- 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 @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. + * Copyright (C) 2020-2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,19 +19,78 @@ */ const mod = require('../ApexModelHandling'); +const ApexResultForm = require("../ApexResultForm"); -test('Test modelHandling_analyse', () => { - const mock_modelHandling_analyse = jest.fn(mod.modelHandling_analyse); - mock_modelHandling_analyse(); - expect(mock_modelHandling_analyse).toHaveBeenCalledWith(); +afterEach(() => { + document.body.innerHTML = ''; }); -test('Test modelHandling_validate', () => { - const mock_modelHandling_validate_ajaxget = jest.fn(mod.modelHandling_validate.ajax_get); - mock_modelHandling_validate_ajaxget('test', jest.fn()); - expect(mock_modelHandling_validate_ajaxget).toHaveBeenCalledTimes(1); +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>'; - const mock_modelHandling_validate = jest.fn(mod.modelHandling_validate); - mock_modelHandling_validate(); - expect(mock_modelHandling_validate).toHaveBeenCalled(); -});
\ No newline at end of file + $.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__/ApexPolicyTab.test.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexPolicyTab.test.js index 47f00ef..4136fd6 100644 --- 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 @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation + * Copyright (C) 2020-2021 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,9 +18,288 @@ */ const mod = require('../ApexPolicyTab'); +const ApexUtils = require('../ApexUtils'); + +afterEach(() => { + document.body.innerHTML = ''; +}); test('Test policyTab_activate', () => { - const mock_activate = jest.fn(mod.policyTab_activate); - mock_activate(); - expect(mock_activate).toBeCalled(); -});
\ No newline at end of file + 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__/ApexTable.test.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexTable.test.js index 894d668..864b0c9 100644 --- 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 @@ -17,7 +17,7 @@ * ============LICENSE_END========================================================= */ -const ApexTable = require("../ApexTable") +const ApexTable = require("../ApexTable"); test("Test createTable", () => { const expected = document.createElement("table"); @@ -25,7 +25,7 @@ test("Test createTable", () => { expected.className = "apexTable ebTable elTablelib-Table-table ebTable_striped"; const actual = ApexTable.createTable(expected.id); - expect(actual).toEqual(actual); + expect(actual).toEqual(expected); }); test("Test setRowHover", () => { |