@pie-lib/mask-markup 3.0.4-next.3 → 3.0.4-next.32

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 -468
  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 -169
  93. package/src/components/__tests__/correct-input.test.js +0 -90
  94. package/src/components/__tests__/dropdown.test.js +0 -93
  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 -410
  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,169 +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
- describe('Blank', () => {
30
- const onChange = jest.fn();
31
- const defaultProps = {
32
- disabled: false,
33
- choice: { value: 'Cow' },
34
- isOver: false,
35
- dragItem: {},
36
- correct: false,
37
- onChange,
38
- };
39
-
40
- beforeEach(() => {
41
- onChange.mockClear();
42
- });
43
-
44
- describe('rendering', () => {
45
- it('renders with default props', () => {
46
- const { container } = render(<Blank {...defaultProps} />);
47
- expect(container.firstChild).toBeInTheDocument();
48
- });
49
-
50
- it('displays the value when provided', () => {
51
- render(<Blank {...defaultProps} />);
52
- expect(screen.getByText('Cow')).toBeInTheDocument();
53
- });
54
-
55
- it('renders as disabled when disabled prop is true', () => {
56
- render(<Blank {...defaultProps} disabled={true} />);
57
- // Check that delete button is not present when disabled
58
- expect(screen.queryByRole('button', { name: /delete/i })).not.toBeInTheDocument();
59
- });
60
-
61
- it('renders with dragged item preview', () => {
62
- render(<Blank {...defaultProps} dragItem={{ choice: { value: 'Dog' } }} />);
63
- // Blank component should render
64
- expect(screen.getByText('Cow')).toBeInTheDocument();
65
- });
66
-
67
- it('shows hover state when isOver is true', () => {
68
- const { container } = render(<Blank {...defaultProps} dragItem={{ choice: { value: 'Dog' } }} isOver={true} />);
69
- // Component should have hover styling
70
- expect(container.firstChild).toBeInTheDocument();
71
- });
72
-
73
- it('shows correct state when correct is true', () => {
74
- const { container } = render(<Blank {...defaultProps} correct={true} />);
75
- // Component should indicate correctness
76
- expect(container.firstChild).toBeInTheDocument();
77
- });
78
- });
79
-
80
- describe('delete functionality', () => {
81
- it('does not show delete button when disabled', () => {
82
- render(<Blank {...defaultProps} disabled={true} />);
83
- expect(screen.queryByRole('button', { name: /delete/i })).not.toBeInTheDocument();
84
- });
85
-
86
- it('does not show delete button when no value is set', () => {
87
- render(<Blank {...defaultProps} choice={undefined} />);
88
- expect(screen.queryByRole('button', { name: /delete/i })).not.toBeInTheDocument();
89
- });
90
-
91
- it('shows delete button when value is present and not disabled', () => {
92
- render(<Blank {...defaultProps} />);
93
- // If delete button is present, it should be clickable
94
- const deleteButton = screen.queryByRole('button');
95
- if (deleteButton) {
96
- expect(deleteButton).toBeInTheDocument();
97
- }
98
- });
99
- });
100
-
101
- describe('dimensions', () => {
102
- it('renders with custom dimensions when provided', () => {
103
- const { container } = render(
104
- <Blank {...defaultProps} emptyResponseAreaHeight={100} emptyResponseAreaWidth={200} />,
105
- );
106
- const element = container.firstChild;
107
- expect(element).toBeInTheDocument();
108
- });
109
-
110
- it('renders with min dimensions by default', () => {
111
- const { container } = render(<Blank {...defaultProps} />);
112
- const element = container.firstChild;
113
- expect(element).toBeInTheDocument();
114
- // Component should have minimum dimensions applied
115
- });
116
-
117
- it('handles non-numeric dimension props gracefully', () => {
118
- const { container } = render(
119
- <Blank {...defaultProps} emptyResponseAreaHeight="non-numeric" emptyResponseAreaWidth="non-numeric" />,
120
- );
121
- expect(container.firstChild).toBeInTheDocument();
122
- });
123
-
124
- it('computes chip dimensions based on content when no emptyResponseArea size is provided', () => {
125
- jest.useFakeTimers();
126
- // Mock getBoundingClientRect to simulate measured content size
127
- const rectSpy = jest
128
- .spyOn(HTMLElement.prototype, 'getBoundingClientRect')
129
- .mockReturnValue({ width: 100, height: 20, top: 0, left: 0, right: 100, bottom: 20 });
130
-
131
- const { container } = render(
132
- <Blank
133
- {...defaultProps}
134
- // Force measurement path that uses getMeasureNode / updateDimensions
135
- emptyResponseAreaHeight={0}
136
- emptyResponseAreaWidth={0}
137
- />,
138
- );
139
-
140
- // Let the internal timeout in handleElements / updateDimensions run
141
- act(() => {
142
- jest.runAllTimers();
143
- });
144
-
145
- const wrapper = container.firstChild; // StyledContent
146
- const chip = wrapper && wrapper.firstChild; // StyledChip (rootRef)
147
-
148
- // Width and height should include padding (24px) around measured content
149
- expect(chip.style.width).toBe('124px');
150
- expect(chip.style.height).toBe('44px');
151
-
152
- rectSpy.mockRestore();
153
- jest.useRealTimers();
154
- });
155
- });
156
-
157
- describe('drag and drop', () => {
158
- it('accepts drag item when not disabled', () => {
159
- render(<Blank {...defaultProps} isOver={true} dragItem={{ choice: { value: 'Dog' } }} />);
160
- expect(screen.getByText('Cow')).toBeInTheDocument();
161
- });
162
-
163
- it('shows drag preview when dragging over', () => {
164
- const { container } = render(<Blank {...defaultProps} isOver={true} dragItem={{ choice: { value: 'Dog' } }} />);
165
- expect(container.firstChild).toBeInTheDocument();
166
- // Should show visual feedback for drag over
167
- });
168
- });
169
- });
@@ -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
- });
@@ -1,93 +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 { choice } from '../../__tests__/utils';
5
- import Dropdown from '../dropdown';
6
-
7
- describe('Dropdown', () => {
8
- const onChange = jest.fn();
9
- const defaultProps = {
10
- onChange,
11
- id: '1',
12
- correct: false,
13
- disabled: false,
14
- value: 'Jumped',
15
- choices: [choice('Jumped'), choice('Laughed'), choice('Smiled')],
16
- };
17
-
18
- beforeEach(() => {
19
- onChange.mockClear();
20
- });
21
-
22
- describe('rendering', () => {
23
- it('renders dropdown with default props', () => {
24
- render(<Dropdown {...defaultProps} />);
25
- const button = screen.getByRole('combobox');
26
- expect(button).toBeInTheDocument();
27
- // Button displays the selected value
28
- expect(button).toHaveTextContent('Jumped');
29
- });
30
-
31
- it('renders with all choices as options when opened', async () => {
32
- const user = userEvent.setup();
33
- render(<Dropdown {...defaultProps} />);
34
-
35
- const button = screen.getByRole('combobox');
36
- await user.click(button);
37
-
38
- // Options should now be visible - find them by role
39
- const options = screen.getAllByRole('option');
40
- expect(options).toHaveLength(3);
41
- // Verify the text content of options using specific elements
42
- expect(options[0]).toHaveTextContent('Jumped');
43
- expect(options[1]).toHaveTextContent('Laughed');
44
- expect(options[2]).toHaveTextContent('Smiled');
45
- });
46
-
47
- it('renders as disabled when disabled prop is true', () => {
48
- render(<Dropdown {...defaultProps} disabled={true} />);
49
- const button = screen.getByRole('combobox');
50
- expect(button).toBeDisabled();
51
- });
52
-
53
- it('shows correct state when correct is true', () => {
54
- const { container } = render(<Dropdown {...defaultProps} correct={true} />);
55
- const button = screen.getByRole('combobox');
56
- expect(button).toBeInTheDocument();
57
- });
58
- });
59
-
60
- describe('user interactions', () => {
61
- it('calls onChange when user selects a different option', async () => {
62
- const user = userEvent.setup();
63
- render(<Dropdown {...defaultProps} />);
64
-
65
- // Click button to open menu
66
- const button = screen.getByRole('combobox');
67
- await user.click(button);
68
-
69
- // Find the option by getting all options and selecting the one with "Laughed" text
70
- const options = screen.getAllByRole('option');
71
- const laughedOption = options.find((opt) => opt.textContent.includes('Laughed'));
72
- await user.click(laughedOption);
73
-
74
- expect(onChange).toHaveBeenCalledWith('1', 'Laughed');
75
- });
76
-
77
- it('calls onChange with correct value', async () => {
78
- const user = userEvent.setup();
79
- render(<Dropdown {...defaultProps} />);
80
-
81
- // Click button to open menu
82
- const button = screen.getByRole('combobox');
83
- await user.click(button);
84
-
85
- // Find the option by getting all options and selecting the one with "Smiled" text
86
- const options = screen.getAllByRole('option');
87
- const smiledOption = options.find((opt) => opt.textContent.includes('Smiled'));
88
- await user.click(smiledOption);
89
-
90
- expect(onChange).toHaveBeenCalledWith('1', 'Smiled');
91
- });
92
- });
93
- });