From 52769f3d17c78207d5778a9ec46d8e090149bfb0 Mon Sep 17 00:00:00 2001 From: Will Barnett Date: Tue, 5 Mar 2024 15:05:35 +0000 Subject: [PATCH] Consolidated ActivityManager constructor tests into their own describe so to reuse test setup and removed unnecessary TestUtility function configToString. --- platform/test/resources/TestUtility.js | 9 -- platform/test/spec/testActivityManagerSpec.js | 108 +++++++----------- 2 files changed, 42 insertions(+), 75 deletions(-) diff --git a/platform/test/resources/TestUtility.js b/platform/test/resources/TestUtility.js index 851981b..2f8a132 100644 --- a/platform/test/resources/TestUtility.js +++ b/platform/test/resources/TestUtility.js @@ -11,12 +11,3 @@ export function configObjectEquals(configA, configB){ return (strConfigA === strConfigB) } - -/** - * Prints a configuration object including its values. - * @param {Object} config - * @returns {string} the string representation - */ -export function configToString (config) { - return JSON.stringify(config); -} \ No newline at end of file diff --git a/platform/test/spec/testActivityManagerSpec.js b/platform/test/spec/testActivityManagerSpec.js index 37cd6cc..d9bf38f 100644 --- a/platform/test/spec/testActivityManagerSpec.js +++ b/platform/test/spec/testActivityManagerSpec.js @@ -6,91 +6,67 @@ import { ActivityConfigValidator } from "../../src/ActivityConfigValidator.js"; import { utility } from "../../src/Utility.js"; import { ACTIVITY_2PANELS_1ACTION } from "../resources/TestActivityFiles.js"; import { TOOL_1PANELDEF_1FUNCTION } from "../resources/TestToolFiles.js"; -import { configObjectEquals, configToString } from "../resources/TestUtility.js"; +import { configObjectEquals } from "../resources/TestUtility.js"; describe("ActivityManager", () => { - it("can be created", () => { + describe("constructor", () => { // Setup - const fileh = new FileHandler("test://th.url") - const refPanelDef = () => {}; - - // Call the target object - var am = new ActivityManager(refPanelDef , fileh); - - // Check the expected results - expect(am).toBeInstanceOf(ActivityManager); - }) - - it("constructor - initialises the configValidator property", () => { - // Setup - const fileh = new FileHandler("test://th.url") - const refPanelDef = () => {}; + const ACTIVITY_URL="test://a.url"; + let am; + let fileh; + let refPanelDef; + let spySearch; - // Call the target object - var am = new ActivityManager(refPanelDef , fileh); + beforeEach( () => { - // Check the expected results - expect(am.configValidator).toBeInstanceOf(ActivityConfigValidator); - }) + fileh = new FileHandler("test://th.url") + refPanelDef = () => {}; - it("constructor - initialises the accessPanelDef property using param panelDefAccessor", () => { - // Setup - const fileh = new FileHandler("test://th.url") - const refPanelDef = () => {}; + spySearch = spyOn( utility, "getWindowLocationSearch"); - // Call the target object - var am = new ActivityManager(refPanelDef , fileh); + // Call the target object + am = new ActivityManager(refPanelDef, fileh); + }) // Check the expected results - expect(am.accessPanelDef).toBe(refPanelDef); - }) - - it("constructor - initialises the fileHandler property using param fileHandler", () => { - // Setup - const fileh = new FileHandler("test://th.url") - const refPanelDef = () => {}; + it("can be created", () => { + expect(am).toBeInstanceOf(ActivityManager); + }) - // Call the target object - var am = new ActivityManager(refPanelDef , fileh); + it("initialises the configValidator property", () => { + expect(am.configValidator).toBeInstanceOf(ActivityConfigValidator); + }) - // Check the expected results - expect(am.fileHandler).toBe(fileh); - }) + it("initialises the accessPanelDef property using param panelDefAccessor", () => { + expect(am.accessPanelDef).toBe(refPanelDef); + }) - it("constructor - uses the query string to set the activitiesUrl property", () => { - // Setup - const ACTIVITY_URL="test://a.url"; - const QUERY = "?activities=" + ACTIVITY_URL; - const fileh = new FileHandler("test://th.url") - const refPanelDef = () => {}; + it("initialises the fileHandler property using param fileHandler", () => { + expect(am.fileHandler).toBe(fileh); + }) - spyOn( utility, "getWindowLocationSearch").and.returnValue(QUERY); + it("uses the query string to set the activitiesUrl property", () => { + const QUERY = "?activities=" + ACTIVITY_URL; + spySearch.and.returnValue(QUERY); //Update the spy - // Call the target object - var am = new ActivityManager(refPanelDef , fileh); + am = new ActivityManager(refPanelDef, fileh); - // Check the expected results - expect(utility.getWindowLocationSearch).toHaveBeenCalled(); - expect(am.activitiesUrl).toBe(ACTIVITY_URL); - }) + expect(utility.getWindowLocationSearch).toHaveBeenCalled(); + expect(am.activitiesUrl).toBe(ACTIVITY_URL); + }) - it ("constructor - if the current activity is provided in the url query string, set the activityId property", () => { - // Setup - const ACTIVITY_URL="test://a.url"; - const ACTIVITY_ID="a1" - const QUERY = "?"+ ACTIVITY_ID + "=&" + "activities=" + ACTIVITY_URL; - const fileh = new FileHandler("test://th.url") - const refPanelDef = () => {}; + it ("if the current activity is provided in the url query string, set the activityId property", () => { + const ACTIVITY_ID="a1" + const QUERY = "?"+ ACTIVITY_ID + "=&" + "activities=" + ACTIVITY_URL; + spySearch.and.returnValue(QUERY); // Update the spy - spyOn( utility, "getWindowLocationSearch").and.returnValue(QUERY); + am = new ActivityManager(refPanelDef , fileh); - // Call the target object - var am = new ActivityManager(refPanelDef , fileh); + expect(am.activityId).toBe(ACTIVITY_ID); + }) - // Check the expected results - expect(am.activityId).toBe(ACTIVITY_ID); }) it("initializeActivities - causes the activity file to be fetched from its URL using the fileHandler", () => { @@ -200,12 +176,12 @@ describe("ActivityManager", () => { expect(action.source).toBeInstanceOf(Object); if (!configObjectEquals( action.source, expectedPanelSource )) { - fail("Expected action's source panel'" + configToString(action.source) + "' to equal'" + configToString(expectedPanelSource) + "'"); + fail("Expected action's source panel'" + JSON.stringify(action.source) + "' to equal'" + JSON.stringify(expectedPanelSource) + "'"); } expect(action.output).toBeInstanceOf(Object); if (!configObjectEquals( action.output, expectedPanelOutput )){ - fail("Expected action's source panel'" + configToString(action.output) + "' to equal'" + configToString(expectedPanelOutput) + "'" ); + fail("Expected action's source panel'" + JSON.stringify(action.output) + "' to equal'" + JSON.stringify(expectedPanelOutput) + "'" ); } })