summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlapentafd <francesco.lapenta@est.tech>2022-02-14 16:54:03 +0000
committerlapentafd <francesco.lapenta@est.tech>2022-02-15 14:25:32 +0000
commit079fd69a71093c3405aa4fc67ef206f1334aaf79 (patch)
tree70a7a5a35bebc7b190c25ff90d325ce9be2c20d9
parent6a4b040b768277b0bc39d153cdf813009677be30 (diff)
Code coverage for ApexPolicyEditForm_State
Issue-ID: POLICY-3351 Signed-off-by: lapentafd <francesco.lapenta@est.tech> Change-Id: I6146510025c33bc754b26970d57da343edfe8311
-rw-r--r--gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexPolicyEditForm_State.test.js78
1 files changed, 76 insertions, 2 deletions
diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexPolicyEditForm_State.test.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexPolicyEditForm_State.test.js
index 8dd9fc4..b69bbe3 100644
--- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexPolicyEditForm_State.test.js
+++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexPolicyEditForm_State.test.js
@@ -136,18 +136,92 @@ test('Test editPolicyForm_State_getStateBean', () => {
const mock_activate = jest.fn(mod.editPolicyForm_State_getStateBean);
mock_activate('stateName');
expect(mock_activate).toBeCalled();
-
});
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_getStateBean with mock', () => {
+ let documentSpy = jest.spyOn(document, 'getElementById');
+ let elementMock = document.createElement("editPolicyFormDirOutputsTable_stateName");
+ elementMock.rows = '1'
+ elementMock.key = {"name": "name1", "version": "version1"}
+ documentSpy.mockReturnValue(elementMock);
const mock_activate = jest.fn(mod.editPolicyForm_State_getStateBean);
- mock_activate(null);
+ mock_activate('stateName');
expect(mock_activate).toBeCalled();
+});
+
+test('Test editPolicyForm_State_getStateBean with page', () => {
+ document.documentElement.innerHTML = '<html><head></head><body>' +
+ '<div id="editPolicyFormStateDiv_stateName"></div>' +
+ '<div id="editPolicyFormTrigger_stateName_dropdownList" selectedOption="1"></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>' +
+ '</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 = {"album": { "key": { "name": 'testAlbumName', "version": '0.0.1'}}, "name": "name1", "version": "version1", "event": { "key": { "name": 'testEventName', "version": '0.1.1'}}};
+ elementMock.value = "localName";
+ documentSpy.mockReturnValue(elementMock);
+ const mock_activate = jest.fn(mod.editPolicyForm_State_getStateBean);
+ mock_activate('stateName');
+ expect(mock_activate).toBeCalled();
});
test('Test editPolicyForm_State_getLogicOutputMappingOptions', () => {
const mock_activate = jest.fn(mod.editPolicyForm_State_getLogicOutputMappingOptions);
mock_activate(null);
expect(mock_activate).toBeCalled();
+});
+
+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).toBeCalled();
+});
+
+test('Test editPolicyForm_State_getDirectOutputMappingOptions with page', () => {
+ document.documentElement.innerHTML = '<html><head></head><body>' +
+ '<table id="editPolicyFormDirOutputsTable_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("editPolicyFormDirOutputsTable_stateName");
+ elementMock.value = "localName";
+ elementMock.rows = document.getElementById("editPolicyFormDirOutputsTable_stateName").rows;
+ documentSpy.mockReturnValue(elementMock);
+ const mock_activate = jest.fn(mod.editPolicyForm_State_getDirectOutputMappingOptions);
+ mock_activate('stateName');
+ expect(mock_activate).toBeCalled();
}); \ No newline at end of file