Skip to content

Commit

Permalink
Merge branch 'main' into catjohnson/fix-scorable-polygon
Browse files Browse the repository at this point in the history
  • Loading branch information
catandthemachines committed Dec 16, 2024
2 parents 16e76f7 + b09d19b commit cf99339
Show file tree
Hide file tree
Showing 157 changed files with 5,629 additions and 3,893 deletions.
5 changes: 5 additions & 0 deletions .changeset/slow-rules-unite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/perseus": patch
---

Fixing bug in creating concave shapes in unlimited polygons.
6 changes: 0 additions & 6 deletions .changeset/strange-lies-talk.md

This file was deleted.

36 changes: 34 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable @typescript-eslint/no-require-imports */
/* eslint-disable import/no-commonjs */
const fs = require("fs");
const path = require("path");
Expand Down Expand Up @@ -139,7 +139,7 @@ module.exports = {
{
files: ["config/**", "utils/**", "testing/*"],
rules: {
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-require-imports": "off",
"import/no-commonjs": "off",
"import/no-extraneous-dependencies": "off",
"import/no-relative-packages": "off",
Expand All @@ -166,6 +166,18 @@ module.exports = {
],
},
},
{
/**
* .typetest.ts files are used to do "type testing" :mindblown:
* It is common practice in these files to declare variables and
* expressions that are never used.
*/
files: ["*.typetest.ts"],
rules: {
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-unused-expressions": "off",
},
},
],
rules: {
"max-lines": "off",
Expand Down Expand Up @@ -277,6 +289,26 @@ module.exports = {
message:
"Use of React.FC<Props> is disallowed, use the following alternative: https://khanacademy.atlassian.net/wiki/spaces/ENG/pages/2201682693/TypeScript+for+Flow+Developers#Functional-Components",
},
{
selector:
"JSXElement[openingElement.name.name='UniqueIDProvider']",
message:
"DEPRECATED: Use the `Id` Wonder Blocks Core component instead, or migrate to the `useId` React hook.",
},
{
selector: "JSXElement[openingElement.name.name='IDProvider']",
message:
"DEPRECATED: Use the `Id` Wonder Blocks Core component instead, or migrate to the `useId` React hook.",
},
{
selector: "CallExpression[callee.name='useUniqueIdWithMock']",
message: "DEPRECATED: Use the `useId` React hook instead.",
},
{
selector:
"CallExpression[callee.name='useUniqueIdWithoutMock']",
message: "DEPRECATED: Use the `useId` React hook instead.",
},
],

/**
Expand Down
1 change: 1 addition & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/* eslint-disable @typescript-eslint/no-require-imports */
// eslint-disable-next-line import/no-commonjs
module.exports = require("./config/build/babel.config");
90 changes: 13 additions & 77 deletions config/test/custom-matchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,56 +19,17 @@ declare global {
}
}

type PerseusRenderer = {
guessAndScore: () => [Array<any>, PerseusScore];
};

type Answerable = PerseusRenderer | PerseusScore;

function isRenderer(obj: Answerable): obj is PerseusRenderer {
// @ts-expect-error - TS(2339) - TS is annoying
return obj?.guessAndScore !== undefined;
}

function check(answerable: Answerable) {
let widgetState: string = "";
let score: PerseusScore;

if (isRenderer(answerable)) {
const result = answerable.guessAndScore();
widgetState = JSON.stringify(result[0]);
score = result[1];
} else {
score = answerable;
}

return {widgetState, score};
}

function maybeAddState(message: string, widgetState: string): string {
if (!widgetState) {
return message;
}

return message + `; widget state: ${widgetState}`;
}

