-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Client Validation] Fixes after merging main (#2122)
## Summary: I recently merged `main` and the introduction of `MockWidget` caused some tests to break. I've fixed them in this PR and adjusted the MockWidget to be simpler (ie. not use KhanAnswerTypes) as I don't _think_ that's needed. I also fixed up some related types so that the MockWidget does not exist in our production Widget types, only in tests. The new `MockWidget` illustrates this "test-only" expansion of the widget types. Issue: LEMS-2561 ## Test plan: `yarn test` `yarn typecheck` Author: jeremywiebe Reviewers: jeremywiebe, handeyeco, benchristel, Myranae Required Reviewers: Approved By: handeyeco Checks: ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x) Pull Request URL: #2122
- Loading branch information
1 parent
5f79a67
commit 1a75ca6
Showing
14 changed files
with
120 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@khanacademy/perseus": patch | ||
"@khanacademy/perseus-core": patch | ||
"@khanacademy/perseus-editor": patch | ||
--- | ||
|
||
Type and test fixes for new MockWidget (isolating to be seen only in tests) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/perseus/src/widget-ai-utils/mock-widget/prompt-utils.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/perseus/src/widget-ai-utils/mock-widget/prompt-utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
packages/perseus/src/widgets/mock-widgets/mock-widget-types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import type {WidgetOptions} from "@khanacademy/perseus-core"; | ||
|
||
export type MockWidget = WidgetOptions<"mock-widget", MockWidgetOptions>; | ||
|
||
export type MockWidgetOptions = { | ||
static?: boolean; | ||
value: string; | ||
}; | ||
|
||
export type PerseusMockWidgetRubric = { | ||
value: string; | ||
}; | ||
|
||
export type PerseusMockWidgetUserInput = { | ||
currentValue: string; | ||
}; | ||
|
||
// Extend the widget registries for testing | ||
// See @khanacademy/perseus-core's PerseusWidgetTypes for a full explanation. | ||
// Basically, we're extending the interface from that package so that our | ||
// testing code knows of the MockWidget. In production code, there's no | ||
// knowledge of the mock widget. | ||
declare module "@khanacademy/perseus-core" { | ||
export interface PerseusWidgetTypes { | ||
"mock-widget": MockWidget; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
packages/perseus/src/widgets/mock-widgets/validate-mock-widget.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import validateMockWidget from "./validate-mock-widget"; | ||
|
||
import type {PerseusMockWidgetUserInput} from "./mock-widget-types"; | ||
|
||
describe("mock-widget", () => { | ||
it("should be invalid if no value provided", () => { | ||
const input: PerseusMockWidgetUserInput = {currentValue: ""}; | ||
|
||
const result = validateMockWidget(input); | ||
|
||
expect(result).toHaveInvalidInput(); | ||
}); | ||
|
||
it("should be valid if a value provided", () => { | ||
const input: PerseusMockWidgetUserInput = {currentValue: "a"}; | ||
|
||
const result = validateMockWidget(input); | ||
|
||
expect(result).toBeNull(); | ||
}); | ||
}); |
17 changes: 17 additions & 0 deletions
17
packages/perseus/src/widgets/mock-widgets/validate-mock-widget.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import type {PerseusMockWidgetUserInput} from "./mock-widget-types"; | ||
import type {ValidationResult} from "../../types"; | ||
|
||
function validateMockWidget( | ||
userInput: PerseusMockWidgetUserInput, | ||
): ValidationResult { | ||
if (userInput.currentValue == null || userInput.currentValue === "") { | ||
return { | ||
type: "invalid", | ||
message: "", | ||
}; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
export default validateMockWidget; |