Skip to content

Commit

Permalink
Fix some naming discrepancies and simplify Matcher scoring type (#2038)
Browse files Browse the repository at this point in the history
## Summary:
Noticed some discrepanies in naming relating to calling the validation function and also noticed some scoring types still reference their widgetOptions. The scoring types for the group widgets still references widgetOptions, but here I updated the scoring type for Matcher to be more specific to what is actually used.

Issue: LEMS-2734

## Test plan:
- Confirm all checks pass
- Will do more manual testing after merging to the feature branch

Author: Myranae

Reviewers: handeyeco, jeremywiebe

Required Reviewers:

Approved By: handeyeco

Checks: ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (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)

Pull Request URL: #2038
  • Loading branch information
Myranae authored Dec 19, 2024
1 parent 879d2a5 commit e6f7cc9
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .changeset/nine-planes-relax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/perseus": minor
---

Fix some naming discrepancies related to validation and simplify Matcher ScoringData type
8 changes: 6 additions & 2 deletions packages/perseus/src/validation.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import type {
PerseusGradedGroupWidgetOptions,
PerseusGraphType,
PerseusGroupWidgetOptions,
PerseusMatcherWidgetOptions,
PerseusMatrixWidgetAnswers,
PerseusNumericInputAnswer,
PerseusOrdererWidgetOptions,
Expand Down Expand Up @@ -144,7 +143,12 @@ export type PerseusLabelImageUserInput = {
}>;
};

export type PerseusMatcherScoringData = PerseusMatcherWidgetOptions;
export type PerseusMatcherScoringData = {
// Translatable Text; Static concepts to show in the left column. e.g. ["Fruit", "Color", "Clothes"]
left: ReadonlyArray<string>;
// Translatable Markup; Values that represent the concepts to be correlated with the concepts. e.g. ["Red", "Shirt", "Banana"]
right: ReadonlyArray<string>;
};

export type PerseusMatcherUserInput = {
left: ReadonlyArray<string>;
Expand Down
6 changes: 3 additions & 3 deletions packages/perseus/src/widgets/group/score-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import type {
// it. As such, scoring a group means scoring all widgets it contains.
function scoreGroup(
userInput: PerseusGroupUserInput,
options: PerseusGroupScoringData,
scoringData: PerseusGroupScoringData,
strings: PerseusStrings,
locale: string,
): PerseusScore {
const scores = scoreWidgetsFunctional(
options.widgets,
Object.keys(options.widgets),
scoringData.widgets,
Object.keys(scoringData.widgets),
userInput,
strings,
locale,
Expand Down
6 changes: 0 additions & 6 deletions packages/perseus/src/widgets/matcher/score-matcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ describe("scoreMatcher", () => {
};

const scoringData: PerseusMatcherScoringData = {
labels: ["One", "Two"],
left: ["1", "0+1"],
right: ["2", "0+2"],
orderMatters: false,
padding: false,
};

// Act
Expand All @@ -31,11 +28,8 @@ describe("scoreMatcher", () => {
it("can be answered correctly", () => {
// Arrange
const scoringData: PerseusMatcherScoringData = {
labels: ["One", "Two"],
left: ["1", "0+1"],
right: ["2", "0+2"],
orderMatters: false,
padding: false,
};

const userInput: PerseusMatcherUserInput = {
Expand Down
6 changes: 3 additions & 3 deletions packages/perseus/src/widgets/matrix/score-matrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ function scoreMatrix(
scoringData: PerseusMatrixScoringData,
strings: PerseusStrings,
): PerseusScore {
const validationResult = validateMatrix(userInput, scoringData, strings);
if (validationResult != null) {
return validationResult;
const validationError = validateMatrix(userInput, scoringData, strings);
if (validationError != null) {
return validationError;
}

const solution = scoringData.answers;
Expand Down
6 changes: 3 additions & 3 deletions packages/perseus/src/widgets/orderer/score-orderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ export function scoreOrderer(
userInput: PerseusOrdererUserInput,
scoringData: PerseusOrdererScoringData,
): PerseusScore {
const validateError = validateOrderer(userInput);
if (validateError) {
return validateError;
const validationError = validateOrderer(userInput);
if (validationError) {
return validationError;
}

const correct = _.isEqual(
Expand Down

0 comments on commit e6f7cc9

Please sign in to comment.