Skip to content

Commit 1e83417

Browse files
committed
[tb/LEMS-2523/merge-get-user-input-map] Replace getUserInput with getUserInputMap
Also removes a test that was testing the deprecated functionality
1 parent cec57bb commit 1e83417

File tree

10 files changed

+75
-158
lines changed

10 files changed

+75
-158
lines changed

packages/perseus/src/__tests__/renderer-api.test.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,9 @@ describe("Perseus API", function () {
101101
const {renderer} = renderQuestion(mockWidget1Item.question);
102102
act(() =>
103103
renderer.setInputValue(["mock-widget 1"], "3", function () {
104-
const guess =
105-
renderer.getUserInput()[0] as PerseusMockWidgetUserInput;
104+
const guess = renderer.getUserInputMap()[
105+
"mock-widget 1"
106+
] as PerseusMockWidgetUserInput;
106107
expect(guess?.currentValue).toBe("3");
107108
resolve(null);
108109
}),

packages/perseus/src/__tests__/renderer.test.tsx

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,50 +1441,6 @@ describe("renderer", () => {
14411441
);
14421442
});
14431443

1444-
it("[DEPRECATED] should return user input array", async () => {
1445-
// Arrange
1446-
const {renderer} = renderQuestion({
1447-
...question2,
1448-
content:
1449-
"Input 1: [[☃ mock-widget 1]]\n\n" +
1450-
"Input 2: [[☃ mock-widget 2]]\n\n" +
1451-
"A widget that doesn't implement getUserInput: [[☃ image 1]]",
1452-
widgets: {
1453-
...question2.widgets,
1454-
"mock-widget 2": {
1455-
...question2.widgets["mock-widget 1"],
1456-
static: true,
1457-
},
1458-
"image 1": {
1459-
type: "image",
1460-
graded: false,
1461-
options: {
1462-
backgroundImage: {
1463-
url: "https://example.com/cat.png",
1464-
width: 100,
1465-
height: 100,
1466-
},
1467-
},
1468-
},
1469-
},
1470-
});
1471-
1472-
const textboxes = screen.getAllByRole("textbox");
1473-
for (let i = 0; i < textboxes.length; i++) {
1474-
await userEvent.type(textboxes[i], i.toString());
1475-
}
1476-
1477-
// Act
1478-
const input = renderer.getUserInput();
1479-
1480-
// Assert
1481-
expect(input).toStrictEqual([
1482-
{currentValue: "0"},
1483-
{currentValue: "1"},
1484-
undefined, // image widget doesn't implement getUserinput
1485-
]);
1486-
});
1487-
14881444
it("should return all widget IDs that were rendererd", () => {
14891445
// Arrange
14901446
const {renderer} = renderQuestion({

packages/perseus/src/renderer.tsx

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ import type {
6666
PerseusWidgetsMap,
6767
ShowSolutions,
6868
PerseusScore,
69-
UserInputArray,
7069
UserInputMap,
7170
PerseusItem,
7271
} from "@khanacademy/perseus-core";
@@ -1694,23 +1693,6 @@ class Renderer
16941693
widget?.setInputValue?.(interWidgetPath, newValue, cb);
16951694
};
16961695

1697-
/**
1698-
* Returns an array of the widget `.getUserInput()` results
1699-
*
1700-
* TODO: can we remove this?
1701-
* @deprecated use getUserInputMap
1702-
*/
1703-
getUserInput(): UserInputArray {
1704-
return this.widgetIds.map((id: string) => {
1705-
const widget = this.getWidgetInstance(id);
1706-
if (widget && widget.getUserInput) {
1707-
// TODO(Jeremy): Add the widget ID in here so we can more
1708-
// easily correlate it to the widget state.
1709-
return widget.getUserInput();
1710-
}
1711-
});
1712-
}
1713-
17141696
/**
17151697
* Returns an object of the widget `.getUserInput()` results
17161698
*/

packages/perseus/src/server-item-renderer.tsx

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import type {
3737
KeypadContextRendererInterface,
3838
RendererInterface,
3939
KEScore,
40-
UserInputArray,
4140
UserInputMap,
4241
} from "@khanacademy/perseus-core";
4342
import type {PropsFor} from "@khanacademy/wonder-blocks-core";
@@ -331,17 +330,6 @@ export class ServerItemRenderer
331330
return this.questionRenderer.getPromptJSON();
332331
}
333332

334-
/**
335-
* Returns an array of the widget `.getUserInput()` results
336-
*
337-
* TODO: can we remove this? Seems to be just for backwards
338-
* compatibility with old Perseus Chrome logging
339-
* @deprecated use getUserInput
340-
*/
341-
getUserInputLegacy(): UserInputArray {
342-
return this.questionRenderer.getUserInput();
343-
}
344-
345333
/**
346334
* Returns an object of the widget `.getUserInput()` results
347335
*/

packages/perseus/src/util/scoring.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {Errors, PerseusError} from "@khanacademy/perseus-core";
33
import type {
44
KEScore,
55
PerseusScore,
6-
UserInputArray,
6+
UserInputMap,
77
} from "@khanacademy/perseus-core";
88

99
export function isCorrect(score: PerseusScore): boolean {
@@ -12,8 +12,7 @@ export function isCorrect(score: PerseusScore): boolean {
1212

1313
export function keScoreFromPerseusScore(
1414
score: PerseusScore,
15-
// It's weird, but this is what we're passing it
16-
guess: UserInputArray | [UserInputArray, []],
15+
guess: UserInputMap,
1716
state: any,
1817
): KEScore {
1918
if (score.type === "points") {

packages/perseus/src/widgets/cs-program/cs-program.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ describe("cs-program widget", () => {
4545
} as const;
4646

4747
const {renderer} = renderQuestion(question1, apiOptions);
48-
const userInput =
49-
renderer.getUserInput()[0] as PerseusCSProgramUserInput;
48+
const userInput = renderer.getUserInputMap()[
49+
"cs-program 1"
50+
] as PerseusCSProgramUserInput;
5051

5152
expect(userInput.status).toBe("incomplete");
5253
expect(userInput.message).toBe(null);

packages/perseus/src/widgets/group/group.test.tsx

Lines changed: 54 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -188,33 +188,32 @@ describe("group widget", () => {
188188
await userEvent.type(screen.getAllByRole("textbox")[0], "99");
189189

190190
// Act
191-
const userInput = renderer.getUserInput();
191+
const userInput = renderer.getUserInputMap();
192192

193193
// Assert
194194
expect(userInput).toMatchInlineSnapshot(`
195-
[
196-
[
197-
{
198-
"choicesSelected": [
199-
false,
200-
false,
201-
false,
202-
false,
203-
false,
204-
],
205-
},
206-
],
207-
[
208-
{
209-
"currentValue": "99",
210-
},
211-
{
212-
"currentValue": "",
213-
},
214-
undefined,
215-
],
216-
]
217-
`);
195+
{
196+
"group 1": {
197+
"radio 1": {
198+
"choicesSelected": [
199+
false,
200+
false,
201+
false,
202+
false,
203+
false,
204+
],
205+
},
206+
},
207+
"group 2": {
208+
"numeric-input 1": {
209+
"currentValue": "99",
210+
},
211+
"numeric-input 2": {
212+
"currentValue": "",
213+
},
214+
},
215+
}
216+
`);
218217
});
219218

220219
it("should return contained renderer's getSerializedState", async () => {
@@ -434,42 +433,41 @@ describe("group widget", () => {
434433

435434
const guess = renderer.getUserInputMap();
436435
const score = scorePerseusItem(question1, guess, "en");
437-
const guessAndScore = [renderer.getUserInput(), score];
436+
const guessAndScore = [renderer.getUserInputMap(), score];
438437

439438
// Assert
440439
expect(score).toHaveBeenAnsweredCorrectly();
441440
expect(guessAndScore).toMatchInlineSnapshot(`
442-
[
443-
[
444-
[
445-
{
446-
"choicesSelected": [
447-
false,
448-
false,
449-
false,
450-
false,
451-
true,
452-
],
453-
},
454-
],
455-
[
456-
{
457-
"currentValue": "230",
458-
},
459-
{
460-
"currentValue": "200",
461-
},
462-
undefined,
463-
],
464-
],
465-
{
466-
"earned": 3,
467-
"message": null,
468-
"total": 3,
469-
"type": "points",
470-
},
471-
]
472-
`);
441+
[
442+
{
443+
"group 1": {
444+
"radio 1": {
445+
"choicesSelected": [
446+
false,
447+
false,
448+
false,
449+
false,
450+
true,
451+
],
452+
},
453+
},
454+
"group 2": {
455+
"numeric-input 1": {
456+
"currentValue": "230",
457+
},
458+
"numeric-input 2": {
459+
"currentValue": "200",
460+
},
461+
},
462+
},
463+
{
464+
"earned": 3,
465+
"message": null,
466+
"total": 3,
467+
"type": "points",
468+
},
469+
]
470+
`);
473471
});
474472

475473
it("should return input paths from contained Renderer", () => {

packages/perseus/src/widgets/group/group.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import type {
2828
import type {GroupPromptJSON} from "../../widget-ai-utils/group/group-ai-utils";
2929
import type {
3030
PerseusGroupWidgetOptions,
31-
UserInputArray,
3231
UserInputMap,
3332
} from "@khanacademy/perseus-core";
3433

@@ -69,13 +68,6 @@ class Group extends React.Component<Props> implements Widget {
6968
return this.rendererRef?.getUserInputMap();
7069
}
7170

72-
/**
73-
* @deprecated getUserInputMap should be used for Groups
74-
*/
75-
getUserInput(): UserInputArray | undefined {
76-
return this.rendererRef?.getUserInput();
77-
}
78-
7971
getPromptJSON(): GroupPromptJSON {
8072
return _getPromptJSON(this.rendererRef?.getPromptJSON());
8173
}

packages/perseus/src/widgets/radio/__tests__/radio.test.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -807,8 +807,9 @@ describe("Radio Widget", () => {
807807
screen.getByRole("radio", {name: /Correct Choice$/}),
808808
);
809809

810-
const userInput =
811-
renderer.getUserInput()[0] as PerseusRadioUserInput;
810+
const userInput = renderer.getUserInputMap()[
811+
"radio 1"
812+
] as PerseusRadioUserInput;
812813
const rubric = shuffledQuestion.widgets["radio 1"].options;
813814
const widgetScore = scoreRadio(userInput, rubric);
814815
const rendererScore = scorePerseusItemTesting(
@@ -835,8 +836,9 @@ describe("Radio Widget", () => {
835836
screen.getByRole("radio", {name: /Incorrect Choice 1$/}),
836837
);
837838

838-
const userInput =
839-
renderer.getUserInput()[0] as PerseusRadioUserInput;
839+
const userInput = renderer.getUserInputMap()[
840+
"radio 1"
841+
] as PerseusRadioUserInput;
840842
const rubric = shuffledQuestion.widgets["radio 1"].options;
841843
const widgetScore = scoreRadio(userInput, rubric);
842844
const rendererScore = scorePerseusItemTesting(
@@ -863,8 +865,9 @@ describe("Radio Widget", () => {
863865
screen.getByRole("radio", {name: /None of the above$/}),
864866
);
865867

866-
const userInput =
867-
renderer.getUserInput()[0] as PerseusRadioUserInput;
868+
const userInput = renderer.getUserInputMap()[
869+
"radio 1"
870+
] as PerseusRadioUserInput;
868871
const rubric = shuffledNoneQuestion.widgets["radio 1"].options;
869872
const widgetScore = scoreRadio(userInput, rubric);
870873
const rendererScore = scorePerseusItemTesting(
@@ -891,8 +894,9 @@ describe("Radio Widget", () => {
891894
screen.getByRole("radio", {name: /Incorrect Choice 1$/}),
892895
);
893896

894-
const userInput =
895-
renderer.getUserInput()[0] as PerseusRadioUserInput;
897+
const userInput = renderer.getUserInputMap()[
898+
"radio 1"
899+
] as PerseusRadioUserInput;
896900
const rubric = shuffledNoneQuestion.widgets["radio 1"].options;
897901
const widgetScore = scoreRadio(userInput, rubric);
898902
const rendererScore = scorePerseusItemTesting(

testing/server-item-renderer-with-debug-ui.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,9 @@ export const ServerItemRendererWithDebugUI = ({
7070
const userInput = renderer.getUserInput();
7171
const score = scorePerseusItem(item.question, userInput, "en");
7272

73-
// Continue to include an empty guess for the now defunct answer area.
74-
// TODO(alex): Check whether we rely on the format here for
75-
// analyzing ProblemLogs. If not, remove this layer.
76-
const maxCompatGuess = [renderer.getUserInputLegacy(), []];
7773
return keScoreFromPerseusScore(
7874
score,
79-
maxCompatGuess,
75+
userInput,
8076
renderer.getSerializedState().question,
8177
);
8278
};

0 commit comments

Comments
 (0)