Skip to content

Commit

Permalink
Measurer and DeprecatedStandin to use noopValidator (#1651)
Browse files Browse the repository at this point in the history
## Summary:
Just made sense to share this logic

Issue: LEMS-2371

## Test plan:
No logic should change

Author: handeyeco

Reviewers: Myranae, jeremywiebe

Required Reviewers:

Approved By: Myranae

Checks: ✅ codecov/project, ✅ codecov/patch, ✅ Upload Coverage (ubuntu-latest, 20.x), ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Jest Coverage (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), 🚫 Upload Coverage, ✅ gerald, 🚫 Publish npm snapshot (ubuntu-latest, 20.x), 🚫 Jest Coverage (ubuntu-latest, 20.x), 🚫 Check builds for changes in size (ubuntu-latest, 20.x), 🚫 Cypress (ubuntu-latest, 20.x), 🚫 Check for .changeset entries for all changed files (ubuntu-latest, 20.x), 🚫 Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), 🚫 Upload Coverage, ✅ gerald, 🚫 Publish npm snapshot (ubuntu-latest, 20.x), 🚫 Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), 🚫 Jest Coverage (ubuntu-latest, 20.x), 🚫 Check builds for changes in size (ubuntu-latest, 20.x), 🚫 Check for .changeset entries for all changed files (ubuntu-latest, 20.x), 🚫 Cypress (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x), ✅ gerald

Pull Request URL: #1651
  • Loading branch information
handeyeco authored Sep 19, 2024
1 parent b5594e8 commit 1080a62
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 37 deletions.
5 changes: 5 additions & 0 deletions .changeset/hip-cameras-mix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/perseus": patch
---

Consolidate Measurer and DeprecatedStandin to use noopValidator
22 changes: 21 additions & 1 deletion packages/perseus/src/widgets/__shared__/noop-validator.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@ import noopValidator from "./noop-validator";

describe("noop-validator", () => {
it("returns a pointless object", () => {
expect(noopValidator()).toHaveBeenAnsweredCorrectly();
const result = noopValidator();
expect(result).toHaveBeenAnsweredCorrectly();

// This is is just to narrow the type
// the expect above checks correctness
if (result.type === "points") {
expect(result.earned).toBe(0);
expect(result.total).toBe(0);
}
});

it("can be configured to be pointful", () => {
const result = noopValidator(1);
expect(result).toHaveBeenAnsweredCorrectly();

// This is is just to narrow the type
// the expect above checks correctness
if (result.type === "points") {
expect(result.earned).toBe(1);
expect(result.total).toBe(1);
}
});
});
6 changes: 3 additions & 3 deletions packages/perseus/src/widgets/__shared__/noop-validator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import type {PerseusScore} from "../../types";
* validation logic and the thing validating an exercise
* should just know to skip these
*/
function noopValidator(): PerseusScore {
function noopValidator(points: number = 0): PerseusScore {
return {
type: "points",
earned: 0,
total: 0,
earned: points,
total: points,
message: null,
};
}
Expand Down
10 changes: 3 additions & 7 deletions packages/perseus/src/widgets/deprecated-standin/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Banner from "@khanacademy/wonder-blocks-banner";
import React from "react";

import {PerseusI18nContext} from "../../components/i18n-context";
import noopValidator from "../__shared__/noop-validator";

import type {PerseusScore, WidgetExports} from "../../types";

Expand All @@ -18,20 +19,15 @@ class DeprecatedStandin extends React.Component<Props> {
static validate(userInput: UserInput, rubric: Rubric): PerseusScore {
// Since this mean to replace an existing widget the learner
// WILL earn points for this widget
return {
type: "points",
earned: 1,
total: 1,
message: null,
};
return noopValidator(1);
}

getUserInput: () => UserInput = () => {
return {};
};

simpleValidate: (arg1: Rubric) => PerseusScore = (rubric) => {
return DeprecatedStandin.validate(this.getUserInput(), rubric);
return noopValidator(1);
};

render() {
Expand Down
12 changes: 0 additions & 12 deletions packages/perseus/src/widgets/measurer/measurer-validator.test.ts

This file was deleted.

10 changes: 0 additions & 10 deletions packages/perseus/src/widgets/measurer/measurer-validator.ts

This file was deleted.

7 changes: 3 additions & 4 deletions packages/perseus/src/widgets/measurer/measurer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import _ from "underscore";
import SvgImage from "../../components/svg-image";
import {ApiOptions} from "../../perseus-api";
import GraphUtils from "../../util/graph-utils";

import measurerValidator from "./measurer-validator";
import noopValidator from "../__shared__/noop-validator";

import type {Coord} from "../../interactive2/types";
import type {WidgetExports} from "../../types";
Expand Down Expand Up @@ -148,7 +147,7 @@ const Measurer: any = createReactClass({
},

simpleValidate: function () {
return measurerValidator();
return noopValidator(1);
},

focus: $.noop,
Expand Down Expand Up @@ -186,7 +185,7 @@ const Measurer: any = createReactClass({
});

_.extend(Measurer, {
validate: measurerValidator,
validate: noopValidator(1),
});

const propUpgrades = {
Expand Down

0 comments on commit 1080a62

Please sign in to comment.