Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Fitzgerald committed Dec 9, 2024
2 parents 8d605d2 + e49f6f7 commit 9531c07
Show file tree
Hide file tree
Showing 25 changed files with 351 additions and 482 deletions.
5 changes: 5 additions & 0 deletions .changeset/poor-numbers-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/perseus": patch
---

[Numeric Input] - BUGFIX - Adjust color contrast of tooltip text
5 changes: 5 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Khan/perseus is tagged for all PRs
@Khan/perseus

# AI Utils are owned by Tutor Platform
widget-ai-utils/* @Khan/tut
55 changes: 0 additions & 55 deletions .github/REVIEWERS

This file was deleted.

13 changes: 0 additions & 13 deletions .github/workflows/gerald-pr.yml

This file was deleted.

2 changes: 1 addition & 1 deletion dev/flipbook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {Renderer} from "../packages/perseus/src";
import {SvgImage} from "../packages/perseus/src/components";
import {scorePerseusItem} from "../packages/perseus/src/renderer-util";
import {mockStrings} from "../packages/perseus/src/strings";
import {isCorrect} from "../packages/perseus/src/util";
import {isCorrect} from "../packages/perseus/src/util/scoring";
import {trueForAllMafsSupportedGraphTypes} from "../packages/perseus/src/widgets/interactive-graphs/mafs-supported-graph-types";

import {EditableControlledInput} from "./editable-controlled-input";
Expand Down
7 changes: 7 additions & 0 deletions packages/perseus-editor/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @khanacademy/perseus-editor

## 15.1.3

### Patch Changes

- Updated dependencies [[`435280ac4`](https://github.com/Khan/perseus/commit/435280ac4cf33ee98ddb1166631f87f81cafa0fc), [`d93e3ecde`](https://github.com/Khan/perseus/commit/d93e3ecdeb6bd714a35dcd9f886299fa80ba71ec)]:
- @khanacademy/perseus@46.0.0

## 15.1.2

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/perseus-editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Perseus editors",
"author": "Khan Academy",
"license": "MIT",
"version": "15.1.2",
"version": "15.1.3",
"publishConfig": {
"access": "public"
},
Expand Down Expand Up @@ -38,7 +38,7 @@
"@khanacademy/keypad-context": "^1.0.4",
"@khanacademy/kmath": "^0.1.16",
"@khanacademy/math-input": "^21.1.6",
"@khanacademy/perseus": "^45.1.0",
"@khanacademy/perseus": "^46.0.0",
"@khanacademy/perseus-core": "1.5.3",
"@khanacademy/pure-markdown": "^0.3.13",
"mafs": "^0.19.0"
Expand Down
8 changes: 8 additions & 0 deletions packages/perseus/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @khanacademy/perseus

## 46.0.0

### Major Changes

- [#1962](https://github.com/Khan/perseus/pull/1962) [`435280ac4`](https://github.com/Khan/perseus/commit/435280ac4cf33ee98ddb1166631f87f81cafa0fc) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Move scoring utility functions out of `Util` object into their own file and only export externally used function (`keScoreFromPerseusScore`)

* [#1961](https://github.com/Khan/perseus/pull/1961) [`d93e3ecde`](https://github.com/Khan/perseus/commit/d93e3ecdeb6bd714a35dcd9f886299fa80ba71ec) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Remove deprecated/unused `examples()` function from `Renderer`

## 45.1.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/perseus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Core Perseus API (includes renderers and widgets)",
"author": "Khan Academy",
"license": "MIT",
"version": "45.1.0",
"version": "46.0.0",
"publishConfig": {
"access": "public"
},
Expand Down
68 changes: 0 additions & 68 deletions packages/perseus/src/__tests__/renderer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1793,72 +1793,4 @@ describe("renderer", () => {
expect(Object.keys(json.widgets)).toEqual(widgetKeys);
});
});

describe("examples", () => {
it("should return examples if all widgets return the same examples (or null)", () => {
// Arrange
const {renderer} = renderQuestion({
content:
"Input widget: [[\u2603 input-number 1]]\n\n" +
"Dropdown widget: [[\u2603 dropdown 1]]\n\n" +
"Image widget (won't have user input): [[\u2603 image 1]]\n\n" +
"Another input widget: [[\u2603 input-number 2]]",
widgets: {
"image 1": imageWidget,
"input-number 1": inputNumberWidget,
"input-number 2": inputNumberWidget,
"dropdown 1": dropdownWidget,
},
images: {},
});

// Act
const examples = renderer.examples();

// Assert
expect(examples).toMatchInlineSnapshot(`
[
"**Your answer should be** ",
"an integer, like $6$",
"a *proper* fraction, like $1/2$ or $6/10$",
"an *improper* fraction, like $10/7$ or $14/8$",
"a mixed number, like $1\\ 3/4$",
]
`);
});

it("should return nothing if widgets return the different examples", () => {
// NOTE(jeremy): I'm unsure why we don't return examples if the
// examples aren't the same, but this is current functionality so
// I'm adding this test to verify the current behaviour.

// Arrange
const {renderer} = renderQuestion({
content:
"Input widget: [[\u2603 input-number 1]]\n\n" +
"Dropdown widget: [[\u2603 dropdown 1]]\n\n" +
"Image widget (won't have user input): [[\u2603 image 1]]\n\n" +
"Another input widget: [[\u2603 input-number 2]]",
widgets: {
"image 1": imageWidget,
"input-number 1": inputNumberWidget,
"input-number 2": {
...inputNumberWidget,
options: {
...inputNumberWidget.options,
answerType: "percent",
},
},
"dropdown 1": dropdownWidget,
},
images: {},
});

// Act
const examples = renderer.examples();

// Assert
expect(examples).toBeNull();
});
});
});
134 changes: 1 addition & 133 deletions packages/perseus/src/__tests__/util.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,4 @@
import Util, {isCorrect} from "../util";

describe("isCorrect", () => {
it("is true given a score with all points earned", () => {
const score = {type: "points", earned: 3, total: 3} as const;
expect(isCorrect(score)).toBe(true);
});

it("is false given a score with some points unearned", () => {
const score = {type: "points", earned: 2, total: 3} as const;
expect(isCorrect(score)).toBe(false);
});

it("is false given an unanswered / invalid score", () => {
const score = {type: "invalid"} as const;
expect(isCorrect(score)).toBe(false);
});
});
import Util from "../util";

describe("#constrainedTickStepsFromTickSteps", () => {
it("should not changes the tick steps if there are fewer than (or exactly) 10 steps", () => {
Expand Down Expand Up @@ -79,118 +62,3 @@ describe("deepClone", () => {
expect(result[0]).not.toBe(input[0]);
});
});

describe("flattenScores", () => {
it("defaults to an empty score", () => {
const result = Util.flattenScores({});

expect(result).toHaveBeenAnsweredCorrectly({shouldHavePoints: false});
expect(result).toEqual({
type: "points",
total: 0,
earned: 0,
message: null,
});
});

it("defaults to single score if there is only one", () => {
const result = Util.flattenScores({
"radio 1": {
type: "points",
total: 1,
earned: 1,
message: null,
},
});

expect(result).toHaveBeenAnsweredCorrectly();
expect(result).toEqual({
type: "points",
total: 1,
earned: 1,
message: null,
});
});

it("returns an invalid score if any are invalid", () => {
const result = Util.flattenScores({
"radio 1": {
type: "points",
total: 1,
earned: 1,
message: null,
},
"radio 2": {
type: "invalid",
message: null,
},
});

expect(result).toHaveInvalidInput();
expect(result).toEqual({
type: "invalid",
message: null,
});
});

it("tallies scores if multiple widgets have points", () => {
const result = Util.flattenScores({
"radio 1": {
type: "points",
total: 1,
earned: 1,
message: null,
},
"radio 2": {
type: "points",
total: 1,
earned: 1,
message: null,
},
"radio 3": {
type: "points",
total: 1,
earned: 1,
message: null,
},
});

expect(result).toHaveBeenAnsweredCorrectly();
expect(result).toEqual({
type: "points",
total: 3,
earned: 3,
message: null,
});
});

it("doesn't count incorrect widgets", () => {
const result = Util.flattenScores({
"radio 1": {
type: "points",
total: 1,
earned: 1,
message: null,
},
"radio 2": {
type: "points",
total: 1,
earned: 1,
message: null,
},
"radio 3": {
type: "points",
total: 1,
earned: 0,
message: null,
},
});

expect(result).toEqual({
type: "points",
total: 3,
earned: 2,
message: null,
});
});
});
9 changes: 7 additions & 2 deletions packages/perseus/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ export {default as TableWidget} from "./widgets/table";
export {default as PlotterWidget} from "./widgets/plotter";
export {default as GrapherWidget} from "./widgets/grapher";

// Some utils in grapher/utils don't need to be used outside of `perseus`,
// so only export the stuff that does need to be exposed
// Some utils in grapher/utils and scoring don't need to be used outside of
// `perseus`, so only export the stuff that does need to be exposed
import {keScoreFromPerseusScore} from "./util/scoring";
import {
allTypes,
DEFAULT_GRAPHER_PROPS,
Expand All @@ -57,6 +58,10 @@ export const GrapherUtil = {
typeToButton,
};

export const ScoringUtil = {
keScoreFromPerseusScore,
};

/**
* Misc
*/
Expand Down
Loading

0 comments on commit 9531c07

Please sign in to comment.