@pie-lib/math-input 8.1.1-next.1 → 8.1.1-next.2

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 (185) hide show
  1. package/dist/_virtual/_rolldown/runtime.js +11 -0
  2. package/dist/horizontal-keypad.d.ts +31 -0
  3. package/dist/horizontal-keypad.js +57 -0
  4. package/dist/index.d.ts +18 -0
  5. package/dist/index.js +19 -0
  6. package/dist/keypad/accessible-keypad.d.ts +37 -0
  7. package/dist/keypad/accessible-keypad.js +614 -0
  8. package/dist/keypad/index.d.ts +2 -0
  9. package/dist/keypad/keys-layout.d.ts +15 -0
  10. package/dist/keypad/keys-layout.js +5 -0
  11. package/dist/keypad/model.d.ts +28 -0
  12. package/dist/keypad/model.js +4 -0
  13. package/dist/keys/basic-operators.d.ts +13 -0
  14. package/dist/keys/basic-operators.js +30 -0
  15. package/dist/keys/chars.d.ts +13 -0
  16. package/dist/keys/comparison.d.ts +12 -0
  17. package/dist/keys/comparison.js +32 -0
  18. package/dist/keys/constants.d.ts +12 -0
  19. package/dist/keys/constants.js +35 -0
  20. package/dist/keys/digits.d.ts +23 -0
  21. package/dist/keys/digits.js +34 -0
  22. package/dist/keys/edit.d.ts +14 -0
  23. package/dist/keys/edit.js +9 -0
  24. package/dist/keys/exponent.d.ts +12 -0
  25. package/dist/keys/exponent.js +28 -0
  26. package/dist/keys/fractions.d.ts +11 -0
  27. package/dist/keys/fractions.js +27 -0
  28. package/dist/keys/geometry.d.ts +31 -0
  29. package/dist/keys/geometry.js +127 -0
  30. package/dist/keys/grades.d.ts +17 -0
  31. package/dist/keys/grades.js +414 -0
  32. package/dist/keys/index.d.ts +14 -0
  33. package/dist/keys/index.js +50 -0
  34. package/dist/keys/log.d.ts +11 -0
  35. package/dist/keys/log.js +25 -0
  36. package/dist/keys/logic.d.ts +10 -0
  37. package/dist/keys/logic.js +13 -0
  38. package/dist/keys/matrices.d.ts +10 -0
  39. package/dist/keys/matrices.js +17 -0
  40. package/dist/keys/misc.d.ts +18 -0
  41. package/dist/keys/misc.js +60 -0
  42. package/dist/keys/navigation.d.ts +10 -0
  43. package/dist/keys/navigation.js +13 -0
  44. package/dist/keys/operators.d.ts +9 -0
  45. package/dist/keys/operators.js +11 -0
  46. package/dist/keys/statistics.d.ts +13 -0
  47. package/dist/keys/statistics.js +38 -0
  48. package/dist/keys/sub-sup.d.ts +10 -0
  49. package/dist/keys/sub-sup.js +17 -0
  50. package/dist/keys/trigonometry.d.ts +14 -0
  51. package/dist/keys/trigonometry.js +43 -0
  52. package/dist/keys/utils.d.ts +13 -0
  53. package/dist/keys/utils.js +24 -0
  54. package/dist/keys/vars.d.ts +11 -0
  55. package/dist/keys/vars.js +22 -0
  56. package/dist/math-input.d.ts +30 -0
  57. package/dist/mq/common-mq-styles.d.ts +225 -0
  58. package/dist/mq/common-mq-styles.js +54 -0
  59. package/dist/mq/custom-elements.d.ts +10 -0
  60. package/dist/mq/custom-elements.js +10 -0
  61. package/dist/mq/index.d.ts +12 -0
  62. package/dist/mq/index.js +12 -0
  63. package/dist/mq/input.d.ts +35 -0
  64. package/dist/mq/input.js +83 -0
  65. package/dist/mq/static.d.ts +43 -0
  66. package/dist/mq/static.js +142 -0
  67. package/dist/updateSpans.d.ts +10 -0
  68. package/dist/updateSpans.js +9 -0
  69. package/package.json +32 -17
  70. package/CHANGELOG.json +0 -17
  71. package/CHANGELOG.md +0 -1172
  72. package/LICENSE.md +0 -5
  73. package/lib/horizontal-keypad.js +0 -96
  74. package/lib/horizontal-keypad.js.map +0 -1
  75. package/lib/index.js +0 -69
  76. package/lib/index.js.map +0 -1
  77. package/lib/keypad/index.js +0 -413
  78. package/lib/keypad/index.js.map +0 -1
  79. package/lib/keypad/keys-layout.js +0 -22
  80. package/lib/keypad/keys-layout.js.map +0 -1
  81. package/lib/keys/basic-operators.js +0 -33
  82. package/lib/keys/basic-operators.js.map +0 -1
  83. package/lib/keys/chars.js +0 -12
  84. package/lib/keys/chars.js.map +0 -1
  85. package/lib/keys/comparison.js +0 -39
  86. package/lib/keys/comparison.js.map +0 -1
  87. package/lib/keys/constants.js +0 -37
  88. package/lib/keys/constants.js.map +0 -1
  89. package/lib/keys/digits.js +0 -46
  90. package/lib/keys/digits.js.map +0 -1
  91. package/lib/keys/edit.js +0 -14
  92. package/lib/keys/edit.js.map +0 -1
  93. package/lib/keys/exponent.js +0 -30
  94. package/lib/keys/exponent.js.map +0 -1
  95. package/lib/keys/fractions.js +0 -29
  96. package/lib/keys/fractions.js.map +0 -1
  97. package/lib/keys/geometry.js +0 -140
  98. package/lib/keys/geometry.js.map +0 -1
  99. package/lib/keys/grades.js +0 -259
  100. package/lib/keys/grades.js.map +0 -1
  101. package/lib/keys/index.js +0 -35
  102. package/lib/keys/index.js.map +0 -1
  103. package/lib/keys/log.js +0 -27
  104. package/lib/keys/log.js.map +0 -1
  105. package/lib/keys/logic.js +0 -19
  106. package/lib/keys/logic.js.map +0 -1
  107. package/lib/keys/matrices.js +0 -19
  108. package/lib/keys/matrices.js.map +0 -1
  109. package/lib/keys/misc.js +0 -62
  110. package/lib/keys/misc.js.map +0 -1
  111. package/lib/keys/navigation.js +0 -20
  112. package/lib/keys/navigation.js.map +0 -1
  113. package/lib/keys/operators.js +0 -15
  114. package/lib/keys/operators.js.map +0 -1
  115. package/lib/keys/statistics.js +0 -40
  116. package/lib/keys/statistics.js.map +0 -1
  117. package/lib/keys/sub-sup.js +0 -19
  118. package/lib/keys/sub-sup.js.map +0 -1
  119. package/lib/keys/trigonometry.js +0 -45
  120. package/lib/keys/trigonometry.js.map +0 -1
  121. package/lib/keys/utils.js +0 -87
  122. package/lib/keys/utils.js.map +0 -1
  123. package/lib/keys/vars.js +0 -24
  124. package/lib/keys/vars.js.map +0 -1
  125. package/lib/math-input.js +0 -141
  126. package/lib/math-input.js.map +0 -1
  127. package/lib/mq/common-mq-styles.js +0 -102
  128. package/lib/mq/common-mq-styles.js.map +0 -1
  129. package/lib/mq/custom-elements.js +0 -20
  130. package/lib/mq/custom-elements.js.map +0 -1
  131. package/lib/mq/index.js +0 -28
  132. package/lib/mq/index.js.map +0 -1
  133. package/lib/mq/input.js +0 -186
  134. package/lib/mq/input.js.map +0 -1
  135. package/lib/mq/mathquill-instance.js +0 -52
  136. package/lib/mq/mathquill-instance.js.map +0 -1
  137. package/lib/mq/static.js +0 -301
  138. package/lib/mq/static.js.map +0 -1
  139. package/lib/updateSpans.js +0 -19
  140. package/lib/updateSpans.js.map +0 -1
  141. package/src/__tests__/horizontal-keypad.test.jsx +0 -463
  142. package/src/__tests__/index.test.js +0 -247
  143. package/src/__tests__/math-input-test.jsx +0 -45
  144. package/src/__tests__/updateSpans.test.js +0 -297
  145. package/src/horizontal-keypad.jsx +0 -69
  146. package/src/index.jsx +0 -28
  147. package/src/keypad/__tests__/index.test.jsx +0 -25
  148. package/src/keypad/__tests__/keys-layout.test.js +0 -14
  149. package/src/keypad/index.jsx +0 -439
  150. package/src/keypad/keys-layout.js +0 -16
  151. package/src/keys/__tests__/utils.test.js +0 -57
  152. package/src/keys/basic-operators.js +0 -32
  153. package/src/keys/chars.js +0 -5
  154. package/src/keys/comparison.js +0 -28
  155. package/src/keys/constants.js +0 -35
  156. package/src/keys/digits.js +0 -40
  157. package/src/keys/edit.js +0 -3
  158. package/src/keys/exponent.js +0 -28
  159. package/src/keys/fractions.js +0 -26
  160. package/src/keys/geometry.js +0 -144
  161. package/src/keys/grades.js +0 -367
  162. package/src/keys/index.js +0 -20
  163. package/src/keys/log.js +0 -22
  164. package/src/keys/logic.js +0 -15
  165. package/src/keys/matrices.js +0 -15
  166. package/src/keys/misc.js +0 -65
  167. package/src/keys/navigation.js +0 -8
  168. package/src/keys/operators.js +0 -10
  169. package/src/keys/statistics.js +0 -38
  170. package/src/keys/sub-sup.js +0 -15
  171. package/src/keys/trigonometry.js +0 -15
  172. package/src/keys/utils.js +0 -66
  173. package/src/keys/vars.js +0 -19
  174. package/src/math-input.jsx +0 -119
  175. package/src/mq/__tests__/custom-elements.test.js +0 -342
  176. package/src/mq/__tests__/input.test.jsx +0 -40
  177. package/src/mq/__tests__/mathquill-instance.test.js +0 -67
  178. package/src/mq/__tests__/static.test.jsx +0 -33
  179. package/src/mq/common-mq-styles.js +0 -109
  180. package/src/mq/custom-elements.js +0 -11
  181. package/src/mq/index.js +0 -5
  182. package/src/mq/input.jsx +0 -166
  183. package/src/mq/mathquill-instance.js +0 -45
  184. package/src/mq/static.jsx +0 -290
  185. package/src/updateSpans.js +0 -15
