Skip to content

Commit

Permalink
Add test to document empty expression can be a correct answer (#2003)
Browse files Browse the repository at this point in the history
## Summary:
RendererUtil: remove unnecessary cast to UserInput

Issue: LEMS-2561


## Test plan:

Author: jeremywiebe

Reviewers: jeremywiebe, handeyeco, Myranae

Required Reviewers:

Approved By: handeyeco

Checks: ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ⏹️  [cancelled] Publish npm snapshot (ubuntu-latest, 20.x), ⏹️  [cancelled] Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ⏹️  [cancelled] Cypress (ubuntu-latest, 20.x), ⏹️  [cancelled] Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ⏹️  [cancelled] Check builds for changes in size (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x)

Pull Request URL: #2003
  • Loading branch information
jeremywiebe authored Dec 16, 2024
1 parent 0db68d2 commit 193d913
Showing 1 changed file with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,39 @@ import scoreNumericInput, {maybeParsePercentInput} from "./score-numeric-input";

import type {PerseusNumericInputRubric} from "../../validation.types";

describe("static function validate", () => {
describe("scoreNumericInput", () => {
beforeEach(() => {
jest.spyOn(Dependencies, "getDependencies").mockReturnValue(
testDependencies,
);
});

it("is correct when input is empty but answer is 1 and coefficient: true", () => {
const rubric: PerseusNumericInputRubric = {
answers: [
{
value: 1,
status: "correct",
maxError: 0,
simplify: "optional",
strict: false,
message: "",
},
],
coefficient: true,
};

const userInput = {
// Empty input being translated to "1" depends on coefficient being
// true.
currentValue: "",
};

const score = scoreNumericInput(userInput, rubric, mockStrings);

expect(score).toHaveBeenAnsweredCorrectly();
});

it("with a simple value", () => {
const rubric: PerseusNumericInputRubric = {
answers: [
Expand Down

0 comments on commit 193d913

Please sign in to comment.