@pie-lib/mask-markup 3.0.4-next.31 → 3.0.4-next.33

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 (107) hide show
  1. package/dist/_virtual/_rolldown/runtime.js +4 -0
  2. package/dist/choices/choice.d.ts +24 -0
  3. package/dist/choices/choice.js +77 -0
  4. package/dist/choices/index.d.ts +25 -0
  5. package/dist/choices/index.js +49 -0
  6. package/dist/componentize.d.ts +12 -0
  7. package/dist/componentize.js +4 -0
  8. package/dist/components/blank.d.ts +39 -0
  9. package/dist/components/blank.js +240 -0
  10. package/dist/components/correct-input.d.ts +11 -0
  11. package/dist/components/dropdown.d.ts +37 -0
  12. package/dist/components/dropdown.js +320 -0
  13. package/dist/components/input.d.ts +37 -0
  14. package/dist/constructed-response.d.ts +44 -0
  15. package/dist/constructed-response.js +55 -0
  16. package/dist/customizable.d.ts +43 -0
  17. package/dist/customizable.js +8 -0
  18. package/dist/drag-in-the-blank.d.ts +37 -0
  19. package/dist/drag-in-the-blank.js +164 -0
  20. package/dist/index.d.ts +15 -0
  21. package/dist/index.js +7 -0
  22. package/dist/inline-dropdown.d.ts +44 -0
  23. package/dist/inline-dropdown.js +24 -0
  24. package/dist/mask.d.ts +30 -0
  25. package/dist/mask.js +99 -0
  26. package/dist/node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.js +16 -0
  27. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/index.js +17 -0
  28. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/cssPrefix.js +9 -0
  29. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/cssUnitless.js +26 -0
  30. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/hasOwn.js +11 -0
  31. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/isFunction.js +11 -0
  32. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/isObject.js +11 -0
  33. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/prefixInfo.js +24 -0
  34. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/prefixProperties.js +32 -0
  35. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/prefixer.js +29 -0
  36. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/camelize.js +14 -0
  37. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/hyphenRe.js +8 -0
  38. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/hyphenate.js +12 -0
  39. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/separate.js +11 -0
  40. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/toLowerFirst.js +10 -0
  41. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/toUpperFirst.js +10 -0
  42. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/toStyleObject.js +55 -0
  43. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/toStyleString.js +16 -0
  44. package/dist/serialization.d.ts +34 -0
  45. package/dist/serialization.js +132 -0
  46. package/dist/with-mask.d.ts +55 -0
  47. package/dist/with-mask.js +45 -0
  48. package/package.json +39 -20
  49. package/CHANGELOG.json +0 -17
  50. package/CHANGELOG.md +0 -1256
  51. package/LICENSE.md +0 -5
  52. package/lib/choices/choice.js +0 -116
  53. package/lib/choices/choice.js.map +0 -1
  54. package/lib/choices/index.js +0 -103
  55. package/lib/choices/index.js.map +0 -1
  56. package/lib/componentize.js +0 -21
  57. package/lib/componentize.js.map +0 -1
  58. package/lib/components/blank.js +0 -371
  59. package/lib/components/blank.js.map +0 -1
  60. package/lib/components/correct-input.js +0 -94
  61. package/lib/components/correct-input.js.map +0 -1
  62. package/lib/components/dropdown.js +0 -483
  63. package/lib/components/dropdown.js.map +0 -1
  64. package/lib/components/input.js +0 -50
  65. package/lib/components/input.js.map +0 -1
  66. package/lib/constructed-response.js +0 -101
  67. package/lib/constructed-response.js.map +0 -1
  68. package/lib/customizable.js +0 -42
  69. package/lib/customizable.js.map +0 -1
  70. package/lib/drag-in-the-blank.js +0 -254
  71. package/lib/drag-in-the-blank.js.map +0 -1
  72. package/lib/index.js +0 -55
  73. package/lib/index.js.map +0 -1
  74. package/lib/inline-dropdown.js +0 -40
  75. package/lib/inline-dropdown.js.map +0 -1
  76. package/lib/mask.js +0 -198
  77. package/lib/mask.js.map +0 -1
  78. package/lib/serialization.js +0 -261
  79. package/lib/serialization.js.map +0 -1
  80. package/lib/with-mask.js +0 -97
  81. package/lib/with-mask.js.map +0 -1
  82. package/src/__tests__/drag-in-the-blank.test.js +0 -111
  83. package/src/__tests__/index.test.js +0 -38
  84. package/src/__tests__/mask.test.js +0 -381
  85. package/src/__tests__/serialization.test.js +0 -54
  86. package/src/__tests__/utils.js +0 -1
  87. package/src/__tests__/with-mask.test.js +0 -76
  88. package/src/choices/__tests__/index.test.js +0 -75
  89. package/src/choices/choice.jsx +0 -97
  90. package/src/choices/index.jsx +0 -64
  91. package/src/componentize.js +0 -13
  92. package/src/components/__tests__/blank.test.js +0 -199
  93. package/src/components/__tests__/correct-input.test.js +0 -90
  94. package/src/components/__tests__/dropdown.test.js +0 -129
  95. package/src/components/__tests__/input.test.js +0 -102
  96. package/src/components/blank.jsx +0 -386
  97. package/src/components/correct-input.jsx +0 -82
  98. package/src/components/dropdown.jsx +0 -423
  99. package/src/components/input.jsx +0 -48
  100. package/src/constructed-response.jsx +0 -87
  101. package/src/customizable.jsx +0 -34
  102. package/src/drag-in-the-blank.jsx +0 -241
  103. package/src/index.js +0 -16
  104. package/src/inline-dropdown.jsx +0 -29
  105. package/src/mask.jsx +0 -172
  106. package/src/serialization.js +0 -260
  107. package/src/with-mask.jsx +0 -75
