diff --git a/packages/perseus-core/src/types.ts b/packages/perseus-core/src/types.ts index f9b93fd731..2e71b875bd 100644 --- a/packages/perseus-core/src/types.ts +++ b/packages/perseus-core/src/types.ts @@ -14,7 +14,6 @@ type State = any; export interface RendererInterface { getSerializedState(): State; restoreSerializedState(state: State, callback?: () => void): void; - scoreInput(): KEScore; blur(): void; focus(): boolean | null | undefined; props: any; diff --git a/packages/perseus/src/__tests__/server-item-renderer.test.tsx b/packages/perseus/src/__tests__/server-item-renderer.test.tsx index aca6b1a413..60ffc47268 100644 --- a/packages/perseus/src/__tests__/server-item-renderer.test.tsx +++ b/packages/perseus/src/__tests__/server-item-renderer.test.tsx @@ -118,31 +118,6 @@ describe("server item renderer", () => { expect(screen.getByRole("textbox")).toBeVisible(); }); - it("should be invalid if no input provided", async () => { - // Arrange - const {renderer} = renderQuestion(itemWithInput); - - // Act - const score = await act(() => renderer.scoreInput()); - - // Assert - expect(score.correct).toBe(false); - expect(score.empty).toBe(true); - }); - - it("should be answerable", async () => { - // Arrange - const {renderer} = renderQuestion(itemWithInput); - await userEvent.type(screen.getByRole("textbox"), "-42"); - - // Act - const score = await act(() => renderer.scoreInput()); - - // Assert - expect(score.correct).toBe(true); - expect(score.empty).toBe(false); - }); - it("should pass showSolutions to the widgets", () => { // Arrange renderQuestion(itemWithRadioAndExpressionWidgets, Object.freeze({}), { diff --git a/packages/perseus/src/server-item-renderer.tsx b/packages/perseus/src/server-item-renderer.tsx index 8e5dff99b5..5152db3bde 100644 --- a/packages/perseus/src/server-item-renderer.tsx +++ b/packages/perseus/src/server-item-renderer.tsx @@ -19,7 +19,6 @@ import HintsRenderer from "./hints-renderer"; import LoadingContext from "./loading-context"; import {ApiOptions} from "./perseus-api"; import Renderer from "./renderer"; -import {scorePerseusItem} from "./renderer-util"; import Util from "./util"; import type {PerseusItem, ShowSolutions} from "./perseus-types"; @@ -347,41 +346,6 @@ export class ServerItemRenderer return this.questionRenderer.getUserInputMap(); } - /** - * Grades the item. - * - * @deprecated use scorePerseusItem - */ - scoreInput(): KEScore { - const guess = this.getUserInput(); - const score = scorePerseusItem( - this.props.item.question, - guess, - this.context.strings, - this.context.locale, - ); - - // Continue to include an empty guess for the now defunct answer area. - // TODO(alex): Check whether we rely on the format here for - // analyzing ProblemLogs. If not, remove this layer. - const maxCompatGuess = [this.questionRenderer.getUserInput(), []]; - - const keScore = Util.keScoreFromPerseusScore( - score, - maxCompatGuess, - this.questionRenderer.getSerializedState(), - ); - - const emptyQuestionAreaWidgets = this.questionRenderer.emptyWidgets(); - - this.setState({ - questionCompleted: keScore.correct, - questionHighlightedWidgets: emptyQuestionAreaWidgets, - }); - - return keScore; - } - /** * Returns an array of all widget IDs in the order they occur in * the question content. diff --git a/packages/perseus/src/widget-container.tsx b/packages/perseus/src/widget-container.tsx index 7396b70ba7..597f34774f 100644 --- a/packages/perseus/src/widget-container.tsx +++ b/packages/perseus/src/widget-container.tsx @@ -153,7 +153,7 @@ class WidgetContainer extends React.Component { : {...this.props.linterContext, highlightLint: false}; // Note: if you add more props here, please consider whether or not - // it should be auto-serialized (e.g. used in scoreInput()). See + // it should be auto-serialized. See // widget-jsonify-deprecated.jsx and widget-prop-denylist.jsx // We default to an empty object for style instead of null diff --git a/packages/perseus/src/widgets/expression/score-expression.ts b/packages/perseus/src/widgets/expression/score-expression.ts index 029a4e987b..dfe4269d61 100644 --- a/packages/perseus/src/widgets/expression/score-expression.ts +++ b/packages/perseus/src/widgets/expression/score-expression.ts @@ -165,9 +165,6 @@ function scoreExpression( // We matched a graded answer form, so we can now tell the user // whether their input was correct or incorrect, and hand out // points accordingly - // TODO(eater): Seems silly to translate result to this - // invalid/points thing and immediately translate it back in - // ItemRenderer.scoreInput() return { type: "points", earned: matchingAnswerForm.considered === "correct" ? 1 : 0, diff --git a/packages/perseus/src/widgets/input-number/score-input-number.ts b/packages/perseus/src/widgets/input-number/score-input-number.ts index ca1a9dfcb6..30ae3a6956 100644 --- a/packages/perseus/src/widgets/input-number/score-input-number.ts +++ b/packages/perseus/src/widgets/input-number/score-input-number.ts @@ -75,8 +75,6 @@ function scoreInputNumber( const result = val(currentValue); - // TODO(eater): Seems silly to translate result to this invalid/points - // thing and immediately translate it back in ItemRenderer.scoreInput() if (result.empty) { return { type: "invalid", diff --git a/packages/perseus/src/widgets/numeric-input/score-numeric-input.ts b/packages/perseus/src/widgets/numeric-input/score-numeric-input.ts index d1aa76782f..cf23c5ad28 100644 --- a/packages/perseus/src/widgets/numeric-input/score-numeric-input.ts +++ b/packages/perseus/src/widgets/numeric-input/score-numeric-input.ts @@ -154,9 +154,6 @@ function scoreNumericInput( guess: localValue, }; - // TODO(eater): Seems silly to translate result to this - // invalid/points thing and immediately translate it - // back in ItemRenderer.scoreInput() if (result.empty) { return { type: "invalid", diff --git a/testing/server-item-renderer-with-debug-ui.tsx b/testing/server-item-renderer-with-debug-ui.tsx index 029ca1c87b..e9294e2e39 100644 --- a/testing/server-item-renderer-with-debug-ui.tsx +++ b/testing/server-item-renderer-with-debug-ui.tsx @@ -4,6 +4,7 @@ import {Strut} from "@khanacademy/wonder-blocks-layout"; import * as React from "react"; import * as Perseus from "../packages/perseus/src/index"; +import {mockStrings} from "../packages/perseus/src/strings"; import KEScoreUI from "./ke-score-ui"; import SideBySide from "./side-by-side"; @@ -29,6 +30,31 @@ export const ServerItemRendererWithDebugUI = ({ const [state, setState] = React.useState(null); const options = apiOptions || Object.freeze({}); + const getKeScore = () => { + const renderer = ref.current; + if (!renderer) { + return; + } + + const userInput = renderer.getUserInput(); + const score = Perseus.scorePerseusItem( + item.question, + userInput, + mockStrings, + "en", + ); + + // Continue to include an empty guess for the now defunct answer area. + // TODO(alex): Check whether we rely on the format here for + // analyzing ProblemLogs. If not, remove this layer. + const maxCompatGuess = [renderer.getUserInputLegacy(), []]; + return Perseus.Util.keScoreFromPerseusScore( + score, + maxCompatGuess, + renderer.getSerializedState().question, + ); + }; + return ( Check diff --git a/yarn.lock b/yarn.lock index ee2e5b0fc5..ee32913250 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5166,16 +5166,11 @@ caniuse-api@^3.0.0: lodash.memoize "^4.1.2" lodash.uniq "^4.5.0" -caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001332, caniuse-lite@^1.0.30001541, caniuse-lite@^1.0.30001587: +caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001332, caniuse-lite@^1.0.30001541, caniuse-lite@^1.0.30001587, caniuse-lite@^1.0.30001669: version "1.0.30001685" resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001685.tgz" integrity sha512-e/kJN1EMyHQzgcMEEgoo+YTCO1NGCmIYHk5Qk8jT6AazWemS5QFKJ5ShCJlH3GZrNIdZofcNCEwZqbMjjKzmnA== -caniuse-lite@^1.0.30001669: - version "1.0.30001685" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001685.tgz#2d10d36c540a9a5d47ad6ab9e1ed5f61fdeadd8c" - integrity sha512-e/kJN1EMyHQzgcMEEgoo+YTCO1NGCmIYHk5Qk8jT6AazWemS5QFKJ5ShCJlH3GZrNIdZofcNCEwZqbMjjKzmnA== - caseless@~0.12.0: version "0.12.0" resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc"