@khanacademy/math-input 17.0.4 → 17.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/dist/es/index.js +1 -1
  2. package/dist/index.js +1 -1
  3. package/package.json +5 -2
  4. package/.eslintrc.js +0 -18
  5. package/CHANGELOG.md +0 -660
  6. package/less/main.less +0 -2
  7. package/less/overrides.less +0 -122
  8. package/src/components/__tests__/integration.test.tsx +0 -300
  9. package/src/components/aphrodite-css-transition-group/index.tsx +0 -78
  10. package/src/components/aphrodite-css-transition-group/transition-child.tsx +0 -192
  11. package/src/components/aphrodite-css-transition-group/types.ts +0 -20
  12. package/src/components/aphrodite-css-transition-group/util.ts +0 -97
  13. package/src/components/input/__tests__/context-tracking.test.ts +0 -176
  14. package/src/components/input/__tests__/mathquill-helpers.test.ts +0 -105
  15. package/src/components/input/__tests__/mathquill.test.ts +0 -747
  16. package/src/components/input/__tests__/test-math-wrapper.ts +0 -29
  17. package/src/components/input/cursor-contexts.ts +0 -37
  18. package/src/components/input/cursor-handle.tsx +0 -137
  19. package/src/components/input/cursor-styles.ts +0 -10
  20. package/src/components/input/drag-listener.ts +0 -79
  21. package/src/components/input/math-input.tsx +0 -1036
  22. package/src/components/input/math-wrapper.ts +0 -189
  23. package/src/components/input/mathquill-helpers.ts +0 -262
  24. package/src/components/input/mathquill-instance.ts +0 -106
  25. package/src/components/input/mathquill-types.ts +0 -32
  26. package/src/components/input/scroll-into-view.ts +0 -65
  27. package/src/components/key-handlers/__tests__/handle-jump-out.test.ts +0 -94
  28. package/src/components/key-handlers/handle-arrow.ts +0 -70
  29. package/src/components/key-handlers/handle-backspace.ts +0 -277
  30. package/src/components/key-handlers/handle-exponent.ts +0 -53
  31. package/src/components/key-handlers/handle-jump-out.ts +0 -107
  32. package/src/components/key-handlers/key-translator.ts +0 -222
  33. package/src/components/keypad/__tests__/__snapshots__/keypad.test.tsx.snap +0 -1913
  34. package/src/components/keypad/__tests__/__snapshots__/mobile-keypad.test.tsx.snap +0 -600
  35. package/src/components/keypad/__tests__/keypad-button.test.tsx +0 -84
  36. package/src/components/keypad/__tests__/keypad-v2-mathquill.test.tsx +0 -304
  37. package/src/components/keypad/__tests__/keypad-v2.cypress.ts +0 -16
  38. package/src/components/keypad/__tests__/keypad.test.tsx +0 -321
  39. package/src/components/keypad/__tests__/mobile-keypad.test.tsx +0 -115
  40. package/src/components/keypad/__tests__/test-data-tabs.ts +0 -21
  41. package/src/components/keypad/button-assets.tsx +0 -1880
  42. package/src/components/keypad/index.tsx +0 -2
  43. package/src/components/keypad/keypad-button.stories.tsx +0 -81
  44. package/src/components/keypad/keypad-button.tsx +0 -124
  45. package/src/components/keypad/keypad-mathquill.stories.tsx +0 -109
  46. package/src/components/keypad/keypad-pages/extras-page.tsx +0 -35
  47. package/src/components/keypad/keypad-pages/fractions-page.tsx +0 -125
  48. package/src/components/keypad/keypad-pages/geometry-page.tsx +0 -34
  49. package/src/components/keypad/keypad-pages/keypad-pages.stories.tsx +0 -37
  50. package/src/components/keypad/keypad-pages/numbers-page.tsx +0 -94
  51. package/src/components/keypad/keypad-pages/operators-page.tsx +0 -117
  52. package/src/components/keypad/keypad.tsx +0 -233
  53. package/src/components/keypad/mobile-keypad-internals.tsx +0 -240
  54. package/src/components/keypad/mobile-keypad.tsx +0 -24
  55. package/src/components/keypad/navigation-button.tsx +0 -127
  56. package/src/components/keypad/navigation-pad.stories.tsx +0 -26
  57. package/src/components/keypad/navigation-pad.tsx +0 -67
  58. package/src/components/keypad/shared-keys.tsx +0 -109
  59. package/src/components/keypad/utils.ts +0 -34
  60. package/src/components/keypad-context.tsx +0 -70
  61. package/src/components/prop-types.ts +0 -16
  62. package/src/components/tabbar/__tests__/tabbar.test.tsx +0 -105
  63. package/src/components/tabbar/icons.tsx +0 -122
  64. package/src/components/tabbar/index.ts +0 -1
  65. package/src/components/tabbar/item.tsx +0 -146
  66. package/src/components/tabbar/tabbar.stories.tsx +0 -83
  67. package/src/components/tabbar/tabbar.tsx +0 -65
  68. package/src/data/key-configs.ts +0 -770
  69. package/src/data/keys.ts +0 -123
  70. package/src/enums.ts +0 -27
  71. package/src/fake-react-native-web/index.ts +0 -11
  72. package/src/fake-react-native-web/text.tsx +0 -55
  73. package/src/fake-react-native-web/view.tsx +0 -91
  74. package/src/full-keypad.stories.tsx +0 -142
  75. package/src/full-mobile-input.stories.tsx +0 -115
  76. package/src/index.ts +0 -52
  77. package/src/types.ts +0 -70
  78. package/src/utils.test.ts +0 -33
  79. package/src/utils.ts +0 -61
  80. package/src/version.ts +0 -10
  81. package/tsconfig-build.json +0 -11
  82. package/tsconfig-build.tsbuildinfo +0 -1
