From 85a7f17ecb252615725a86353932f9f21951adc9 Mon Sep 17 00:00:00 2001 From: lapentafd Date: Thu, 17 Feb 2022 16:46:55 +0000 Subject: Code coverage policy gui Policy Edit Form Issue-ID: POLICY-3351 Signed-off-by: lapentafd Change-Id: I682f046955b06bc7738987b8998ecd4cdb287276 --- .../webapp/js/__test__/ApexPolicyEditForm.test.js | 95 +++++++++++++++++++++- 1 file changed, 93 insertions(+), 2 deletions(-) (limited to 'gui-editors/gui-editor-apex/src/main') diff --git a/gui-editors/gui-editor-apex/src/main/webapp/js/__test__/ApexPolicyEditForm.test.js b/gui-editors/gui-editor-apex/src/main/webapp/js/__test__/ApexPolicyEditForm.test.js index b3153a9..24af346 100644 --- a/gui-editors/gui-editor-apex/src/main/webapp/js/__test__/ApexPolicyEditForm.test.js +++ b/gui-editors/gui-editor-apex/src/main/webapp/js/__test__/ApexPolicyEditForm.test.js @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2020-2021 Nordix Foundation + * 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. @@ -142,6 +142,35 @@ test('Test Update Trigger Event', () => { expect(mock_activate).toBeCalled(); }); +test('Test Update Trigger Event with firststate', () => { + document.documentElement.innerHTML = '' + + '
' + + ''; + let documentSpy = jest.spyOn(document, 'getElementById'); + let elementMock = document.getElementById("editEventFormSelectFirstState_dropdownList"); + elementMock.setAttribute("createEditOrView", "CREATE") + elementMock.setAttribute("disabled", "false") + elementMock.selectedOption = {"name": "name1", "version": "version1", "displaytext": "PeriodicEvent"}; + documentSpy.mockReturnValue(elementMock); + const mock_activate = jest.fn(mod.editPolicyForm_updateTriggerEventOptions); + mock_activate('events'); + expect(mock_activate).toBeCalled(); +}); + +test('Test editPolicyForm_getNextStateOptions', () => { + document.documentElement.innerHTML = '' + + '
  • a1
  • a2
  • ' + + ''; + let documentSpy = jest.spyOn(document, 'getElementById'); + let elementMock = document.getElementById("editEventFormStates"); + elementMock.value = 'notNullValue'; + elementMock.setAttribute("stateName", "state"); + documentSpy.mockReturnValue(elementMock); + let options = mod.editPolicyForm_getNextStateOptions(); + let expected = [{"name" : "NULL", "displaytext" : "None"}]; + expect(options).toStrictEqual(expected); +}); + test('Test activate CREATE', () => { jest.spyOn(apexUtils, 'apexUtils_removeElement').mockReturnValueOnce(null); const mock_activate = jest.fn(mod.editPolicyForm_activate); @@ -171,4 +200,66 @@ test('Test editPolicyForm_editPolicy_inner', () => { 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 +}); + +test('Test editPolicyForm_submitPressed CREATE with page', () => { + const jqXHR = { status: 200, responseText: "" }; + $.ajax = jest.fn().mockImplementation((args) => { + args.success(data, null, jqXHR); + }); + jest.spyOn(apexPolicyTab, 'policyTab_reset').mockReturnValueOnce(null); + jest.spyOn(keyInformationTab_reset, 'keyInformationTab_reset').mockReturnValueOnce(null); + jest.spyOn(apexUtils, 'apexUtils_removeElement').mockReturnValueOnce(null); + document.documentElement.innerHTML = '' + + '
  • a1
  • a2
  • ' + + ''; + let documentSpy = jest.spyOn(document, 'getElementById'); + let elementMock = document.getElementById("#editEventFormStates"); + elementMock.value = 'notNullValue'; + elementMock.setAttribute("stateName", "state"); + elementMock.selectedOption = {"name": "name1", "version": "version1"}; + elementMock.setAttribute("createEditOrView", "CREATE") + documentSpy.mockReturnValue(elementMock); + const mock_activate = jest.fn(mod.editPolicyForm_submitPressed); + mock_activate(); + expect(mock_activate).toBeCalled(); +}); + +test('Test editPolicyForm_submitPressed EDIT with page', () => { + const jqXHR = { status: 200, responseText: "" }; + $.ajax = jest.fn().mockImplementation((args) => { + args.success(data, null, jqXHR); + }); + jest.spyOn(apexPolicyTab, 'policyTab_reset').mockReturnValueOnce(null); + jest.spyOn(keyInformationTab_reset, 'keyInformationTab_reset').mockReturnValueOnce(null); + jest.spyOn(apexUtils, 'apexUtils_removeElement').mockReturnValueOnce(null); + document.documentElement.innerHTML = '' + + '
  • a1
  • a2
  • ' + + ''; + let documentSpy = jest.spyOn(document, 'getElementById'); + let elementMock = document.getElementById("#editEventFormStates"); + elementMock.value = 'notNullValue'; + elementMock.setAttribute("stateName", "state"); + elementMock.selectedOption = {"name": "name1", "version": "version1"}; + elementMock.setAttribute("createEditOrView", "EDIT") + documentSpy.mockReturnValue(elementMock); + const mock_activate = jest.fn(mod.editPolicyForm_submitPressed); + mock_activate(); + expect(mock_activate).toBeCalled(); +}); + +test('Test editPolicyForm_cancelPressed', () => { + jest.spyOn(apexPolicyTab, 'policyTab_reset').mockReturnValueOnce(null); + jest.spyOn(apexUtils, 'apexUtils_removeElement').mockReturnValueOnce(null); + const mock_activate = jest.fn(mod.editPolicyForm_cancelPressed); + mock_activate(); + expect(mock_activate).toBeCalled(); +}); + +test('Test editPolicyForm_generateUUIDPressed', () => { + document.documentElement.innerHTML = '' + + '
    test
    ' + + ''; + mod.editPolicyForm_generateUUIDPressed(); + expect(document.getElementById("editPolicyFormUuidInput").value).not.toBeNull(); +}); -- cgit 1.2.3-korg