-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cc2f19f
commit 41e86c3
Showing
2 changed files
with
168 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/*global describe, it, expect, beforeEach -- functions provided by Jasmine */ | ||
import { ActivityConfigValidator } from "../../src/ActivityConfigValidator.js" | ||
import { ACTIVITY_2PANELS_1ACTION } from "../resources/TestActivityFiles.js"; | ||
import { ConfigValidationError } from "../../src/ConfigValidationError.js" | ||
|
||
|
||
const EXPECTED_FILE_TYPE = "ActivityConfig"; | ||
|
||
describe("ActivityConfigValidator", () => { | ||
|
||
describe("constructor", () => { | ||
it("can be created", () => { | ||
// Call the target object | ||
let acv = new ActivityConfigValidator(); | ||
|
||
// Check the expected results | ||
expect(acv).toBeInstanceOf(ActivityConfigValidator); | ||
}) | ||
}) | ||
|
||
describe("validate tool configration", () => { | ||
let acv; | ||
let activityConfig; | ||
|
||
//Setup | ||
beforeEach( () => { | ||
activityConfig = JSON.parse(ACTIVITY_2PANELS_1ACTION); | ||
acv = new ActivityConfigValidator(); | ||
}) | ||
|
||
it("reports no errors for a valid config", () => { | ||
// Call the target object | ||
let errors = acv.validateConfigFile(activityConfig); | ||
|
||
// Check the expected results | ||
expect(errors).toHaveSize(0); | ||
}) | ||
|
||
it("returns errors that are ConfigValidationError instances",() => { | ||
delete activityConfig.activities[0].id; | ||
|
||
// Call the target object | ||
let errors = acv.validateConfigFile(activityConfig); | ||
let e = errors[0]; | ||
|
||
// Check the expected results | ||
expect(e).toBeInstanceOf(ConfigValidationError); | ||
expect(e.fileType).toEqual(EXPECTED_FILE_TYPE); | ||
}) | ||
|
||
it("returns an error if the config has no id key", () => { | ||
delete activityConfig.activities[0].id; | ||
|
||
// Call the target object | ||
let errors = acv.validateConfigFile(activityConfig); | ||
let e = errors[0]; | ||
|
||
// Check the expected results | ||
expect(errors).toHaveSize(1); | ||
checkErrorPopulated(e); | ||
}) | ||
|
||
it("returns an error if a panel in config has no id key", () => { | ||
delete activityConfig.activities[0].panels[1].id; | ||
|
||
// Call the target object | ||
let errors = acv.validateConfigFile(activityConfig); | ||
let e = errors[0]; | ||
|
||
// Check the expected results | ||
expect(errors).toHaveSize(1); | ||
checkErrorPopulated(e); | ||
}) | ||
}) | ||
}) | ||
|
||
function checkErrorPopulated(error){ | ||
const MIN_LENGTH = 3; | ||
expect(error).toBeInstanceOf(ConfigValidationError); | ||
expect(error.fileType).toEqual(EXPECTED_FILE_TYPE); | ||
expect(error.location.length).toBeGreaterThanOrEqual(MIN_LENGTH); | ||
expect(error.category.length).toBeGreaterThanOrEqual(MIN_LENGTH); | ||
expect(error.message.length).toBeGreaterThanOrEqual(MIN_LENGTH); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/*global describe, it, expect, beforeEach -- functions provided by Jasmine */ | ||
import { ToolConfigValidator } from "../../src/ToolConfigValidator" | ||
import { TOOL_1PANELDEF_1FUNCTION } from "../resources/TestToolFiles.js"; | ||
import { ConfigValidationError } from "../../src/ConfigValidationError.js" | ||
|
||
|
||
const EXPECTED_FILE_TYPE = "ToolConfig"; | ||
|
||
describe("ToolConfigValidator", () => { | ||
|
||
describe("constructor", () => { | ||
it("can be created", () => { | ||
// Call the target object | ||
let tcv = new ToolConfigValidator(); | ||
|
||
// Check the expected results | ||
expect(tcv).toBeInstanceOf(ToolConfigValidator); | ||
}) | ||
}) | ||
|
||
describe("validate tool configration", () => { | ||
let tcv; | ||
let toolConfig; | ||
|
||
//Setup | ||
beforeEach( () => { | ||
toolConfig = JSON.parse(TOOL_1PANELDEF_1FUNCTION); | ||
tcv = new ToolConfigValidator(); | ||
}) | ||
|
||
it("reports no errors for a valid config", () => { | ||
// Call the target object | ||
let errors = tcv.validateConfigFile(toolConfig); | ||
|
||
// Check the expected results | ||
expect(errors).toHaveSize(0); | ||
}) | ||
|
||
it("returns errors that are ConfigValidationError instances",() => { | ||
delete toolConfig.tool.id; | ||
|
||
// Call the target object | ||
let errors = tcv.validateConfigFile(toolConfig); | ||
let e = errors[0]; | ||
|
||
// Check the expected results | ||
expect(e).toBeInstanceOf(ConfigValidationError); | ||
expect(e.fileType).toEqual(EXPECTED_FILE_TYPE); | ||
}) | ||
|
||
it("returns an error if the config has no id key", () => { | ||
delete toolConfig.tool.id; | ||
|
||
// Call the target object | ||
let errors = tcv.validateConfigFile(toolConfig); | ||
let e = errors[0]; | ||
|
||
// Check the expected results | ||
expect(errors).toHaveSize(1); | ||
checkErrorPopulated(e); | ||
}) | ||
|
||
it("returns an error if a panel definition in the config has no id key", () => { | ||
delete toolConfig.tool.panelDefs[0].id; | ||
|
||
// Call the target object | ||
let errors = tcv.validateConfigFile(toolConfig); | ||
let e = errors[0]; | ||
|
||
// Check the expected results | ||
expect(errors).toHaveSize(1); | ||
checkErrorPopulated(e); | ||
}) | ||
}) | ||
}) | ||
|
||
function checkErrorPopulated(error){ | ||
const MIN_LENGTH = 3; | ||
expect(error).toBeInstanceOf(ConfigValidationError); | ||
expect(error.fileType).toEqual(EXPECTED_FILE_TYPE); | ||
expect(error.location.length).toBeGreaterThanOrEqual(MIN_LENGTH); | ||
expect(error.category.length).toBeGreaterThanOrEqual(MIN_LENGTH); | ||
expect(error.message.length).toBeGreaterThanOrEqual(MIN_LENGTH); | ||
} |