Skip to content

Commit

Permalink
Consolidated ActivityManager constructor tests into their own describ…
Browse files Browse the repository at this point in the history
…e so to reuse test setup and removed unnecessary TestUtility function configToString.
  • Loading branch information
barnettwilliam committed Mar 5, 2024
1 parent cac21eb commit 52769f3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 75 deletions.
9 changes: 0 additions & 9 deletions platform/test/resources/TestUtility.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
108 changes: 42 additions & 66 deletions platform/test/spec/testActivityManagerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down Expand Up @@ -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) + "'" );
}
})

Expand Down

0 comments on commit 52769f3

Please sign in to comment.