@@ -1 +0,0 @@
1
- export const choice = (v, id) => ({ label: v, value: v, id });
@@ -1,76 +0,0 @@
1
- import * as React from 'react';
2
- import { render, screen } from '@testing-library/react';
3
- import userEvent from '@testing-library/user-event';
4
- import { withMask } from '../with-mask';
5
-
6
- describe('WithMask', () => {
7
- const onChange = jest.fn();
8
- const defaultProps = {
9
- markup: '<p>Foo bar {{0}} over the moon;</p>',
10
- value: {
11
- 0: 'blank',
12
- },
13
- onChange,
14
- };
15
-
16
- const Masked = withMask('foo', (props) => (node) => {
17
- const dataset = node.data ? node.data.dataset || {} : {};
18
-
19
- if (dataset.component === 'foo') {
20
- return <input type="text" data-testid="masked-input" defaultValue="Foo" onChange={props.onChange} />;
21
- }
22
- });
23
-
24
- beforeEach(() => {
25
- onChange.mockClear();
26
- });
27
-
28
- describe('rendering', () => {
29
- it('renders with default props', () => {
30
- const { container } = render(<Masked {...defaultProps} />);
31
- expect(container.firstChild).toBeInTheDocument();
32
- });
33
-
34
- it('renders markup content', () => {
35
- render(<Masked {...defaultProps} />);
36
- expect(screen.getByText(/Foo bar/)).toBeInTheDocument();
37
- });
38
-
39
- it('renders paragraph content', () => {
40
- const { container } = render(<Masked {...defaultProps} />);
41
- // Paragraph is rendered as a styled div, not a <p> tag
42
- expect(container.firstChild).toBeInTheDocument();
43
- expect(screen.getByText(/Foo bar/)).toBeInTheDocument();
44
- });
45
- });
46
-
47
- describe('onChange handler', () => {
48
- it('calls onChange when value changes', async () => {
49
- const user = userEvent.setup();
50
- render(<Masked {...defaultProps} />);
51
-
52
- const input = screen.queryByTestId('masked-input');
53
- if (input) {
54
- await user.clear(input);
55
- await user.type(input, 'ceva');
56
-
57
- expect(onChange).toHaveBeenCalled();
58
- }
59
- });
60
-
61
- it('passes event to onChange', async () => {
62
- const user = userEvent.setup();
63
- render(<Masked {...defaultProps} />);
64
-
65
- const input = screen.queryByTestId('masked-input');
66
- if (input) {
67
- await user.clear(input);
68
- await user.type(input, 'test');
69
-
70
- expect(onChange).toHaveBeenCalled();
71
- const lastCall = onChange.mock.calls[onChange.mock.calls.length - 1][0];
72
- expect(lastCall).toHaveProperty('target');
73
- }
74
- });
75
- });
76
- });
@@ -1,75 +0,0 @@
1
- import * as React from 'react';
2
- import { render, screen } from '@testing-library/react';
3
- import Choice from '../choice';
4
- import { choice } from '../../__tests__/utils';
5
- import Choices from '../index';
6
-
7
- // Mock @dnd-kit hooks to avoid DndContext requirement
8
- jest.mock('@dnd-kit/core', () => ({
9
- useDraggable: jest.fn(() => ({
10
- attributes: {},
11
- listeners: {},
12
- setNodeRef: jest.fn(),
13
- isDragging: false,
14
- })),
15
- useDroppable: jest.fn(() => ({
16
- setNodeRef: jest.fn(),
17
- isOver: false,
18
- active: null,
19
- })),
20
- }));
21
-
22
- describe('index', () => {
23
- describe('Choices', () => {
24
- const defaultProps = {
25
- disabled: false,
26
- choices: [choice('Jumped', '0'), choice('Laughed', '1'), choice('Spoon', '2')],
27
- choicePosition: 'below',
28
- instanceId: 'test-instance',
29
- };
30
-
31
- it('renders correctly with default props', () => {
32
- const { container } = render(<Choices {...defaultProps} />);
33
- expect(container.firstChild).toBeInTheDocument();
34
- expect(screen.getByText('Jumped')).toBeInTheDocument();
35
- expect(screen.getByText('Laughed')).toBeInTheDocument();
36
- expect(screen.getByText('Spoon')).toBeInTheDocument();
37
- });
38
-
39
- it('renders correctly with disabled prop as true', () => {
40
- const { container } = render(<Choices {...defaultProps} disabled={true} />);
41
- expect(container.firstChild).toBeInTheDocument();
42
- });
43
-
44
- it('renders without duplicates', () => {
45
- const { container } = render(<Choices {...defaultProps} duplicates={undefined} value={{ 0: '0', 1: '1' }} />);
46
- expect(container.firstChild).toBeInTheDocument();
47
- });
48
-
49
- it('renders with duplicates', () => {
50
- const { container } = render(<Choices {...defaultProps} duplicates={true} value={{ 0: '0', 1: '1' }} />);
51
- expect(container.firstChild).toBeInTheDocument();
52
- });
53
- });
54
-
55
- describe('Choice', () => {
56
- const defaultProps = {
57
- disabled: false,
58
- choice: choice('Label', '1'),
59
- instanceId: 'test-instance',
60
- };
61
-
62
- describe('render', () => {
63
- it('renders correctly with default props', () => {
64
- const { container } = render(<Choice {...defaultProps} />);
65
- expect(container.firstChild).toBeInTheDocument();
66
- expect(screen.getByText('Label')).toBeInTheDocument();
67
- });
68
-
69
- it('renders correctly with disabled prop as true', () => {
70
- const { container } = render(<Choice {...defaultProps} disabled={true} />);
71
- expect(container.firstChild).toBeInTheDocument();
72
- });
73
- });
74
- });
75
- });
@@ -1,97 +0,0 @@
1
- import React, { useEffect, useRef } from 'react';
2
- import PropTypes from 'prop-types';
3
- import { useDraggable } from '@dnd-kit/core';
4
- import { styled } from '@mui/material/styles';
5
- import Chip from '@mui/material/Chip';
6
- import { renderMath } from '@pie-lib/math-rendering';
7
- import { color } from '@pie-lib/render-ui';
8
-
9
- export const DRAG_TYPE = 'MaskBlank';
10
-
11
- const StyledChoice = styled('span')(({ theme, disabled }) => ({
12
- border: `solid 0px ${theme.palette.primary.main}`,
13
- borderRadius: theme.spacing(2),
14
- margin: theme.spacing(0.5),
15
- transform: 'translate(0, 0)',
16
- display: 'inline-flex',
17
- ...(disabled && {}),
18
- }));
19
-
20
- const StyledChip = styled(Chip)(() => ({
21
- backgroundColor: color.white(),
22
- border: `1px solid ${color.text()}`,
23
- color: color.text(),
24
- alignItems: 'center',
25
- display: 'inline-flex',
26
- height: 'initial',
27
- minHeight: '32px',
28
- fontSize: 'inherit',
29
- whiteSpace: 'pre-wrap',
30
- maxWidth: '374px',
31
- // Added for touch devices, for image content.
32
- // This will prevent the context menu from appearing and not allowing other interactions with the image.
33
- // If interactions with the image in the token will be requested we should handle only the context Menu.
34
- pointerEvents: 'none',
35
- borderRadius: '3px',
36
- paddingTop: '12px',
37
- paddingBottom: '12px',
38
-
39
- '&.Mui-disabled': {
40
- opacity: 1,
41
- },
42
- }));
43
-
44
- const StyledChipLabel = styled('span')(() => ({
45
- whiteSpace: 'normal',
46
- '& img': {
47
- display: 'block',
48
- padding: '2px 0',
49
- },
50
- '& mjx-frac': {
51
- fontSize: '120% !important',
52
- },
53
- }));
54
-
55
- export default function Choice({ choice, disabled, instanceId }) {
56
- const rootRef = useRef(null);
57
-
58
- const { attributes, listeners, setNodeRef, isDragging } = useDraggable({
59
- id: `choice-${choice.id}`,
60
- data: { choice, instanceId, fromChoice: true, type: DRAG_TYPE },
61
- disabled,
62
- });
63
-
64
- useEffect(() => {
65
- renderMath(rootRef.current);
66
- }, [choice.value]);
67
-
68
- return (
69
- <StyledChoice
70
- ref={setNodeRef}
71
- style={
72
- isDragging
73
- ? {
74
- width: rootRef.current?.offsetWidth,
75
- height: rootRef.current?.offsetHeight,
76
- }
77
- : {}
78
- }
79
- disabled={disabled}
80
- {...listeners}
81
- {...attributes}
82
- >
83
- <StyledChip
84
- clickable={false}
85
- disabled={disabled}
86
- ref={rootRef}
87
- label={<StyledChipLabel dangerouslySetInnerHTML={{ __html: choice.value }} />}
88
- />
89
- </StyledChoice>
90
- );
91
- }
92
-
93
- Choice.propTypes = {
94
- choice: PropTypes.object.isRequired,
95
- disabled: PropTypes.bool,
96
- instanceId: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
97
- };
@@ -1,64 +0,0 @@
1
- import React from 'react';
2
- import PropTypes from 'prop-types';
3
- import { findKey } from 'lodash-es';
4
- import Choice from './choice';
5
- import { DragDroppablePlaceholder } from '@pie-lib/drag';
6
-
7
- export default class Choices extends React.Component {
8
- static propTypes = {
9
- disabled: PropTypes.bool,
10
- duplicates: PropTypes.bool,
11
- choices: PropTypes.arrayOf(PropTypes.shape({ label: PropTypes.string, value: PropTypes.string })),
12
- value: PropTypes.object,
13
- choicePosition: PropTypes.string.isRequired,
14
- instanceId: PropTypes.string, // Added for drag isolation
15
- };
16
-
17
- getStyleForWrapper = () => {
18
- const { choicePosition } = this.props;
19
-
20
- switch (choicePosition) {
21
- case 'above':
22
- return {
23
- margin: '0 0 40px 0',
24
- };
25
-
26
- case 'below':
27
- return {
28
- margin: '40px 0 0 0',
29
- };
30
-
31
- case 'right':
32
- return {
33
- margin: '0 0 0 40px',
34
- };
35
-
36
- default:
37
- return {
38
- margin: '0 40px 0 0',
39
- };
40
- }
41
- };
42
-
43
- render() {
44
- const { disabled, duplicates, choices, value, instanceId } = this.props;
45
- const filteredChoices = choices.filter((c) => {
46
- if (duplicates === true) {
47
- return true;
48
- }
49
- const foundChoice = findKey(value, (v) => v === c.id);
50
- return foundChoice === undefined;
51
- });
52
- const elementStyle = { ...this.getStyleForWrapper(), minWidth: '100px' };
53
-
54
- return (
55
- <div style={elementStyle}>
56
- <DragDroppablePlaceholder disabled={disabled} instanceId={instanceId}>
57
- {filteredChoices.map((c, index) => (
58
- <Choice key={`${c.value}-${index}`} disabled={disabled} choice={c} instanceId={instanceId} />
59
- ))}
60
- </DragDroppablePlaceholder>
61
- </div>
62
- );
63
- }
64
- }
@@ -1,13 +0,0 @@
1
- const REGEX = /\{\{(\d+)\}\}/g;
2
-
3
- export default (s, t) => {
4
- if (!s) {
5
- return { markup: '' };
6
- }
7
-
8
- const markup = s.replace(REGEX, (match, g) => {
9
- return `<span data-component="${t}" data-id="${g}"></span>`;
10
- });
11
-
12
- return { markup };
13
- };
@@ -1,199 +0,0 @@
1
- import * as React from 'react';
2
- import { render, screen, act } from '@testing-library/react';
3
- import Blank from '../blank';
4
-
5
- // Mock @dnd-kit hooks to avoid DndContext requirement
6
- jest.mock('@dnd-kit/core', () => ({
7
- useDraggable: jest.fn(() => ({
8
- attributes: {},
9
- listeners: {},
10
- setNodeRef: jest.fn(),
11
- transform: null,
12
- isDragging: false,
13
- })),
14
- useDroppable: jest.fn(() => ({
15
- setNodeRef: jest.fn(),
16
- isOver: false,
17
- active: null,
18
- })),
19
- }));
20
-
21
- jest.mock('@dnd-kit/utilities', () => ({
22
- CSS: {
23
- Translate: {
24
- toString: jest.fn(() => 'translate3d(0, 0, 0)'),
25
- },
26
- },
27
- }));
28
-
29
- jest.mock('@pie-lib/math-rendering', () => ({
30
- renderMath: jest.fn(),
31
- }));
32
-
33
- describe('Blank', () => {
34
- const { renderMath } = require('@pie-lib/math-rendering');
35
- const onChange = jest.fn();
36
- const defaultProps = {
37
- disabled: false,
38
- choice: { value: 'Cow' },
39
- isOver: false,
40
- dragItem: {},
41
- correct: false,
42
- onChange,
43
- };
44
-
45
- beforeEach(() => {
46
- onChange.mockClear();
47
- renderMath.mockClear();
48
- });
49
-
50
- describe('rendering', () => {
51
- it('renders with default props', () => {
52
- const { container } = render(<Blank {...defaultProps} />);
53
- expect(container.firstChild).toBeInTheDocument();
54
- });
55
-
56
- it('displays the value when provided', () => {
57
- render(<Blank {...defaultProps} />);
58
- expect(screen.getByText('Cow')).toBeInTheDocument();
59
- });
60
-
61
- it('renders as disabled when disabled prop is true', () => {
62
- render(<Blank {...defaultProps} disabled={true} />);
63
- // Check that delete button is not present when disabled
64
- expect(screen.queryByRole('button', { name: /delete/i })).not.toBeInTheDocument();
65
- });
66
-
67
- it('renders with dragged item preview', () => {
68
- render(<Blank {...defaultProps} dragItem={{ choice: { value: 'Dog' } }} />);
69
- // Blank component should render
70
- expect(screen.getByText('Cow')).toBeInTheDocument();
71
- });
72
-
73
- it('shows hover state when isOver is true', () => {
74
- const { container } = render(<Blank {...defaultProps} dragItem={{ choice: { value: 'Dog' } }} isOver={true} />);
75
- // Component should have hover styling
76
- expect(container.firstChild).toBeInTheDocument();
77
- });
78
-
79
- it('shows correct state when correct is true', () => {
80
- const { container } = render(<Blank {...defaultProps} correct={true} />);
81
- // Component should indicate correctness
82
- expect(container.firstChild).toBeInTheDocument();
83
- });
84
- });
85
-
86
- describe('delete functionality', () => {
87
- it('does not show delete button when disabled', () => {
88
- render(<Blank {...defaultProps} disabled={true} />);
89
- expect(screen.queryByRole('button', { name: /delete/i })).not.toBeInTheDocument();
90
- });
91
-
92
- it('does not show delete button when no value is set', () => {
93
- render(<Blank {...defaultProps} choice={undefined} />);
94
- expect(screen.queryByRole('button', { name: /delete/i })).not.toBeInTheDocument();
95
- });
96
-
97
- it('shows delete button when value is present and not disabled', () => {
98
- render(<Blank {...defaultProps} />);
99
- // If delete button is present, it should be clickable
100
- const deleteButton = screen.queryByRole('button');
101
- if (deleteButton) {
102
- expect(deleteButton).toBeInTheDocument();
103
- }
104
- });
105
- });
106
-
107
- describe('dimensions', () => {
108
- it('renders with custom dimensions when provided', () => {
109
- const { container } = render(
110
- <Blank {...defaultProps} emptyResponseAreaHeight={100} emptyResponseAreaWidth={200} />,
111
- );
112
- const element = container.firstChild;
113
- expect(element).toBeInTheDocument();
114
- });
115
-
116
- it('renders with min dimensions by default', () => {
117
- const { container } = render(<Blank {...defaultProps} />);
118
- const element = container.firstChild;
119
- expect(element).toBeInTheDocument();
120
- // Component should have minimum dimensions applied
121
- });
122
-
123
- it('handles non-numeric dimension props gracefully', () => {
124
- const { container } = render(
125
- <Blank {...defaultProps} emptyResponseAreaHeight="non-numeric" emptyResponseAreaWidth="non-numeric" />,
126
- );
127
- expect(container.firstChild).toBeInTheDocument();
128
- });
129
-
130
- it('computes chip dimensions based on content when no emptyResponseArea size is provided', () => {
131
- jest.useFakeTimers();
132
- // Mock getBoundingClientRect to simulate measured content size
133
- const rectSpy = jest
134
- .spyOn(HTMLElement.prototype, 'getBoundingClientRect')
135
- .mockReturnValue({ width: 100, height: 20, top: 0, left: 0, right: 100, bottom: 20 });
136
-
137
- const { container } = render(
138
- <Blank
139
- {...defaultProps}
140
- // Force measurement path that uses getMeasureNode / updateDimensions
141
- emptyResponseAreaHeight={0}
142
- emptyResponseAreaWidth={0}
143
- />,
144
- );
145
-
146
- // Let the internal timeout in handleElements / updateDimensions run
147
- act(() => {
148
- jest.runAllTimers();
149
- });
150
-
151
- const wrapper = container.firstChild; // StyledContent
152
- const chip = wrapper && wrapper.firstChild; // StyledChip (rootRef)
153
-
154
- // Width and height should include padding (24px) around measured content
155
- expect(chip.style.width).toBe('124px');
156
- expect(chip.style.height).toBe('44px');
157
-
158
- rectSpy.mockRestore();
159
- jest.useRealTimers();
160
- });
161
- });
162
-
163
- describe('math rendering', () => {
164
- it('calls renderMath on mount when choice has content', () => {
165
- render(<Blank {...defaultProps} />);
166
- expect(renderMath).toHaveBeenCalled();
167
- });
168
-
169
- it('calls renderMath again when correct changes', () => {
170
- const { rerender } = render(<Blank {...defaultProps} correct={false} />);
171
- const callsAfterMount = renderMath.mock.calls.length;
172
- expect(callsAfterMount).toBeGreaterThan(0);
173
-
174
- rerender(<Blank {...defaultProps} correct={true} />);
175
- expect(renderMath.mock.calls.length).toBeGreaterThan(callsAfterMount);
176
- });
177
-
178
- it('does not call renderMath again when correct is unchanged', () => {
179
- const { rerender } = render(<Blank {...defaultProps} correct={true} />);
180
- const callsAfterMount = renderMath.mock.calls.length;
181
-
182
- rerender(<Blank {...defaultProps} correct={true} />);
183
- expect(renderMath.mock.calls.length).toBe(callsAfterMount);
184
- });
185
- });
186
-
187
- describe('drag and drop', () => {
188
- it('accepts drag item when not disabled', () => {
189
- render(<Blank {...defaultProps} isOver={true} dragItem={{ choice: { value: 'Dog' } }} />);
190
- expect(screen.getByText('Cow')).toBeInTheDocument();
191
- });
192
-
193
- it('shows drag preview when dragging over', () => {
194
- const { container } = render(<Blank {...defaultProps} isOver={true} dragItem={{ choice: { value: 'Dog' } }} />);
195
- expect(container.firstChild).toBeInTheDocument();
196
- // Should show visual feedback for drag over
197
- });
198
- });
199
- });
@@ -1,90 +0,0 @@
1
- import * as React from 'react';
2
- import { render, screen } from '@testing-library/react';
3
- import userEvent from '@testing-library/user-event';
4
- import CorrectInput from '../correct-input';
5
-
6
- describe('CorrectInput', () => {
7
- const onChange = jest.fn();
8
- const defaultProps = {
9
- disabled: false,
10
- correct: false,
11
- variant: 'outlined',
12
- value: 'Cow',
13
- onChange,
14
- };
15
-
16
- beforeEach(() => {
17
- onChange.mockClear();
18
- });
19
-
20
- describe('rendering', () => {
21
- it('renders input with default props', () => {
22
- render(<CorrectInput {...defaultProps} />);
23
- const input = screen.getByRole('textbox');
24
- expect(input).toBeInTheDocument();
25
- expect(input).toHaveValue('Cow');
26
- });
27
-
28
- it('renders as disabled when disabled prop is true', () => {
29
- render(<CorrectInput {...defaultProps} disabled={true} />);
30
- const input = screen.getByRole('textbox');
31
- expect(input).toBeDisabled();
32
- });
33
-
34
- it('renders with correct state as false', () => {
35
- const { container } = render(<CorrectInput {...defaultProps} correct={false} />);
36
- const input = screen.getByRole('textbox');
37
- expect(input).toBeInTheDocument();
38
- });
39
-
40
- it('renders with correct state as true', () => {
41
- const { container } = render(<CorrectInput {...defaultProps} correct={true} />);
42
- const input = screen.getByRole('textbox');
43
- expect(input).toBeInTheDocument();
44
- // Should show visual indication of correctness
45
- });
46
-
47
- it('renders with outlined variant', () => {
48
- render(<CorrectInput {...defaultProps} variant="outlined" />);
49
- const input = screen.getByRole('textbox');
50
- expect(input).toBeInTheDocument();
51
- });
52
- });
53
-
54
- describe('user interactions', () => {
55
- it('calls onChange when user types', async () => {
56
- const user = userEvent.setup();
57
- render(<CorrectInput {...defaultProps} />);
58
-
59
- const input = screen.getByRole('textbox');
60
- await user.clear(input);
61
- await user.type(input, '1');
62
-
63
- expect(onChange).toHaveBeenCalled();
64
- });
65
-
66
- it('calls onChange with event object', async () => {
67
- const user = userEvent.setup();
68
- render(<CorrectInput {...defaultProps} value="" />);
69
-
70
- const input = screen.getByRole('textbox');
71
- await user.type(input, 'test');
72
-
73
- expect(onChange).toHaveBeenCalled();
74
- // Check that onChange receives an event-like object
75
- const lastCall = onChange.mock.calls[onChange.mock.calls.length - 1][0];
76
- expect(lastCall).toHaveProperty('target');
77
- });
78
-
79
- it('updates value when user changes input', async () => {
80
- const user = userEvent.setup();
81
- render(<CorrectInput {...defaultProps} />);
82
-
83
- const input = screen.getByRole('textbox');
84
- await user.clear(input);
85
- await user.type(input, 'Dog');
86
-
87
- expect(onChange).toHaveBeenCalled();
88
- });
89
- });
90
- });