@pie-lib/math-input 7.1.1-next.0 → 7.2.0-next.0

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 (80) hide show
  1. package/lib/horizontal-keypad.js +0 -3
  2. package/lib/horizontal-keypad.js.map +1 -1
  3. package/lib/index.js +0 -8
  4. package/lib/index.js.map +1 -1
  5. package/lib/keypad/index.js +2 -24
  6. package/lib/keypad/index.js.map +1 -1
  7. package/lib/keypad/keys-layout.js +4 -13
  8. package/lib/keypad/keys-layout.js.map +1 -1
  9. package/lib/keys/basic-operators.js +0 -1
  10. package/lib/keys/basic-operators.js.map +1 -1
  11. package/lib/keys/chars.js +0 -1
  12. package/lib/keys/chars.js.map +1 -1
  13. package/lib/keys/comparison.js +0 -10
  14. package/lib/keys/comparison.js.map +1 -1
  15. package/lib/keys/constants.js +0 -1
  16. package/lib/keys/constants.js.map +1 -1
  17. package/lib/keys/digits.js +2 -8
  18. package/lib/keys/digits.js.map +1 -1
  19. package/lib/keys/edit.js +0 -1
  20. package/lib/keys/edit.js.map +1 -1
  21. package/lib/keys/exponent.js +0 -1
  22. package/lib/keys/exponent.js.map +1 -1
  23. package/lib/keys/fractions.js +0 -1
  24. package/lib/keys/fractions.js.map +1 -1
  25. package/lib/keys/geometry.js +0 -10
  26. package/lib/keys/geometry.js.map +1 -1
  27. package/lib/keys/grades.js +0 -12
  28. package/lib/keys/grades.js.map +1 -1
  29. package/lib/keys/index.js +0 -7
  30. package/lib/keys/index.js.map +1 -1
  31. package/lib/keys/log.js +0 -1
  32. package/lib/keys/log.js.map +1 -1
  33. package/lib/keys/logic.js +0 -1
  34. package/lib/keys/logic.js.map +1 -1
  35. package/lib/keys/matrices.js +0 -1
  36. package/lib/keys/matrices.js.map +1 -1
  37. package/lib/keys/misc.js +0 -1
  38. package/lib/keys/misc.js.map +1 -1
  39. package/lib/keys/navigation.js +0 -1
  40. package/lib/keys/navigation.js.map +1 -1
  41. package/lib/keys/operators.js +0 -1
  42. package/lib/keys/operators.js.map +1 -1
  43. package/lib/keys/statistics.js +0 -1
  44. package/lib/keys/statistics.js.map +1 -1
  45. package/lib/keys/sub-sup.js +0 -1
  46. package/lib/keys/sub-sup.js.map +1 -1
  47. package/lib/keys/trigonometry.js +0 -1
  48. package/lib/keys/trigonometry.js.map +1 -1
  49. package/lib/keys/utils.js +8 -23
  50. package/lib/keys/utils.js.map +1 -1
  51. package/lib/keys/vars.js +0 -1
  52. package/lib/keys/vars.js.map +1 -1
  53. package/lib/math-input.js +0 -8
  54. package/lib/math-input.js.map +1 -1
  55. package/lib/mq/common-mq-styles.js +0 -10
  56. package/lib/mq/common-mq-styles.js.map +1 -1
  57. package/lib/mq/custom-elements.js +0 -1
  58. package/lib/mq/custom-elements.js.map +1 -1
  59. package/lib/mq/index.js +0 -1
  60. package/lib/mq/index.js.map +1 -1
  61. package/lib/mq/input.js +0 -10
  62. package/lib/mq/input.js.map +1 -1
  63. package/lib/mq/static.js +0 -14
  64. package/lib/mq/static.js.map +1 -1
  65. package/lib/updateSpans.js +0 -6
  66. package/lib/updateSpans.js.map +1 -1
  67. package/package.json +7 -3
  68. package/src/__tests__/horizontal-keypad.test.jsx +463 -0
  69. package/src/__tests__/index.test.js +242 -0
  70. package/src/__tests__/updateSpans.test.js +297 -0
  71. package/src/index.jsx +5 -6
  72. package/src/keypad/__tests__/keys-layout.test.js +0 -1
  73. package/src/keypad/index.jsx +3 -4
  74. package/src/keypad/keys-layout.js +4 -5
  75. package/src/keys/__tests__/utils.test.js +1 -1
  76. package/src/keys/digits.js +1 -1
  77. package/src/keys/index.js +5 -6
  78. package/src/keys/utils.js +6 -11
  79. package/src/mq/__tests__/custom-elements.test.js +342 -0
  80. package/NEXT.CHANGELOG.json +0 -1