@@ -1,463 +0,0 @@
1
- import React from 'react';
2
- import { render, screen } from '@testing-library/react';
3
- import HorizontalKeypad from '../horizontal-keypad';
4
-
5
- jest.mock('../keypad', () => {
6
- return function Keypad({
7
- className,
8
- controlledKeypadMode,
9
- onFocus,
10
- noDecimal,
11
- layoutForKeyPad,
12
- additionalKeys,
13
- onPress,
14
- mode,
15
- setKeypadInteraction,
16
- }) {
17
- const attrs = {
18
- 'data-testid': 'keypad',
19
- 'data-controlled-mode': controlledKeypadMode,
20
- 'data-has-focus': !!onFocus,
21
- 'data-no-decimal': noDecimal,
22
- 'data-has-layout': !!layoutForKeyPad,
23
- 'data-additional-keys-length': additionalKeys?.length || 0,
24
- 'data-mode': mode,
25
- 'data-has-interaction': !!setKeypadInteraction,
26
- };
27
-
28
- if (className !== undefined) {
29
- attrs['data-class'] = className;
30
- }
31
-
32
- return (
33
- <div {...attrs} onClick={() => onPress && onPress({ command: 'test' })}>
34
- Keypad Mock
35
- </div>
36
- );
37
- };
38
- });
39
-
40
- jest.mock('../keys/grades', () => ({
41
- keysForGrade: jest.fn((mode) => {
42
- return [[{ name: 'key1', latex: 'x' }], [{ name: 'key2', latex: 'y' }], [{ name: 'key3', latex: 'z' }], [], []];
43
- }),
44
- normalizeAdditionalKeys: jest.fn((keys) => keys || []),
45
- }));
46
-
47
- jest.mock('../keys/utils', () => ({
48
- extendKeySet: jest.fn((base, additional) => {
49
- return [...base, ...(additional || [])];
50
- }),
51
- }));
52
-
53
- describe('HorizontalKeypad', () => {
54
- const { keysForGrade, normalizeAdditionalKeys } = require('../keys/grades');
55
- const { extendKeySet } = require('../keys/utils');
56
-
57
- const defaultProps = {
58
- onClick: jest.fn(),
59
- };
60
-
61
- beforeEach(() => {
62
- jest.clearAllMocks();
63
- });
64
-
65
- describe('rendering', () => {
66
- it('should render the Keypad component', () => {
67
- render(<HorizontalKeypad {...defaultProps} />);
68
- expect(screen.getByTestId('keypad')).toBeInTheDocument();
69
- expect(screen.getByText('Keypad Mock')).toBeInTheDocument();
70
- });
71
-
72
- it('should render with default mode (scientific)', () => {
73
- render(<HorizontalKeypad {...defaultProps} />);
74
- const keypad = screen.getByTestId('keypad');
75
- expect(keypad).toHaveAttribute('data-mode', 'scientific');
76
- });
77
-
78
- it('should render with custom mode as string', () => {
79
- render(<HorizontalKeypad {...defaultProps} mode="geometry" />);
80
- const keypad = screen.getByTestId('keypad');
81
- expect(keypad).toHaveAttribute('data-mode', 'geometry');
82
- });
83
-
84
- it('should render with numeric mode', () => {
85
- render(<HorizontalKeypad {...defaultProps} mode={6} />);
86
- const keypad = screen.getByTestId('keypad');
87
- expect(keypad).toHaveAttribute('data-mode', '6');
88
- });
89
-
90
- it('should render with custom className', () => {
91
- render(<HorizontalKeypad {...defaultProps} className="custom-keypad" />);
92
- const keypad = screen.getByTestId('keypad');
93
- expect(keypad).toHaveAttribute('data-class', 'custom-keypad');
94
- });
95
- });
96
-
97
- describe('props forwarding to Keypad', () => {
98
- it('should forward controlledKeypadMode prop', () => {
99
- render(<HorizontalKeypad {...defaultProps} controlledKeypadMode={true} />);
100
- const keypad = screen.getByTestId('keypad');
101
- expect(keypad).toHaveAttribute('data-controlled-mode', 'true');
102
- });
103
-
104
- it('should forward onFocus prop', () => {
105
- const onFocus = jest.fn();
106
- render(<HorizontalKeypad {...defaultProps} onFocus={onFocus} />);
107
- const keypad = screen.getByTestId('keypad');
108
- expect(keypad).toHaveAttribute('data-has-focus', 'true');
109
- });
110
-
111
- it('should forward noDecimal prop (default false)', () => {
112
- render(<HorizontalKeypad {...defaultProps} />);
113
- const keypad = screen.getByTestId('keypad');
114
- expect(keypad).toHaveAttribute('data-no-decimal', 'false');
115
- });
116
-
117
- it('should forward noDecimal prop when true', () => {
118
- render(<HorizontalKeypad {...defaultProps} noDecimal={true} />);
119
- const keypad = screen.getByTestId('keypad');
120
- expect(keypad).toHaveAttribute('data-no-decimal', 'true');
121
- });
122
-
123
- it('should forward layoutForKeyPad prop', () => {
124
- const layout = { type: 'custom' };
125
- render(<HorizontalKeypad {...defaultProps} layoutForKeyPad={layout} />);
126
- const keypad = screen.getByTestId('keypad');
127
- expect(keypad).toHaveAttribute('data-has-layout', 'true');
128
- });
129
-
130
- it('should forward setKeypadInteraction prop', () => {
131
- const setKeypadInteraction = jest.fn();
132
- render(<HorizontalKeypad {...defaultProps} setKeypadInteraction={setKeypadInteraction} />);
133
- const keypad = screen.getByTestId('keypad');
134
- expect(keypad).toHaveAttribute('data-has-interaction', 'true');
135
- });
136
-
137
- it('should forward all props together', () => {
138
- const allProps = {
139
- onClick: jest.fn(),
140
- onFocus: jest.fn(),
141
- className: 'test-class',
142
- controlledKeypadMode: true,
143
- mode: 'advanced',
144
- noDecimal: true,
145
- layoutForKeyPad: { type: 'test' },
146
- setKeypadInteraction: jest.fn(),
147
- };
148
-
149
- render(<HorizontalKeypad {...allProps} />);
150
- const keypad = screen.getByTestId('keypad');
151
-
152
- expect(keypad).toHaveAttribute('data-class', 'test-class');
153
- expect(keypad).toHaveAttribute('data-controlled-mode', 'true');
154
- expect(keypad).toHaveAttribute('data-has-focus', 'true');
155
- expect(keypad).toHaveAttribute('data-no-decimal', 'true');
156
- expect(keypad).toHaveAttribute('data-has-layout', 'true');
157
- expect(keypad).toHaveAttribute('data-mode', 'advanced');
158
- expect(keypad).toHaveAttribute('data-has-interaction', 'true');
159
- });
160
- });
161
-
162
- describe('key processing', () => {
163
- it('should call keysForGrade with mode', () => {
164
- render(<HorizontalKeypad {...defaultProps} mode="scientific" />);
165
- expect(keysForGrade).toHaveBeenCalledWith('scientific');
166
- });
167
-
168
- it('should call keysForGrade with numeric mode', () => {
169
- render(<HorizontalKeypad {...defaultProps} mode={8} />);
170
- expect(keysForGrade).toHaveBeenCalledWith(8);
171
- });
172
-
173
- it('should normalize additional keys', () => {
174
- const additionalKeys = [{ name: 'custom', latex: 'c' }];
175
- render(<HorizontalKeypad {...defaultProps} additionalKeys={additionalKeys} />);
176
- expect(normalizeAdditionalKeys).toHaveBeenCalledWith(additionalKeys);
177
- });
178
-
179
- it('should normalize empty additional keys (default)', () => {
180
- render(<HorizontalKeypad {...defaultProps} />);
181
- expect(normalizeAdditionalKeys).toHaveBeenCalledWith([]);
182
- });
183
-
184
- it('should extend key set with additional keys', () => {
185
- const additionalKeys = [{ name: 'custom', latex: 'c' }];
186
- render(<HorizontalKeypad {...defaultProps} additionalKeys={additionalKeys} />);
187
-
188
- expect(extendKeySet).toHaveBeenCalled();
189
- const calls = extendKeySet.mock.calls[0];
190
- expect(calls).toHaveLength(2);
191
- });
192
- });
193
-
194
- describe('keypadPress callback', () => {
195
- it('should call onClick with transformed command data', () => {
196
- const onClick = jest.fn();
197
- const { container } = render(<HorizontalKeypad onClick={onClick} />);
198
-
199
- const keypad = screen.getByTestId('keypad');
200
- keypad.click();
201
-
202
- expect(onClick).toHaveBeenCalledWith({
203
- value: 'test',
204
- type: 'command',
205
- });
206
- });
207
-
208
- it('should transform command data correctly', () => {
209
- const onClick = jest.fn();
210
- const component = new HorizontalKeypad({ onClick });
211
-
212
- component.keypadPress({ command: 'sqrt' });
213
-
214
- expect(onClick).toHaveBeenCalledWith({
215
- value: 'sqrt',
216
- type: 'command',
217
- });
218
- });
219
-
220
- it('should transform write data correctly', () => {
221
- const onClick = jest.fn();
222
- const component = new HorizontalKeypad({ onClick });
223
-
224
- component.keypadPress({ write: 'x^2' });
225
-
226
- expect(onClick).toHaveBeenCalledWith({
227
- value: 'x^2',
228
- });
229
- });
230
-
231
- it('should transform keystroke data correctly', () => {
232
- const onClick = jest.fn();
233
- const component = new HorizontalKeypad({ onClick });
234
-
235
- component.keypadPress({ keystroke: 'Left' });
236
-
237
- expect(onClick).toHaveBeenCalledWith({
238
- type: 'cursor',
239
- value: 'Left',
240
- });
241
- });
242
-
243
- it('should handle data with only command', () => {
244
- const onClick = jest.fn();
245
- const component = new HorizontalKeypad({ onClick });
246
-
247
- component.keypadPress({ command: 'backspace' });
248
-
249
- expect(onClick).toHaveBeenCalledWith({
250
- value: 'backspace',
251
- type: 'command',
252
- });
253
- });
254
-
255
- it('should prioritize command over write', () => {
256
- const onClick = jest.fn();
257
- const component = new HorizontalKeypad({ onClick });
258
-
259
- component.keypadPress({ command: 'cmd', write: 'w' });
260
-
261
- expect(onClick).toHaveBeenCalledWith({
262
- value: 'cmd',
263
- type: 'command',
264
- });
265
- });
266
-
267
- it('should prioritize write over keystroke', () => {
268
- const onClick = jest.fn();
269
- const component = new HorizontalKeypad({ onClick });
270
-
271
- component.keypadPress({ write: 'w', keystroke: 'k' });
272
-
273
- expect(onClick).toHaveBeenCalledWith({
274
- value: 'w',
275
- });
276
- });
277
- });
278
-
279
- describe('toOldModel transformation', () => {
280
- it('should transform different data types correctly', () => {
281
- const onClick = jest.fn();
282
- const component = new HorizontalKeypad({ onClick });
283
-
284
- // command
285
- component.keypadPress({ command: 'frac' });
286
- expect(onClick).toHaveBeenLastCalledWith({ value: 'frac', type: 'command' });
287
-
288
- // write
289
- component.keypadPress({ write: 'pi' });
290
- expect(onClick).toHaveBeenLastCalledWith({ value: 'pi' });
291
-
292
- // keystroke
293
- component.keypadPress({ keystroke: 'Right' });
294
- expect(onClick).toHaveBeenLastCalledWith({ type: 'cursor', value: 'Right' });
295
- });
296
- });
297
-
298
- describe('additional keys handling', () => {
299
- it('should handle multiple additional keys', () => {
300
- const additionalKeys = [
301
- { name: 'alpha', latex: '\\alpha' },
302
- { name: 'beta', latex: '\\beta' },
303
- { name: 'gamma', latex: '\\gamma' },
304
- ];
305
-
306
- render(<HorizontalKeypad {...defaultProps} additionalKeys={additionalKeys} />);
307
-
308
- expect(normalizeAdditionalKeys).toHaveBeenCalledWith(additionalKeys);
309
- expect(extendKeySet).toHaveBeenCalled();
310
- });
311
-
312
- it('should handle empty additional keys array', () => {
313
- render(<HorizontalKeypad {...defaultProps} additionalKeys={[]} />);
314
-
315
- expect(normalizeAdditionalKeys).toHaveBeenCalledWith([]);
316
- });
317
-
318
- it('should use default empty array for additional keys', () => {
319
- render(<HorizontalKeypad {...defaultProps} />);
320
-
321
- expect(normalizeAdditionalKeys).toHaveBeenCalledWith([]);
322
- });
323
- });
324
-
325
- describe('re-rendering', () => {
326
- it('should update when mode changes', () => {
327
- const { rerender } = render(<HorizontalKeypad {...defaultProps} mode="scientific" />);
328
-
329
- expect(keysForGrade).toHaveBeenCalledWith('scientific');
330
-
331
- rerender(<HorizontalKeypad {...defaultProps} mode="geometry" />);
332
-
333
- expect(keysForGrade).toHaveBeenCalledWith('geometry');
334
- });
335
-
336
- it('should update when additional keys change', () => {
337
- const keys1 = [{ name: 'key1', latex: 'k1' }];
338
- const keys2 = [{ name: 'key2', latex: 'k2' }];
339
-
340
- const { rerender } = render(<HorizontalKeypad {...defaultProps} additionalKeys={keys1} />);
341
-
342
- expect(normalizeAdditionalKeys).toHaveBeenCalledWith(keys1);
343
-
344
- rerender(<HorizontalKeypad {...defaultProps} additionalKeys={keys2} />);
345
-
346
- expect(normalizeAdditionalKeys).toHaveBeenCalledWith(keys2);
347
- });
348
-
349
- it('should update when onClick changes', () => {
350
- const onClick1 = jest.fn();
351
- const onClick2 = jest.fn();
352
-
353
- const { rerender } = render(<HorizontalKeypad onClick={onClick1} />);
354
-
355
- rerender(<HorizontalKeypad onClick={onClick2} />);
356
-
357
- expect(screen.getByTestId('keypad')).toBeInTheDocument();
358
- });
359
- });
360
-
361
- describe('edge cases', () => {
362
- it('should handle undefined mode (uses default)', () => {
363
- render(<HorizontalKeypad {...defaultProps} mode={undefined} />);
364
- const keypad = screen.getByTestId('keypad');
365
- expect(keypad).toHaveAttribute('data-mode', 'scientific');
366
- });
367
-
368
- it('should handle null additional keys', () => {
369
- render(<HorizontalKeypad {...defaultProps} additionalKeys={null} />);
370
- expect(normalizeAdditionalKeys).toHaveBeenCalledWith(null);
371
- });
372
-
373
- it('should handle mode as 0', () => {
374
- render(<HorizontalKeypad {...defaultProps} mode={0} />);
375
- const keypad = screen.getByTestId('keypad');
376
- expect(keypad).toHaveAttribute('data-mode', '0');
377
- expect(keysForGrade).toHaveBeenCalledWith(0);
378
- });
379
-
380
- it('should handle empty string mode', () => {
381
- render(<HorizontalKeypad {...defaultProps} mode="" />);
382
- const keypad = screen.getByTestId('keypad');
383
- expect(keypad).toHaveAttribute('data-mode', '');
384
- });
385
-
386
- it('should handle keypadPress with empty object', () => {
387
- const onClick = jest.fn();
388
- const component = new HorizontalKeypad({ onClick });
389
-
390
- component.keypadPress({});
391
-
392
- expect(onClick).toHaveBeenCalled();
393
- });
394
- });
395
-
396
- describe('prop types validation', () => {
397
- const originalError = console.error;
398
- beforeAll(() => {
399
- console.error = jest.fn();
400
- });
401
- afterAll(() => {
402
- console.error = originalError;
403
- });
404
-
405
- it('should accept valid string mode', () => {
406
- expect(() => {
407
- render(<HorizontalKeypad {...defaultProps} mode="scientific" />);
408
- }).not.toThrow();
409
- });
410
-
411
- it('should accept valid number mode', () => {
412
- expect(() => {
413
- render(<HorizontalKeypad {...defaultProps} mode={6} />);
414
- }).not.toThrow();
415
- });
416
-
417
- it('should accept boolean controlledKeypadMode', () => {
418
- expect(() => {
419
- render(<HorizontalKeypad {...defaultProps} controlledKeypadMode={true} />);
420
- }).not.toThrow();
421
- });
422
-
423
- it('should accept object layoutForKeyPad', () => {
424
- expect(() => {
425
- render(<HorizontalKeypad {...defaultProps} layoutForKeyPad={{}} />);
426
- }).not.toThrow();
427
- });
428
-
429
- it('should accept function props', () => {
430
- expect(() => {
431
- render(<HorizontalKeypad onClick={jest.fn()} onFocus={jest.fn()} setKeypadInteraction={jest.fn()} />);
432
- }).not.toThrow();
433
- });
434
-
435
- it('should accept array additionalKeys', () => {
436
- expect(() => {
437
- render(<HorizontalKeypad {...defaultProps} additionalKeys={[]} />);
438
- }).not.toThrow();
439
- });
440
- });
441
-
442
- describe('component lifecycle', () => {
443
- it('should render correctly on mount', () => {
444
- const { container } = render(<HorizontalKeypad {...defaultProps} />);
445
- expect(container.firstChild).toBeInTheDocument();
446
- });
447
-
448
- it('should clean up properly on unmount', () => {
449
- const { unmount } = render(<HorizontalKeypad {...defaultProps} />);
450
- expect(() => unmount()).not.toThrow();
451
- });
452
-
453
- it('should handle multiple renders', () => {
454
- const { rerender } = render(<HorizontalKeypad {...defaultProps} />);
455
-
456
- rerender(<HorizontalKeypad {...defaultProps} mode="geometry" />);
457
- rerender(<HorizontalKeypad {...defaultProps} mode="scientific" />);
458
- rerender(<HorizontalKeypad {...defaultProps} mode="statistics" />);
459
-
460
- expect(screen.getByTestId('keypad')).toBeInTheDocument();
461
- });
462
- });
463
- });