From 079fd69a71093c3405aa4fc67ef206f1334aaf79 Mon Sep 17 00:00:00 2001 From: lapentafd Date: Mon, 14 Feb 2022 16:54:03 +0000 Subject: Code coverage for ApexPolicyEditForm_State Issue-ID: POLICY-3351 Signed-off-by: lapentafd Change-Id: I6146510025c33bc754b26970d57da343edfe8311 --- .../js/__test__/ApexPolicyEditForm_State.test.js | 78 +++++++++++++++++++++- 1 file changed, 76 insertions(+), 2 deletions(-) (limited to 'gui-editors/gui-editor-apex/src/main/resources') 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 = '' + + '
' + + '
' + + '' + + '' + + '' + + '' + + '
cell 1cell 2
cell 3cell4
cell 5cell6
' + + ''; + + 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 = '' + + '' + + '' + + '' + + '' + + '
cell 1cell 2
cell 3cell4
cell 5cell6
' + + ''; + 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 = '' + + '' + + '' + + '' + + '' + + '
cell 1cell 2
cell 3cell4
cell 5cell6
' + + ''; + 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 -- cgit 1.2.3-korg