@@ -0,0 +1,342 @@
1
+ import { registerLineBreak } from '../custom-elements';
2
+
3
+ describe('custom-elements', () => {
4
+ describe('registerLineBreak', () => {
5
+ let mockMQ;
6
+ let mockRegisterEmbed;
7
+ let embedCallback;
8
+
9
+ beforeEach(() => {
10
+ mockRegisterEmbed = jest.fn((name, callback) => {
11
+ embedCallback = callback;
12
+ });
13
+
14
+ mockMQ = {
15
+ registerEmbed: mockRegisterEmbed,
16
+ };
17
+ });
18
+
19
+ afterEach(() => {
20
+ jest.clearAllMocks();
21
+ embedCallback = null;
22
+ });
23
+
24
+ it('should call MQ.registerEmbed with "newLine" as the embed name', () => {
25
+ registerLineBreak(mockMQ);
26
+
27
+ expect(mockRegisterEmbed).toHaveBeenCalledTimes(1);
28
+ expect(mockRegisterEmbed).toHaveBeenCalledWith('newLine', expect.any(Function));
29
+ });
30
+
31
+ it('should register an embed callback function', () => {
32
+ registerLineBreak(mockMQ);
33
+
34
+ expect(embedCallback).toBeDefined();
35
+ expect(typeof embedCallback).toBe('function');
36
+ });
37
+
38
+ describe('newLine embed configuration', () => {
39
+ let embedConfig;
40
+
41
+ beforeEach(() => {
42
+ registerLineBreak(mockMQ);
43
+ embedConfig = embedCallback();
44
+ });
45
+
46
+ it('should return a configuration object with all required properties', () => {
47
+ expect(embedConfig).toHaveProperty('htmlString');
48
+ expect(embedConfig).toHaveProperty('text');
49
+ expect(embedConfig).toHaveProperty('latex');
50
+ });
51
+
52
+ it('should return htmlString with newLine div', () => {
53
+ expect(embedConfig.htmlString).toBe('<div class="newLine"></div>');
54
+ });
55
+
56
+ it('should return text function that returns "testText"', () => {
57
+ expect(embedConfig.text).toBeDefined();
58
+ expect(typeof embedConfig.text).toBe('function');
59
+ expect(embedConfig.text()).toBe('testText');
60
+ });
61
+
62
+ it('should return latex function that returns embed syntax', () => {
63
+ expect(embedConfig.latex).toBeDefined();
64
+ expect(typeof embedConfig.latex).toBe('function');
65
+ expect(embedConfig.latex()).toBe('\\embed{newLine}[]');
66
+ });
67
+
68
+ it('should return consistent values on multiple calls', () => {
69
+ const firstCall = embedCallback();
70
+ const secondCall = embedCallback();
71
+
72
+ expect(firstCall.htmlString).toBe(secondCall.htmlString);
73
+ expect(firstCall.text()).toBe(secondCall.text());
74
+ expect(firstCall.latex()).toBe(secondCall.latex());
75
+ });
76
+
77
+ it('should have text function that returns the same value on multiple invocations', () => {
78
+ expect(embedConfig.text()).toBe('testText');
79
+ expect(embedConfig.text()).toBe('testText');
80
+ expect(embedConfig.text()).toBe('testText');
81
+ });
82
+
83
+ it('should have latex function that returns the same value on multiple invocations', () => {
84
+ expect(embedConfig.latex()).toBe('\\embed{newLine}[]');
85
+ expect(embedConfig.latex()).toBe('\\embed{newLine}[]');
86
+ expect(embedConfig.latex()).toBe('\\embed{newLine}[]');
87
+ });
88
+ });
89
+
90
+ describe('integration scenarios', () => {
91
+ it('should handle multiple registrations without errors', () => {
92
+ registerLineBreak(mockMQ);
93
+ expect(() => registerLineBreak(mockMQ)).not.toThrow();
94
+
95
+ expect(mockRegisterEmbed).toHaveBeenCalledTimes(2);
96
+ });
97
+
98
+ it('should work with different MQ instances', () => {
99
+ const mockMQ1 = { registerEmbed: jest.fn() };
100
+ const mockMQ2 = { registerEmbed: jest.fn() };
101
+
102
+ registerLineBreak(mockMQ1);
103
+ registerLineBreak(mockMQ2);
104
+
105
+ expect(mockMQ1.registerEmbed).toHaveBeenCalledTimes(1);
106
+ expect(mockMQ2.registerEmbed).toHaveBeenCalledTimes(1);
107
+ });
108
+
109
+ it('should register embed with correct callback signature', () => {
110
+ registerLineBreak(mockMQ);
111
+
112
+ const callArgs = mockRegisterEmbed.mock.calls[0];
113
+ expect(callArgs[0]).toBe('newLine');
114
+ expect(callArgs[1]).toBeInstanceOf(Function);
115
+ });
116
+ });
117
+
118
+ describe('embed configuration structure', () => {
119
+ it('should return an object with exactly 3 properties', () => {
120
+ registerLineBreak(mockMQ);
121
+ const config = embedCallback();
122
+
123
+ const keys = Object.keys(config);
124
+ expect(keys).toHaveLength(3);
125
+ expect(keys).toContain('htmlString');
126
+ expect(keys).toContain('text');
127
+ expect(keys).toContain('latex');
128
+ });
129
+
130
+ it('should have htmlString as a string type', () => {
131
+ registerLineBreak(mockMQ);
132
+ const config = embedCallback();
133
+
134
+ expect(typeof config.htmlString).toBe('string');
135
+ });
136
+
137
+ it('should have text as a function type', () => {
138
+ registerLineBreak(mockMQ);
139
+ const config = embedCallback();
140
+
141
+ expect(typeof config.text).toBe('function');
142
+ });
143
+
144
+ it('should have latex as a function type', () => {
145
+ registerLineBreak(mockMQ);
146
+ const config = embedCallback();
147
+
148
+ expect(typeof config.latex).toBe('function');
149
+ });
150
+ });
151
+
152
+ describe('HTML structure validation', () => {
153
+ it('should return htmlString with valid HTML div element', () => {
154
+ registerLineBreak(mockMQ);
155
+ const config = embedCallback();
156
+
157
+ expect(config.htmlString).toMatch(/<div[^>]*>.*<\/div>/);
158
+ });
159
+
160
+ it('should return htmlString with newLine class', () => {
161
+ registerLineBreak(mockMQ);
162
+ const config = embedCallback();
163
+
164
+ expect(config.htmlString).toContain('class="newLine"');
165
+ });
166
+
167
+ it('should return htmlString with empty div content', () => {
168
+ registerLineBreak(mockMQ);
169
+ const config = embedCallback();
170
+
171
+ expect(config.htmlString).toBe('<div class="newLine"></div>');
172
+ });
173
+ });
174
+
175
+ describe('LaTeX syntax validation', () => {
176
+ it('should return latex with correct embed syntax', () => {
177
+ registerLineBreak(mockMQ);
178
+ const config = embedCallback();
179
+
180
+ expect(config.latex()).toMatch(/\\embed\{[^}]+\}\[\]/);
181
+ });
182
+
183
+ it('should return latex with newLine identifier', () => {
184
+ registerLineBreak(mockMQ);
185
+ const config = embedCallback();
186
+
187
+ expect(config.latex()).toContain('newLine');
188
+ });
189
+
190
+ it('should return latex with empty bracket notation', () => {
191
+ registerLineBreak(mockMQ);
192
+ const config = embedCallback();
193
+
194
+ expect(config.latex()).toContain('[]');
195
+ });
196
+
197
+ it('should return latex that matches exact expected format', () => {
198
+ registerLineBreak(mockMQ);
199
+ const config = embedCallback();
200
+
201
+ expect(config.latex()).toBe('\\embed{newLine}[]');
202
+ });
203
+ });
204
+
205
+ describe('error handling', () => {
206
+ it('should not throw if MQ object is valid', () => {
207
+ expect(() => registerLineBreak(mockMQ)).not.toThrow();
208
+ });
209
+
210
+ it('should handle MQ with additional properties', () => {
211
+ const extendedMQ = {
212
+ registerEmbed: mockRegisterEmbed,
213
+ otherProperty: 'value',
214
+ otherMethod: jest.fn(),
215
+ };
216
+
217
+ expect(() => registerLineBreak(extendedMQ)).not.toThrow();
218
+ expect(mockRegisterEmbed).toHaveBeenCalledTimes(1);
219
+ });
220
+ });
221
+
222
+ describe('function export', () => {
223
+ it('should export registerLineBreak as a function', () => {
224
+ expect(typeof registerLineBreak).toBe('function');
225
+ });
226
+
227
+ it('should be callable', () => {
228
+ expect(() => registerLineBreak(mockMQ)).not.toThrow();
229
+ });
230
+
231
+ it('should accept one parameter', () => {
232
+ expect(registerLineBreak.length).toBe(1);
233
+ });
234
+ });
235
+
236
+ describe('embed callback behavior', () => {
237
+ it('should return functions that are new instances on each call', () => {
238
+ registerLineBreak(mockMQ);
239
+
240
+ const config1 = embedCallback();
241
+ const config2 = embedCallback();
242
+
243
+ expect(config1.text).not.toBe(config2.text);
244
+ expect(config1.latex).not.toBe(config2.latex);
245
+ });
246
+
247
+ it('should not require any parameters for embed callback', () => {
248
+ registerLineBreak(mockMQ);
249
+
250
+ expect(() => embedCallback()).not.toThrow();
251
+ expect(() => embedCallback(null)).not.toThrow();
252
+ expect(() => embedCallback('arg')).not.toThrow();
253
+ });
254
+ });
255
+
256
+ describe('text function behavior', () => {
257
+ it('should return a string', () => {
258
+ registerLineBreak(mockMQ);
259
+ const config = embedCallback();
260
+
261
+ expect(typeof config.text()).toBe('string');
262
+ });
263
+
264
+ it('should return a non-empty string', () => {
265
+ registerLineBreak(mockMQ);
266
+ const config = embedCallback();
267
+
268
+ expect(config.text().length).toBeGreaterThan(0);
269
+ });
270
+
271
+ it('should return the exact string "testText"', () => {
272
+ registerLineBreak(mockMQ);
273
+ const config = embedCallback();
274
+
275
+ expect(config.text()).toBe('testText');
276
+ });
277
+
278
+ it('should not accept parameters', () => {
279
+ registerLineBreak(mockMQ);
280
+ const config = embedCallback();
281
+
282
+ expect(config.text('ignored')).toBe('testText');
283
+ expect(config.text(123)).toBe('testText');
284
+ });
285
+ });
286
+
287
+ describe('latex function behavior', () => {
288
+ it('should return a string', () => {
289
+ registerLineBreak(mockMQ);
290
+ const config = embedCallback();
291
+
292
+ expect(typeof config.latex()).toBe('string');
293
+ });
294
+
295
+ it('should return a non-empty string', () => {
296
+ registerLineBreak(mockMQ);
297
+ const config = embedCallback();
298
+
299
+ expect(config.latex().length).toBeGreaterThan(0);
300
+ });
301
+
302
+ it('should start with backslash', () => {
303
+ registerLineBreak(mockMQ);
304
+ const config = embedCallback();
305
+
306
+ expect(config.latex()).toMatch(/^\\/);
307
+ });
308
+
309
+ it('should not accept parameters', () => {
310
+ registerLineBreak(mockMQ);
311
+ const config = embedCallback();
312
+
313
+ expect(config.latex('ignored')).toBe('\\embed{newLine}[]');
314
+ expect(config.latex(123)).toBe('\\embed{newLine}[]');
315
+ });
316
+ });
317
+
318
+ describe('registration validation', () => {
319
+ it('should register only one embed type', () => {
320
+ registerLineBreak(mockMQ);
321
+
322
+ expect(mockRegisterEmbed).toHaveBeenCalledTimes(1);
323
+ });
324
+
325
+ it('should use consistent embed name', () => {
326
+ registerLineBreak(mockMQ);
327
+
328
+ const firstArg = mockRegisterEmbed.mock.calls[0][0];
329
+ expect(firstArg).toBe('newLine');
330
+ });
331
+
332
+ it('should not modify the MQ object', () => {
333
+ const originalMQ = { registerEmbed: mockRegisterEmbed };
334
+ const mqKeysBeforeCount = Object.keys(originalMQ).length;
335
+
336
+ registerLineBreak(originalMQ);
337
+
338
+ expect(Object.keys(originalMQ)).toHaveLength(mqKeysBeforeCount);
339
+ });
340
+ });
341
+ });
342
+ });
@@ -1 +0,0 @@
1
- []