@pie-lib/math-input 8.1.0 → 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,8 +0,0 @@
1
- import { LEFT_ARROW, RIGHT_ARROW } from './chars';
2
- import { mkSet } from './utils';
3
-
4
- const set = mkSet('navigation');
5
-
6
- export const left = set({ label: LEFT_ARROW, keystroke: 'Left', ariaLabel: 'Move cursor left' });
7
-
8
- export const right = set({ label: RIGHT_ARROW, keystroke: 'Right', ariaLabel: 'Move cursor right' });
@@ -1,10 +0,0 @@
1
- import { mkSet } from './utils';
2
-
3
- const set = mkSet('operators');
4
-
5
- export const circleDot = set({
6
- name: 'CircleDot',
7
- label: '⋅',
8
- write: '\\cdot',
9
- ariaLabel: 'Dot multiplier',
10
- });
@@ -1,38 +0,0 @@
1
- import { mkSet } from './utils';
2
-
3
- const set = mkSet('statistics');
4
- export const xBar = set({
5
- name: 'X Bar',
6
- label: 'x̄',
7
- latex: '\\overline{x}',
8
- write: '\\overline{x}',
9
- });
10
-
11
- export const yBar = set({
12
- name: 'Y Bar',
13
- latex: '\\overline{y}',
14
- write: '\\overline{y}',
15
- });
16
-
17
- export const mu = set({
18
- name: 'mu',
19
- label: 'mu',
20
- latex: '\\mu',
21
- write: '\\mu',
22
- });
23
-
24
- export const sigma = set({
25
- name: 'Sigma',
26
- ariaLabel: 'Uppercase Sigma',
27
- label: '\\Sigma',
28
- latex: '\\Sigma',
29
- write: '\\Sigma',
30
- });
31
-
32
- export const smallSigma = set({
33
- name: 'sigma',
34
- ariaLabel: 'Lowercase Sigma',
35
- label: '\\sigma',
36
- latex: '\\sigma',
37
- write: '\\sigma',
38
- });
@@ -1,15 +0,0 @@
1
- import { mkSet } from './utils';
2
-
3
- const set = mkSet('sub-sup');
4
-
5
- export const superscript = set({
6
- name: 'Superscript',
7
- latex: 'x^{}',
8
- command: '^',
9
- });
10
-
11
- export const subscript = set({
12
- name: 'Subscript',
13
- latex: 'x_{}',
14
- command: '_',
15
- });
@@ -1,15 +0,0 @@
1
- import { mkSet } from './utils';
2
-
3
- const set = mkSet('trigonometry');
4
-
5
- export const sin = set({ name: 'sine', label: 'sin', command: '\\sin', latex: '\\sin' });
6
-
7
- export const cos = set({ name: 'cosine', label: 'cos', command: '\\cos', latex: '\\cos' });
8
-
9
- export const tan = set({ name: 'tanget', label: 'tan', command: '\\tan', latex: '\\tan' });
10
-
11
- export const sec = set({ name: 'secant', label: 'sec', command: '\\sec', latex: '\\sec' });
12
-
13
- export const csc = set({ name: 'cosecant', label: 'csc', command: '\\csc', latex: '\\csc' });
14
-
15
- export const cot = set({ name: 'cotangent', label: 'cot', command: '\\cot', latex: '\\cot' });
package/src/keys/utils.js DELETED
@@ -1,66 +0,0 @@
1
- import { flatten, times } from 'lodash-es';
2
-
3
- export const mkSet = (category) => (o) => ({ ...o, category });
4
-
5
- export const toArray = (o) => Object.keys(o).map((k) => o[k]);
6
-
7
- export const toKey = (category) => (v) => {
8
- if (typeof v === 'string') {
9
- return {
10
- name: v,
11
- label: v,
12
- category,
13
- write: v,
14
- };
15
- } else {
16
- return {
17
- ...v,
18
- category,
19
- };
20
- }
21
- };
22
-
23
- export const transformToKeySetStructure = (data = []) => {
24
- const structure = [];
25
-
26
- times(5, () => structure.push([]));
27
-
28
- let ln = data.length;
29
- let i = 0;
30
- let j = 0;
31
-
32
- while (j < ln) {
33
- structure[i++].push(data[j++]);
34
-
35
- if (i === 5) {
36
- i = 0;
37
- }
38
- }
39
-
40
- return structure;
41
- };
42
-
43
- const latexAndNameDontExist = (base) => (k) => {
44
- const flattened = flatten(base);
45
- const latexExists = flattened.some((b) => b.latex === k.latex);
46
- const nameExists = flattened.some((b) => b.name === k.name);
47
-
48
- return !latexExists && !nameExists;
49
- };
50
-
51
- export const extendKeySet = (base = [], keySetData = []) => {
52
- keySetData = keySetData.filter(latexAndNameDontExist(base));
53
-
54
- const final = [];
55
-
56
- times(5 - base.length, () => base.push([]));
57
- times(5, () => final.push([]));
58
-
59
- const extra = transformToKeySetStructure(keySetData);
60
-
61
- for (let i = 0; i < 5; i++) {
62
- final[i] = [...base[i], ...extra[i]];
63
- }
64
-
65
- return final;
66
- };
package/src/keys/vars.js DELETED
@@ -1,19 +0,0 @@
1
- import { mkSet } from './utils';
2
-
3
- const set = mkSet('vars');
4
-
5
- export const x = set({
6
- name: 'X',
7
- latex: 'x',
8
- write: 'x',
9
- });
10
- export const y = set({
11
- name: 'Y',
12
- latex: 'y',
13
- write: 'y',
14
- });
15
- export const theta = set({
16
- name: 'Theta',
17
- latex: '\\theta',
18
- write: '\\theta',
19
- });
@@ -1,119 +0,0 @@
1
- import React from 'react';
2
- import PropTypes from 'prop-types';
3
- import { styled } from '@mui/material/styles';
4
- import * as mq from './mq';
5
- import { baseSet } from './keys';
6
- import KeyPad from './keypad';
7
- import debug from 'debug';
8
-
9
- const log = debug('pie-lib:math-input');
10
-
11
- const grey = 'rgba(0, 0, 0, 0.23)';
12
-
13
- const MathInputContainer = styled('div')(({ theme, focused }) => ({
14
- borderRadius: '4px',
15
- border: `solid 1px ${focused ? theme.palette.primary.main : grey}`,
16
- marginTop: theme.spacing(1),
17
- marginBottom: theme.spacing(1),
18
- transition: 'border 200ms linear',
19
- }));
20
-
21
- const PadContainer = styled('div')({
22
- width: '100%',
23
- display: 'flex',
24
- });
25
-
26
- const StyledMqInput = styled(mq.Input)(({ theme }) => ({
27
- width: '100%',
28
- border: `solid 0px ${theme.palette.primary.light}`,
29
- transition: 'border 200ms linear',
30
- padding: theme.spacing(1),
31
- '&.mq-focused': {
32
- outline: 'none',
33
- boxShadow: 'none',
34
- border: `solid 0px ${theme.palette.primary.dark}`,
35
- },
36
- }));
37
-
38
- export class MathInput extends React.Component {
39
- static propTypes = {
40
- className: PropTypes.string,
41
- keyset: PropTypes.array,
42
- displayMode: PropTypes.oneOf(['block', 'block-on-focus']),
43
- latex: PropTypes.string,
44
- onChange: PropTypes.func,
45
- };
46
-
47
- static defaultProps = {
48
- keyset: [],
49
- displayMode: 'block',
50
- };
51
-
52
- constructor(props) {
53
- super(props);
54
- this.state = {
55
- focused: false,
56
- };
57
- }
58
-
59
- keypadPress = (key) => {
60
- log('[keypadPress] key:', key);
61
-
62
- if (!this.input) {
63
- return;
64
- }
65
-
66
- if (key.latex && !key.command) {
67
- this.input.write(key.latex);
68
- } else if (key.write) {
69
- this.input.write(key.write);
70
- } else if (key.command) {
71
- this.input.command(key.command);
72
- } else if (key.keystroke) {
73
- this.input.keystroke(key.keystroke);
74
- }
75
- };
76
-
77
- inputFocus = () => {
78
- this.setState({ focused: true });
79
- };
80
-
81
- inputBlur = () => {
82
- this.setState({ focused: false });
83
- };
84
-
85
- changeLatex = (l) => {
86
- const { onChange } = this.props;
87
-
88
- if (onChange && l !== this.props.latex) {
89
- log('[changeLatex]', l, this.props.latex);
90
- onChange(l);
91
- }
92
- };
93
-
94
- render() {
95
- const { className, keyset, latex } = this.props;
96
- const { focused } = this.state;
97
-
98
- const showKeypad = true; // TODO: add support for different displayModes - displayMode === 'block' || focused;
99
-
100
- return (
101
- <MathInputContainer className={className} focused={focused}>
102
- <StyledMqInput
103
- innerRef={(r) => (this.input = r)}
104
- onFocus={this.inputFocus}
105
- onBlur={this.inputBlur}
106
- latex={latex}
107
- onChange={this.changeLatex}
108
- />
109
- {showKeypad && (
110
- <PadContainer>
111
- <KeyPad baseSet={baseSet} additionalKeys={keyset} onPress={this.keypadPress} />
112
- </PadContainer>
113
- )}
114
- </MathInputContainer>
115
- );
116
- }
117
- }
118
-
119
- export default MathInput;
@@ -1,342 +0,0 @@
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,40 +0,0 @@
1
- import * as React from 'react';
2
- import { render } from '@testing-library/react';
3
- import { Input } from '../input';
4
-
5
- describe('Input', () => {
6
- const onChange = jest.fn();
7
- const defaultProps = {
8
- classes: {},
9
- className: 'className',
10
- onChange,
11
- };
12
-
13
- beforeEach(() => {
14
- onChange.mockClear();
15
- });
16
-
17
- describe('rendering', () => {
18
- it('renders with default props', () => {
19
- const { container } = render(<Input {...defaultProps} />);
20
- expect(container.firstChild).toBeInTheDocument();
21
- expect(container.firstChild).toHaveClass('className');
22
- });
23
-
24
- it('renders with latex prop', () => {
25
- const { container } = render(<Input {...defaultProps} latex="x^2" />);
26
- expect(container.firstChild).toBeInTheDocument();
27
- });
28
-
29
- it('renders with disabled prop', () => {
30
- const { container } = render(<Input {...defaultProps} disabled={true} />);
31
- expect(container.firstChild).toBeInTheDocument();
32
- });
33
- });
34
-
35
- // Note: Tests for internal methods (clear, blur, focus, command, keystroke, write)
36
- // are implementation details and cannot be directly tested with RTL.
37
- // These components are wrappers around MathQuill library and the original tests
38
- // focused on testing internal implementation via instance methods rather than user-facing behavior.
39
- // The actual MathQuill integration and user interactions are tested through integration/e2e tests.
40
- });