Skip to content

Commit

Permalink
Update test
Browse files Browse the repository at this point in the history
Revert values to options
Add changed to userInput
Refactor matchers
Add test for invalid logic
  • Loading branch information
Myranae committed Sep 23, 2024
1 parent cce97f8 commit f83c4cc
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions packages/perseus/src/widgets/sorter/sorter-validator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import type {Rubric, UserInput} from "./sorter.types";
describe("SorterValidator", () => {
it("is correct when the user input values are in the order defined in the rubric", () => {
const userInput: UserInput = {
values: ["$0.005$ kilograms", "$15$ grams", "$55$ grams"],
options: ["$0.005$ kilograms", "$15$ grams", "$55$ grams"],
changed: true,
};
const rubric: Rubric = {
padding: true,
Expand All @@ -18,19 +19,29 @@ describe("SorterValidator", () => {

it("is incorrect when the user input values are not in the order defined in the rubric", () => {
const userInput: UserInput = {
values: ["$15$ grams", "$55$ grams", "$0.005$ kilograms"],
options: ["$15$ grams", "$55$ grams", "$0.005$ kilograms"],
changed: true,
};
const rubric: Rubric = {
padding: true,
layout: "horizontal",
correct: ["$0.005$ kilograms", "$15$ grams", "$55$ grams"],
};
const result = sorterValidator(userInput, rubric);
expect(result).toEqual({
type: "points",
earned: 0,
total: 1,
message: null,
});
expect(result).toHaveBeenAnsweredIncorrectly();
});

it("is invalid when the user has not made any changes", () => {
const userInput: UserInput = {
options: ["$15$ grams", "$55$ grams", "$0.005$ kilograms"],
changed: false,
};
const rubric: Rubric = {
padding: true,
layout: "horizontal",
correct: ["$0.005$ kilograms", "$15$ grams", "$55$ grams"],
};
const result = sorterValidator(userInput, rubric);
expect(result).toHaveInvalidInput();
});
});

0 comments on commit f83c4cc

Please sign in to comment.