@@ -1,321 +0,0 @@
1
- import * as wbi18n from "@khanacademy/wonder-blocks-i18n";
2
- import {render, screen} from "@testing-library/react";
3
- import userEvent from "@testing-library/user-event";
4
- import * as React from "react";
5
- import "@testing-library/jest-dom";
6
-
7
- import keyConfigs from "../../../data/key-configs";
8
- import * as utils from "../../../utils";
9
- import {CursorContext} from "../../input/cursor-contexts";
10
- import Keypad from "../index";
11
-
12
- import tabs from "./test-data-tabs";
13
-
14
- const contextToKeyAria = {
15
- [CursorContext.IN_PARENS]: keyConfigs.JUMP_OUT_PARENTHESES.ariaLabel,
16
- [CursorContext.IN_SUPER_SCRIPT]: keyConfigs.JUMP_OUT_EXPONENT.ariaLabel,
17
- [CursorContext.IN_SUB_SCRIPT]: keyConfigs.JUMP_OUT_BASE.ariaLabel,
18
- [CursorContext.IN_NUMERATOR]: keyConfigs.JUMP_OUT_NUMERATOR.ariaLabel,
19
- [CursorContext.IN_DENOMINATOR]: keyConfigs.JUMP_OUT_DENOMINATOR.ariaLabel,
20
- [CursorContext.BEFORE_FRACTION]: keyConfigs.JUMP_INTO_NUMERATOR.ariaLabel,
21
- };
22
-
23
- describe("keypad", () => {
24
- const originalDecimalSeparator = utils.decimalSeparator;
25
-
26
- afterEach(() => {
27
- // @ts-expect-error TS2540 - Cannot assign to 'decimalSeparator' because it is a read-only property.
28
- // eslint-disable-next-line import/namespace
29
- utils.decimalSeparator = originalDecimalSeparator;
30
- });
31
-
32
- describe("shows navigation buttons", () => {
33
- Object.entries(contextToKeyAria).forEach(([context, ariaLabel]) => {
34
- it(`shows button for ${context}`, () => {
35
- // Arrange
36
- // Act
37
- render(
38
- <Keypad
39
- onClickKey={() => {}}
40
- cursorContext={
41
- context as typeof CursorContext[keyof typeof CursorContext]
42
- }
43
- onAnalyticsEvent={async () => {
44
- /* TODO: verify correct analytics event sent */
45
- }}
46
- />,
47
- );
48
-
49
- // Assert
50
- expect(
51
- screen.getByRole("button", {
52
- name: ariaLabel,
53
- }),
54
- ).toBeInTheDocument();
55
- });
56
- });
57
- });
58
-
59
- it("should snapshot unexpanded", () => {
60
- // Arrange
61
- // Act
62
- const {container} = render(
63
- <Keypad
64
- onClickKey={() => {}}
65
- preAlgebra
66
- trigonometry
67
- extraKeys={["PI"]}
68
- onAnalyticsEvent={async () => {}}
69
- expandedView={false}
70
- />,
71
- );
72
-
73
- // Assert
74
- expect(container).toMatchSnapshot("first render");
75
- });
76
-
77
- it("should snapshot expanded", () => {
78
- // Arrange
79
- // Act
80
- const {container} = render(
81
- <Keypad
82
- onClickKey={() => {}}
83
- preAlgebra
84
- trigonometry
85
- extraKeys={["PI"]}
86
- onAnalyticsEvent={async () => {}}
87
- expandedView={true}
88
- />,
89
- );
90
-
91
- // Assert
92
- expect(container).toMatchSnapshot("first render");
93
- });
94
-
95
- it(`shows optional dismiss button`, () => {
96
- // Arrange
97
- // Act
98
- render(
99
- <Keypad
100
- onClickKey={() => {}}
101
- onAnalyticsEvent={async () => {}}
102
- showDismiss
103
- />,
104
- );
105
-
106
- // Assert
107
- expect(
108
- screen.getByRole("tab", {
109
- name: "Dismiss",
110
- }),
111
- ).toBeInTheDocument();
112
- });
113
-
114
- it(`hides optional dismiss button`, () => {
115
- // Arrange
116
- // Act
117
- render(
118
- <Keypad onClickKey={() => {}} onAnalyticsEvent={async () => {}} />,
119
- );
120
-
121
- // Assert
122
- expect(
123
- screen.queryByRole("tab", {
124
- name: "Dismiss",
125
- }),
126
- ).not.toBeInTheDocument();
127
- });
128
-
129
- it(`shows the dot symbol when convertDotToTimes is false`, () => {
130
- // Arrange
131
- // Act
132
- render(
133
- <Keypad
134
- onClickKey={() => {}}
135
- convertDotToTimes={false}
136
- onAnalyticsEvent={async () => {}}
137
- />,
138
- );
139
-
140
- // Assert
141
- expect(screen.getByTestId("CDOT")).toBeInTheDocument();
142
- });
143
-
144
- it(`shows the times symbol when convertDotToTimes is true`, () => {
145
- // Arrange
146
- // Act
147
- render(
148
- <Keypad
149
- onClickKey={() => {}}
150
- convertDotToTimes={true}
151
- onAnalyticsEvent={async () => {}}
152
- />,
153
- );
154
-
155
- // Assert
156
- expect(screen.getByTestId("TIMES")).toBeInTheDocument();
157
- });
158
-
159
- it(`forces CDOT in locales that require it`, () => {
160
- // Arrange
161
- jest.spyOn(wbi18n, "getLocale").mockReturnValue("az");
162
-
163
- // Act
164
- render(
165
- <Keypad
166
- onClickKey={() => {}}
167
- convertDotToTimes={true}
168
- onAnalyticsEvent={async () => {}}
169
- />,
170
- );
171
-
172
- // Assert
173
- expect(screen.getByTestId("CDOT")).toBeInTheDocument();
174
- expect(screen.queryByTestId("TIMES")).not.toBeInTheDocument();
175
- });
176
-
177
- it(`forces TIMES in locales that require it`, () => {
178
- // Arrange
179
- jest.spyOn(wbi18n, "getLocale").mockReturnValue("fr");
180
-
181
- // Act
182
- render(
183
- <Keypad
184
- onClickKey={() => {}}
185
- convertDotToTimes={false}
186
- onAnalyticsEvent={async () => {}}
187
- />,
188
- );
189
-
190
- // Assert
191
- expect(screen.getByTestId("TIMES")).toBeInTheDocument();
192
- expect(screen.queryByTestId("CDOT")).not.toBeInTheDocument();
193
- });
194
-
195
- it(`hides the tabs if providing the Fraction Keypad`, () => {
196
- // Arrange
197
- // Act
198
- render(
199
- <Keypad
200
- onClickKey={() => {}}
201
- fractionsOnly={true}
202
- onAnalyticsEvent={async () => {}}
203
- />,
204
- );
205
-
206
- // Assert
207
- expect(screen.queryByRole("tab")).not.toBeInTheDocument();
208
- });
209
-
210
- it(`clicking tab triggers callback`, () => {
211
- // Arrange
212
- const onClickKey = jest.fn();
213
-
214
- // Act
215
- render(
216
- <Keypad
217
- onClickKey={onClickKey}
218
- preAlgebra
219
- trigonometry
220
- extraKeys={["PI"]}
221
- onAnalyticsEvent={async () => {}}
222
- />,
223
- );
224
-
225
- for (const tabData of tabs) {
226
- const tab = screen.getByLabelText(tabData.name);
227
- expect(tab).toBeInTheDocument();
228
- userEvent.click(tab);
229
- const key = screen.getByLabelText(tabData.label);
230
- expect(key).toBeInTheDocument();
231
- userEvent.click(key);
232
- }
233
-
234
- // Assert
235
- expect(onClickKey).toHaveBeenCalledTimes(tabs.length);
236
- });
237
-
238
- it(`does not show navigation pad with expanded view turned off`, () => {
239
- // Arrange
240
- // Act
241
- render(
242
- <Keypad
243
- onClickKey={() => {}}
244
- preAlgebra
245
- trigonometry
246
- extraKeys={["PI"]}
247
- onAnalyticsEvent={async () => {}}
248
- expandedView={false}
249
- />,
250
- );
251
-
252
- // Assert
253
- expect(
254
- screen.queryByRole("button", {name: "Up arrow"}),
255
- ).not.toBeInTheDocument();
256
- expect(
257
- screen.queryByRole("button", {name: "Right arrow"}),
258
- ).not.toBeInTheDocument();
259
- expect(
260
- screen.queryByRole("button", {name: "Down arrow"}),
261
- ).not.toBeInTheDocument();
262
- expect(
263
- screen.queryByRole("button", {name: "Left arrow"}),
264
- ).not.toBeInTheDocument();
265
- });
266
-
267
- it(`shows navigation pad in expanded view`, () => {
268
- // Arrange
269
- // Act
270
- render(
271
- <Keypad
272
- onClickKey={() => {}}
273
- preAlgebra
274
- trigonometry
275
- extraKeys={["PI"]}
276
- onAnalyticsEvent={async () => {}}
277
- expandedView={true}
278
- />,
279
- );
280
-
281
- // Assert
282
- expect(
283
- screen.getByRole("button", {name: "Up arrow"}),
284
- ).toBeInTheDocument();
285
- expect(
286
- screen.getByRole("button", {name: "Right arrow"}),
287
- ).toBeInTheDocument();
288
- expect(
289
- screen.getByRole("button", {name: "Down arrow"}),
290
- ).toBeInTheDocument();
291
- expect(
292
- screen.getByRole("button", {name: "Left arrow"}),
293
- ).toBeInTheDocument();
294
- });
295
-
296
- it(`can show the comma decimal separator`, () => {
297
- // @ts-expect-error TS2540 - Cannot assign to 'decimalSeparator' because it is a read-only property.
298
- // eslint-disable-next-line import/namespace
299
- utils.decimalSeparator = utils.DecimalSeparator.COMMA;
300
-
301
- // Arrange
302
- // Act
303
- render(
304
- <Keypad onClickKey={() => {}} onAnalyticsEvent={async () => {}} />,
305
- );
306
-
307
- // Assert
308
- expect(screen.getByTestId("comma-decimal")).toBeInTheDocument();
309
- });
310
-
311
- it(`can show the period decimal separator`, () => {
312
- // Arrange
313
- // Act
314
- render(
315
- <Keypad onClickKey={() => {}} onAnalyticsEvent={async () => {}} />,
316
- );
317
-
318
- // Assert
319
- expect(screen.getByTestId("period-decimal")).toBeInTheDocument();
320
- });
321
- });
@@ -1,115 +0,0 @@
1
- import {render, screen} from "@testing-library/react";
2
- import * as React from "react";
3
- import "@testing-library/jest-dom";
4
-
5
- import MobileKeypadInternals from "../mobile-keypad-internals";
6
-
7
- describe("mobile keypad", () => {
8
- it("should render keypad when active", () => {
9
- // Arrange
10
- // Act
11
- const {container} = render(
12
- <MobileKeypadInternals
13
- onAnalyticsEvent={async () => undefined}
14
- setKeypadActive={(keypadActive: boolean) => undefined}
15
- keypadActive={true}
16
- />,
17
- );
18
-
19
- // Assert
20
- expect(container).toMatchSnapshot();
21
- });
22
-
23
- it("should not render the keypad when not active", () => {
24
- // Arrange
25
- // Act
26
- const {container} = render(
27
- <MobileKeypadInternals
28
- onAnalyticsEvent={async () => undefined}
29
- setKeypadActive={(keypadActive: boolean) => undefined}
30
- keypadActive={false}
31
- />,
32
- );
33
-
34
- // Assert
35
- expect(container).toMatchSnapshot();
36
- });
37
-
38
- it("should render the keypad when going from keypadActive=false to keypadActive=true", () => {
39
- // Arrange
40
- const {rerender} = render(
41
- <MobileKeypadInternals
42
- onAnalyticsEvent={async () => undefined}
43
- setKeypadActive={(keypadActive: boolean) => undefined}
44
- keypadActive={false}
45
- />,
46
- );
47
-
48
- expect(screen.queryAllByRole("button")).toHaveLength(0);
49
-
50
- // Act
51
- rerender(
52
- <MobileKeypadInternals
53
- onAnalyticsEvent={async () => undefined}
54
- setKeypadActive={(keypadActive: boolean) => undefined}
55
- keypadActive={true}
56
- />,
57
- );
58
-
59
- // Assert
60
- expect(screen.queryAllByRole("tab")).not.toHaveLength(0);
61
- });
62
-
63
- it("should fire an 'opened' event when activated", () => {
64
- // Arrange
65
- const onAnalyticsEvent = jest.fn();
66
-
67
- // Act
68
- render(
69
- <MobileKeypadInternals
70
- onAnalyticsEvent={onAnalyticsEvent}
71
- setKeypadActive={(keypadActive: boolean) => undefined}
72
- keypadActive={true}
73
- />,
74
- );
75
-
76
- // Assert
77
- expect(onAnalyticsEvent).toHaveBeenCalledWith({
78
- type: "math-input:keypad-opened",
79
- payload: {
80
- virtualKeypadVersion: "MATH_INPUT_KEYPAD_V2",
81
- },
82
- });
83
- });
84
-
85
- it("should fire an 'closed' event when dismissed", async () => {
86
- const onAnalyticsEvent = jest.fn();
87
-
88
- // Arrange
89
- const {rerender, unmount} = render(
90
- <MobileKeypadInternals
91
- onAnalyticsEvent={onAnalyticsEvent}
92
- setKeypadActive={(keypadActive: boolean) => undefined}
93
- keypadActive={true}
94
- />,
95
- );
96
-
97
- // Act
98
- rerender(
99
- <MobileKeypadInternals
100
- onAnalyticsEvent={onAnalyticsEvent}
101
- setKeypadActive={(keypadActive: boolean) => undefined}
102
- keypadActive={false}
103
- />,
104
- );
105
- unmount();
106
-
107
- // Assert
108
- expect(onAnalyticsEvent).toHaveBeenCalledWith({
109
- type: "math-input:keypad-closed",
110
- payload: {
111
- virtualKeypadVersion: "MATH_INPUT_KEYPAD_V2",
112
- },
113
- });
114
- });
115
- });
@@ -1,21 +0,0 @@
1
- import KeyConfigs from "../../../data/key-configs";
2
-
3
- export default [
4
- {
5
- name: "Operators",
6
- specialButton: "EXP_2",
7
- label: KeyConfigs["EXP_2"].ariaLabel,
8
- },
9
- {name: "Extras", specialButton: "PI", label: KeyConfigs["PI"].ariaLabel},
10
-
11
- {
12
- name: "Geometry",
13
- specialButton: "COS",
14
- label: KeyConfigs["COS"].ariaLabel,
15
- },
16
- {
17
- name: "Numbers",
18
- specialButton: "NUM_7",
19
- label: KeyConfigs["NUM_7"].ariaLabel,
20
- },
21
- ];