expect.extend({
toHaveBeenAnsweredCorrectly(
answerable: Answerable,
score: PerseusScore,
options: {
shouldHavePoints: boolean;
},
) {
const shouldHavePoints = options?.shouldHavePoints ?? true;
const {widgetState, score} = check(answerable);

if (score.type === "invalid") {
const errMessage = maybeAddState(
`Invalid answer: ${score.message || "(no message)"}`,
widgetState,
);

const errMessage = `Invalid answer: ${score.message || "(no message)"}`;
return {
pass: false,
message: () => errMessage,
Expand All @@ -83,10 +44,7 @@ expect.extend({
}

if (score.earned !== score.total) {
const errMessage = maybeAddState(
"Problem was answered incorrectly",
widgetState,
);
const errMessage = "Problem was answered incorrectly";

return {
pass: false,
Expand All @@ -95,20 +53,14 @@ expect.extend({
}

if (shouldHavePoints && score.total < 1) {
const errMessage = maybeAddState(
"Score did not have any points",
widgetState,
);
const errMessage = "Score did not have any points";

return {
pass: false,
message: () => errMessage,
};
} else if (!shouldHavePoints && score.total > 0) {
const errMessage = maybeAddState(
"Score had points when it shouldn't have",
widgetState,
);
const errMessage = "Score had points when it shouldn't have";

return {
pass: false,
Expand All @@ -119,14 +71,9 @@ expect.extend({
return {pass: true, message: () => ""};
},

toHaveInvalidInput(answerable: Answerable, message: string | null) {
const {widgetState, score} = check(answerable);

toHaveInvalidInput(score: PerseusScore, message: string | null) {
if (score.type !== "invalid") {
const errMessage = maybeAddState(
`Answer state is not invalid. Score: ${JSON.stringify(score)}`,
widgetState,
);
const errMessage = `Answer state is not invalid. Score: ${JSON.stringify(score)}`;

return {
pass: false,
Expand All @@ -135,12 +82,9 @@ expect.extend({
}

if (message && (!score.message || !score.message.includes(message))) {
const errMessage = maybeAddState(
`Message shown for invalid input did not include "${message}": ${
score.message || "(no message)"
}. Score: ${JSON.stringify(score)}`,
widgetState,
);
const errMessage = `Message shown for invalid input did not include "${message}": ${
score.message || "(no message)"
}. Score: ${JSON.stringify(score)}`;

return {
pass: false,
Expand All @@ -151,14 +95,9 @@ expect.extend({
return {pass: true, message: () => ""};
},

toHaveBeenAnsweredIncorrectly(answerable: Answerable) {
const {widgetState, score} = check(answerable);

toHaveBeenAnsweredIncorrectly(score: PerseusScore) {
if (score.type === "invalid") {
const errMessage = maybeAddState(
`Invalid answer: ${score.message || "(no message)"}`,
widgetState,
);
const errMessage = `Invalid answer: ${score.message || "(no message)"}`;

return {
pass: false,
Expand All @@ -179,10 +118,7 @@ expect.extend({
if (score.earned !== 0) {
return {
pass: false,
message: () =>
`Problem was answered correctly. Widget state: ${JSON.stringify(
widgetState,
)}`,
message: () => `Problem was answered correctly.`,
};
}

Expand Down
30 changes: 30 additions & 0 deletions dev/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
# @khanacademy/perseus-dev-ui

## 5.0.0

### Major Changes

- [#2007](https://github.com/Khan/perseus/pull/2007) [`ea1bf0c2c`](https://github.com/Khan/perseus/commit/ea1bf0c2cfc7ae552d039549950d1973b56f5ca9) Thanks [@somewhatabstract](https://github.com/somewhatabstract)! - Update to latest webapp dependencies and prepare for deprecation of custom WB ID generators

### Patch Changes

- Updated dependencies [[`ea1bf0c2c`](https://github.com/Khan/perseus/commit/ea1bf0c2cfc7ae552d039549950d1973b56f5ca9)]:
- @khanacademy/math-input@22.0.0
- @khanacademy/perseus-core@3.0.0
- @khanacademy/kas@0.4.4
- @khanacademy/kmath@0.1.18
- @khanacademy/perseus-linter@1.2.6
- @khanacademy/pure-markdown@0.3.15
- @khanacademy/simple-markdown@0.13.8

## 4.0.4

### Patch Changes

- Updated dependencies [[`f9906728c`](https://github.com/Khan/perseus/commit/f9906728c1a8f09c91c11d824718b8a06d6a7609), [`341d316aa`](https://github.com/Khan/perseus/commit/341d316aa8727ebb9e7fde28fc4e2d8779aa3e82)]:
- @khanacademy/perseus-core@2.0.0
- @khanacademy/kas@0.4.3
- @khanacademy/kmath@0.1.17
- @khanacademy/math-input@21.1.7
- @khanacademy/perseus-linter@1.2.5
- @khanacademy/pure-markdown@0.3.14
- @khanacademy/simple-markdown@0.13.7

## 4.0.3

### Patch Changes
Expand Down
2 changes: 2 additions & 0 deletions dev/gallery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ function capitalize(key: string): string {
}

export function Gallery() {
// TODO(WB-1812, somewhatabstract): Migrate to Id or useId
// eslint-disable-next-line no-restricted-syntax
const ids = useUniqueIdWithMock();
const params = useMemo(
() => new URLSearchParams(window.location.search),
Expand Down
36 changes: 18 additions & 18 deletions dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Perseus dev UI",
"author": "Khan Academy",
"license": "MIT",
"version": "4.0.3",
"version": "5.0.0",
"private": true,
"repository": {
"type": "git",
Expand All @@ -14,23 +14,23 @@
"dev": "vite"
},
"dependencies": {
"@khanacademy/kas": "^0.4.2",
"@khanacademy/kmath": "^0.1.16",
"@khanacademy/math-input": "^21.1.6",
"@khanacademy/perseus-core": "1.5.3",
"@khanacademy/perseus-linter": "^1.2.4",
"@khanacademy/pure-markdown": "^0.3.13",
"@khanacademy/simple-markdown": "^0.13.6",
"@khanacademy/wonder-blocks-banner": "3.1.7",
"@khanacademy/wonder-blocks-icon": "4.1.3",
"@khanacademy/wonder-blocks-icon-button": "5.3.4",
"@khanacademy/wonder-blocks-link": "6.1.6",
"@khanacademy/wonder-blocks-search-field": "2.2.23",
"@khanacademy/wonder-blocks-timing": "5.0.1",
"@khanacademy/wonder-blocks-tokens": "2.0.0",
"@khanacademy/wonder-blocks-toolbar": "3.0.35",
"@khanacademy/wonder-blocks-tooltip": "2.4.0",
"@khanacademy/wonder-stuff-core": "1.5.2",
"@khanacademy/kas": "^0.4.4",
"@khanacademy/kmath": "^0.1.18",
"@khanacademy/math-input": "^22.0.0",
"@khanacademy/perseus-core": "3.0.0",
"@khanacademy/perseus-linter": "^1.2.6",
"@khanacademy/pure-markdown": "^0.3.15",
"@khanacademy/simple-markdown": "^0.13.8",
"@khanacademy/wonder-blocks-banner": "4.0.2",
"@khanacademy/wonder-blocks-icon": "5.0.2",
"@khanacademy/wonder-blocks-icon-button": "6.0.2",
"@khanacademy/wonder-blocks-link": "7.0.2",
"@khanacademy/wonder-blocks-search-field": "4.0.0",
"@khanacademy/wonder-blocks-timing": "6.0.0",
"@khanacademy/wonder-blocks-tokens": "3.0.0",
"@khanacademy/wonder-blocks-toolbar": "5.0.2",
"@khanacademy/wonder-blocks-tooltip": "4.0.0",
"@khanacademy/wonder-stuff-core": "1.5.4",
"@phosphor-icons/core": "^2.0.2"
},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/* eslint-disable @typescript-eslint/no-require-imports */
/* eslint-disable import/no-commonjs */
module.exports = require("./config/test/test.config");
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
"@jest/globals": "^29.7.0",
"@khanacademy/eslint-config": "^4.0.0",
"@khanacademy/eslint-plugin": "^3.0.1",
"@khanacademy/mathjax-renderer": "^2.1.0",
"@khanacademy/wonder-blocks-button": "6.3.8",
"@khanacademy/wonder-blocks-layout": "2.1.3",
"@khanacademy/mathjax-renderer": "^2.1.1",
"@khanacademy/wonder-blocks-button": "7.0.2",
"@khanacademy/wonder-blocks-layout": "3.0.2",
"@khanacademy/wonder-blocks-spacing": "^4.0.1",
"@popperjs/core": "^2.10.2",
"@rollup/plugin-alias": "^3.1.9",
Expand Down Expand Up @@ -61,8 +61,8 @@
"@types/react": "~18.2.64",
"@types/react-dom": "~18.2.19",
"@types/underscore": "^1.11.4",
"@typescript-eslint/eslint-plugin": "^7.3.1",
"@typescript-eslint/parser": "^7.3.1",
"@typescript-eslint/eslint-plugin": "^8.18.0",
"@typescript-eslint/parser": "^8.18.0",
"ancesdir": "^3.1.0",
"babel-jest": "^29.7.0",
"babel-loader": "^9.1.3",
Expand All @@ -73,15 +73,15 @@
"cypress-jest-adapter": "^0.1.1",
"cypress-real-events": "^1.12.0",
"cypress-wait-until": "^3.0.1",
"eslint": "^8.57.0",
"eslint": "^8.57.1",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-alias": "^1.1.2",
"eslint-import-resolver-typescript": "^3.5.5",
"eslint-plugin-cypress": "^2.15.1",
"eslint-plugin-disable": "^2.0.3",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "27.9.0",
"eslint-plugin-jest": "28.9.0",
"eslint-plugin-jsdoc": "^48.2.1",
"eslint-plugin-jsx-a11y": "^6.7.1",
"eslint-plugin-monorepo": "^0.3.2",
Expand Down Expand Up @@ -109,7 +109,7 @@
"react-router": "5.3.4",
"react-router-dom": "5.3.4",
"react-transition-group": "^4.4.1",
"react-window": "^1.8.5",
"react-window": "^1.8.10",
"rollup": "^2.70.2",
"rollup-plugin-auto-external": "^2.0.0",
"rollup-plugin-executable-output": "^1.3.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/kas/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable @typescript-eslint/no-require-imports */
/* eslint-disable import/no-commonjs */
const path = require("path");

Expand Down
Loading

0 comments on commit cf99339

Please sign in to comment.