Skip to content

Commit

Permalink
Remove empty numeric-input validator
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremywiebe committed Nov 20, 2024
1 parent 33a71ff commit 6a26500
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 109 deletions.
4 changes: 1 addition & 3 deletions packages/perseus/src/validation.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,12 @@ export type PerseusNumericInputRubric = {
answers: ReadonlyArray<PerseusNumericInputAnswer>;
// A coefficient style number allows the student to use - for -1 and an empty string to mean 1.
coefficient: boolean;
} & PerseusNumericInputValidationData;
};

export type PerseusNumericInputUserInput = {
currentValue: string;
};

export type PerseusNumericInputValidationData = Empty;

export type PerseusOrdererRubric = PerseusOrdererWidgetOptions;

export type PerseusOrdererUserInput = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as Dependencies from "../../dependencies";
import {mockStrings} from "../../strings";

import scoreNumericInput, {maybeParsePercentInput} from "./score-numeric-input";
import * as NumericInputValidator from "./validate-numeric-input";

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

Expand All @@ -14,64 +13,6 @@ describe("static function validate", () => {
);
});

it("should be correctly answerable if validation passes", function () {
// Arrange
const mockValidator = jest
.spyOn(NumericInputValidator, "default")
.mockReturnValue(null);
const rubric: PerseusNumericInputRubric = {
answers: [
{
value: 1,
status: "correct",
maxError: 0,
simplify: "",
strict: false,
message: "",
},
],
coefficient: true,
};

const userInput = {currentValue: "1"} as const;

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

// Assert
expect(mockValidator).toHaveBeenCalledWith(userInput, rubric);
expect(score).toHaveBeenAnsweredCorrectly();
});

it("should return 'empty' result if validation fails", function () {
// Arrange
const mockValidator = jest
.spyOn(NumericInputValidator, "default")
.mockReturnValue({type: "invalid", message: null});
const rubric: PerseusNumericInputRubric = {
answers: [
{
value: 1,
status: "correct",
maxError: 0,
simplify: "",
strict: false,
message: "",
},
],
coefficient: true,
};

const userInput = {currentValue: "1"} as const;

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

// Assert
expect(mockValidator).toHaveBeenCalledWith(userInput, rubric);
expect(score).toHaveInvalidInput();
});

it("with a simple value", () => {
const rubric: PerseusNumericInputRubric = {
answers: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import TexWrangler from "../../tex-wrangler";
import KhanAnswerTypes from "../../util/answer-types";

import validateNumericInput from "./validate-numeric-input";

import type {MathFormat, PerseusNumericInputAnswer} from "../../perseus-types";
import type {PerseusStrings} from "../../strings";
import type {PerseusScore} from "../../types";
Expand Down Expand Up @@ -63,7 +61,7 @@ export function maybeParsePercentInput(
return value / 100;
}

// Otherwise, we return input valuåe (number) stripped of the "%".
// Otherwise, we return input value (number) stripped of the "%".
return value;
}

Expand All @@ -72,11 +70,6 @@ function scoreNumericInput(
rubric: PerseusNumericInputRubric,
strings: PerseusStrings,
): PerseusScore {
const validationResult = validateNumericInput(userInput, rubric);
if (validationResult != null) {
return validationResult;
}

const defaultAnswerForms = answerFormButtons
.map((e) => e["value"])
// Don't default to validating the answer as a pi answer
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit 6a26500

Please sign in to comment.