-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
- Loading branch information
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
"@khanacademy/perseus": patch | ||
--- | ||
|
||
Split out validation logic in Radio | ||
Move and test Grapher's validator |
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@khanacademy/perseus": patch | ||
--- | ||
|
||
Omit unused data from interactive graph onChange callback |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
"@khanacademy/perseus": patch | ||
--- | ||
|
||
Split validation logic from LabelImage | ||
Port some tests to new custom matcher |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@khanacademy/perseus": patch | ||
--- | ||
|
||
Internal: remove dead code from InteractiveGraph.validate() |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@khanacademy/perseus": patch | ||
--- | ||
|
||
Split out InteractiveGraph validator |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@khanacademy/perseus": patch | ||
--- | ||
|
||
Split validation logic out of Matrix |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@khanacademy/perseus": patch | ||
--- | ||
|
||
Move validation logic out of the cs-program widget and add tests |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import {csProgramValidator} from "./cs-program-validator"; | ||
|
||
import type {PerseusCSProgramUserInput} from "../../validation.types"; | ||
|
||
describe("csProgramValidator", () => { | ||
it("is correct when the state from the iframe shows the status is correct", () => { | ||
// Arrange | ||
const state: PerseusCSProgramUserInput = { | ||
status: "correct", | ||
message: "Good job!", | ||
}; | ||
|
||
// Act | ||
const result = csProgramValidator(state); | ||
|
||
// Assert | ||
expect(result).toHaveBeenAnsweredCorrectly(); | ||
}); | ||
|
||
it("is incorrect when the state from the iframe shows the status is incorrect", () => { | ||
// Arrange | ||
const state: PerseusCSProgramUserInput = { | ||
status: "incorrect", | ||
message: "Try again!", | ||
}; | ||
|
||
// Act | ||
const result = csProgramValidator(state); | ||
|
||
// Assert | ||
expect(result).toHaveBeenAnsweredIncorrectly(); | ||
}); | ||
|
||
// Note: It looks like the iframe only says if the answer is correct or | ||
// incorrect, but status is set to "incomplete" by default. | ||
it("should return invalid score before user interactions", () => { | ||
// Arrange | ||
const state: PerseusCSProgramUserInput = { | ||
status: "incomplete", | ||
message: null, | ||
}; | ||
|
||
// Act | ||
const result = csProgramValidator(state); | ||
|
||
// Assert | ||
expect(result).toHaveInvalidInput("Keep going, you're not there yet!"); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import type {PerseusScore} from "../../types"; | ||
import type {PerseusCSProgramUserInput} from "../../validation.types"; | ||
|
||
export function csProgramValidator( | ||
state: PerseusCSProgramUserInput, | ||
): PerseusScore { | ||
// The iframe can tell us whether it's correct or incorrect, | ||
// and pass an optional message | ||
if (state.status === "correct") { | ||
return { | ||
type: "points", | ||
earned: 1, | ||
total: 1, | ||
message: state.message || null, | ||
}; | ||
} | ||
if (state.status === "incorrect") { | ||
return { | ||
type: "points", | ||
earned: 0, | ||
total: 1, | ||
message: state.message || null, | ||
}; | ||
} | ||
return { | ||
type: "invalid", | ||
message: "Keep going, you're not there yet!", | ||
}; | ||
} |