-
Notifications
You must be signed in to change notification settings - Fork 350
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
80d9120
commit 47794bd
Showing
4 changed files
with
95 additions
and
1 deletion.
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
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
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
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 @@ | ||
import {generateExamples, shouldShowExamples} from "./utils"; | ||
|
||
import type {PerseusStrings} from "../../strings"; | ||
import type {PerseusNumericInputAnswerForm} from "@khanacademy/perseus-core"; | ||
|
||
describe("generateExamples", () => { | ||
it("returns an array of examples", () => { | ||
const answerForms: readonly PerseusNumericInputAnswerForm[] = [ | ||
{ | ||
name: "integer", | ||
simplify: "optional", | ||
}, | ||
{ | ||
name: "proper", | ||
simplify: "required", | ||
}, | ||
]; | ||
const strings: Partial<PerseusStrings> = { | ||
yourAnswer: "Your answer", | ||
integerExample: "Integer example", | ||
properExample: "Proper example", | ||
simplifiedProperExample: "Simplified proper example", | ||
}; | ||
const expected = [ | ||
"Your answer", | ||
"Integer example", | ||
"Simplified proper example", | ||
]; | ||
expect( | ||
generateExamples(answerForms, strings as PerseusStrings), | ||
).toEqual(expected); | ||
}); | ||
}); | ||
|
||
describe("shouldShowExamples", () => { | ||
it("returns true when not all forms are accepted", () => { | ||
const answerForms: readonly PerseusNumericInputAnswerForm[] = [ | ||
{ | ||
name: "integer", | ||
simplify: "optional", | ||
}, | ||
{ | ||
name: "proper", | ||
simplify: "required", | ||
}, | ||
]; | ||
expect(shouldShowExamples(answerForms)).toBe(true); | ||
}); | ||
|
||
it("returns false when all forms are accepted", () => { | ||
const answerForms: readonly PerseusNumericInputAnswerForm[] = [ | ||
{ | ||
name: "integer", | ||
simplify: "optional", | ||
}, | ||
{ | ||
name: "proper", | ||
simplify: "required", | ||
}, | ||
{ | ||
name: "improper", | ||
simplify: "optional", | ||
}, | ||
{ | ||
name: "mixed", | ||
simplify: "required", | ||
}, | ||
{ | ||
name: "decimal", | ||
simplify: "optional", | ||
}, | ||
{ | ||
name: "pi", | ||
simplify: "required", | ||
}, | ||
]; | ||
expect(shouldShowExamples(answerForms)).toBe(false); | ||
}); | ||
|
||
it("returns false when no forms are accepted", () => { | ||
const answerForms = []; | ||
expect(shouldShowExamples(answerForms)).toBe(false); | ||
}); | ||
}); |