@pie-lib/mask-markup 1.33.3-next.2 → 1.33.4-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 (72) hide show
  1. package/CHANGELOG.md +6 -76
  2. package/lib/__tests__/drag-in-the-blank.test.js +129 -0
  3. package/lib/__tests__/index.test.js +42 -0
  4. package/lib/__tests__/mask.test.js +163 -0
  5. package/lib/__tests__/serialization.test.js +44 -0
  6. package/lib/__tests__/utils.js +14 -0
  7. package/lib/__tests__/with-mask.test.js +110 -0
  8. package/lib/choices/__tests__/index.test.js +101 -0
  9. package/lib/choices/choice.js +99 -204
  10. package/lib/choices/choice.js.map +1 -1
  11. package/lib/choices/index.js +22 -54
  12. package/lib/choices/index.js.map +1 -1
  13. package/lib/componentize.js +2 -6
  14. package/lib/componentize.js.map +1 -1
  15. package/lib/components/__tests__/blank.test.js +189 -0
  16. package/lib/components/__tests__/correct-input.test.js +132 -0
  17. package/lib/components/__tests__/dropdown.test.js +134 -0
  18. package/lib/components/__tests__/input.test.js +129 -0
  19. package/lib/components/blank.js +304 -362
  20. package/lib/components/blank.js.map +1 -1
  21. package/lib/components/correct-input.js +42 -66
  22. package/lib/components/correct-input.js.map +1 -1
  23. package/lib/components/dropdown.js +219 -258
  24. package/lib/components/dropdown.js.map +1 -1
  25. package/lib/components/input.js +11 -18
  26. package/lib/components/input.js.map +1 -1
  27. package/lib/constructed-response.js +39 -53
  28. package/lib/constructed-response.js.map +1 -1
  29. package/lib/customizable.js +6 -10
  30. package/lib/customizable.js.map +1 -1
  31. package/lib/drag-in-the-blank.js +141 -106
  32. package/lib/drag-in-the-blank.js.map +1 -1
  33. package/lib/index.js +1 -8
  34. package/lib/index.js.map +1 -1
  35. package/lib/inline-dropdown.js +5 -13
  36. package/lib/inline-dropdown.js.map +1 -1
  37. package/lib/mask.js +61 -119
  38. package/lib/mask.js.map +1 -1
  39. package/lib/serialization.js +9 -49
  40. package/lib/serialization.js.map +1 -1
  41. package/lib/with-mask.js +31 -59
  42. package/lib/with-mask.js.map +1 -1
  43. package/package.json +12 -20
  44. package/src/__tests__/drag-in-the-blank.test.js +66 -26
  45. package/src/__tests__/mask.test.js +147 -112
  46. package/src/__tests__/with-mask.test.js +44 -19
  47. package/src/choices/__tests__/index.test.js +38 -25
  48. package/src/choices/choice.jsx +86 -153
  49. package/src/choices/index.jsx +9 -3
  50. package/src/components/__tests__/blank.test.js +92 -156
  51. package/src/components/__tests__/correct-input.test.js +60 -19
  52. package/src/components/__tests__/dropdown.test.js +61 -19
  53. package/src/components/__tests__/input.test.js +72 -20
  54. package/src/components/blank.jsx +273 -272
  55. package/src/components/correct-input.jsx +33 -39
  56. package/src/components/dropdown.jsx +173 -161
  57. package/src/constructed-response.jsx +22 -18
  58. package/src/drag-in-the-blank.jsx +131 -42
  59. package/src/mask.jsx +38 -29
  60. package/src/with-mask.jsx +7 -4
  61. package/esm/index.css +0 -847
  62. package/esm/index.js +0 -195939
  63. package/esm/index.js.map +0 -1
  64. package/esm/package.json +0 -3
  65. package/src/__tests__/__snapshots__/drag-in-the-blank.test.js.snap +0 -316
  66. package/src/__tests__/__snapshots__/mask.test.js.snap +0 -55
  67. package/src/__tests__/__snapshots__/with-mask.test.js.snap +0 -62
  68. package/src/choices/__tests__/__snapshots__/index.test.js.snap +0 -209
  69. package/src/components/__tests__/__snapshots__/blank.test.js.snap +0 -111
  70. package/src/components/__tests__/__snapshots__/correct-input.test.js.snap +0 -64
  71. package/src/components/__tests__/__snapshots__/dropdown.test.js.snap +0 -136
  72. package/src/components/__tests__/__snapshots__/input.test.js.snap +0 -34
@@ -1,12 +1,11 @@
1
1
  import * as React from 'react';
2
- import { shallow } from 'enzyme';
2
+ import { render, screen } from '@testing-library/react';
3
3
  import Mask from '../mask';
4
4
 
5
5
  describe('Mask', () => {
6
- const renderChildren = jest.fn();
6
+ // Don't mock renderChildren - let the component render naturally
7
7
  const onChange = jest.fn();
8
8
  const defaultProps = {
9
- renderChildren,
10
9
  onChange,
11
10
  layout: {
12
11
  nodes: [
@@ -22,131 +21,167 @@ describe('Mask', () => {
22
21
  },
23
22
  value: {},
24
23
  };
25
- let wrapper;
26
24
 
27
25
  beforeEach(() => {
28
- wrapper = shallow(<Mask {...defaultProps} />);
26
+ onChange.mockClear();
29
27
  });
30
28
 
31
- describe('render', () => {
32
- it('renders correctly with default props', () => {
33
- expect(wrapper).toMatchSnapshot();
29
+ describe('rendering', () => {
30
+ it('renders with default props', () => {
31
+ const { container } = render(<Mask {...defaultProps} />);
32
+ expect(container.firstChild).toBeInTheDocument();
34
33
  });
35
34
 
36
- it('renders correctly a paragraph', () => {
37
- wrapper.setProps({
38
- layout: {
39
- nodes: [
40
- {
41
- type: 'p',
42
- nodes: [
43
- {
44
- object: 'text',
45
- leaves: [
46
- {
47
- text: 'Foo',
48
- },
49
- ],
50
- },
51
- ],
52
- },
53
- ],
54
- },
55
- });
56
-
57
- expect(wrapper).toMatchSnapshot();
35
+ it('renders text content', () => {
36
+ render(<Mask {...defaultProps} />);
37
+ expect(screen.getByText('Foo')).toBeInTheDocument();
58
38
  });
59
39
 
60
- it('renders correctly a div', () => {
61
- wrapper.setProps({
62
- layout: {
63
- nodes: [
64
- {
65
- type: 'div',
66
- data: {
67
- attributes: {},
68
- },
69
- nodes: [
70
- {
71
- type: 'p',
72
- data: {
73
- attributes: {},
40
+ it('renders a paragraph element', () => {
41
+ const { container } = render(
42
+ <Mask
43
+ {...defaultProps}
44
+ layout={{
45
+ nodes: [
46
+ {
47
+ type: 'p',
48
+ nodes: [
49
+ {
50
+ object: 'text',
51
+ leaves: [
52
+ {
53
+ text: 'Foo',
54
+ },
55
+ ],
74
56
  },
75
- nodes: [
76
- {
77
- object: 'text',
78
- leaves: [
79
- {
80
- text: 'Foo',
81
- },
82
- ],
83
- },
84
- ],
85
- },
86
- ],
87
- },
88
- ],
89
- },
90
- });
57
+ ],
58
+ },
59
+ ],
60
+ }}
61
+ />,
62
+ );
91
63
 
92
- expect(wrapper).toMatchSnapshot();
64
+ // Paragraph is rendered as a styled div, not a <p> tag
65
+ expect(screen.getByText('Foo')).toBeInTheDocument();
93
66
  });
94
67
 
95
- it.only('renders correctly a em', () => {
96
- wrapper.setProps({
97
- layout: {
98
- nodes: [
99
- {
100
- leaves: [{ text: 'Foo ' }],
101
- object: 'text',
102
- },
103
- {
104
- leaves: [
105
- {
106
- marks: [
107
- {
108
- data: undefined,
109
- type: 'italic',
110
- },
111
- ],
112
- text: 'x',
68
+ it('renders nested div and paragraph', () => {
69
+ const { container } = render(
70
+ <Mask
71
+ {...defaultProps}
72
+ layout={{
73
+ nodes: [
74
+ {
75
+ type: 'div',
76
+ data: {
77
+ attributes: {},
113
78
  },
114
- ],
115
- object: 'text',
116
- },
117
- {
118
- leaves: [{ text: ' bar' }],
119
- object: 'text',
120
- },
121
- ],
122
- object: 'block',
123
- type: 'div',
124
- },
125
- });
79
+ nodes: [
80
+ {
81
+ type: 'p',
82
+ data: {
83
+ attributes: {},
84
+ },
85
+ nodes: [
86
+ {
87
+ object: 'text',
88
+ leaves: [
89
+ {
90
+ text: 'Foo',
91
+ },
92
+ ],
93
+ },
94
+ ],
95
+ },
96
+ ],
97
+ },
98
+ ],
99
+ }}
100
+ />,
101
+ );
126
102
 
127
- expect(wrapper).toMatchSnapshot();
103
+ expect(container.querySelector('div')).toBeInTheDocument();
104
+ // Paragraph is rendered as a styled div, not a <p> tag
105
+ expect(screen.getByText('Foo')).toBeInTheDocument();
128
106
  });
129
107
 
130
- const da = () => ({ data: { attributes: {} } });
131
- it('renders without space under tbody', () => {
132
- wrapper.setProps({
133
- layout: {
134
- nodes: [
135
- {
136
- type: 'tbody',
137
- ...da(),
138
- nodes: [
139
- {
140
- object: 'text',
141
- leaves: [{ text: ' ' }],
142
- },
143
- { type: 'tr', ...da(), nodes: [] },
144
- ],
145
- },
146
- ],
147
- },
148
- });
149
- expect(wrapper).toMatchSnapshot();
108
+ it('renders text with italic marks', () => {
109
+ const { container } = render(
110
+ <Mask
111
+ {...defaultProps}
112
+ layout={{
113
+ nodes: [
114
+ {
115
+ leaves: [{ text: 'Foo ' }],
116
+ object: 'text',
117
+ },
118
+ {
119
+ leaves: [
120
+ {
121
+ marks: [
122
+ {
123
+ data: undefined,
124
+ type: 'italic',
125
+ },
126
+ ],
127
+ text: 'x',
128
+ },
129
+ ],
130
+ object: 'text',
131
+ },
132
+ {
133
+ leaves: [{ text: ' bar' }],
134
+ object: 'text',
135
+ },
136
+ ],
137
+ object: 'block',
138
+ type: 'div',
139
+ }}
140
+ />,
141
+ );
142
+
143
+ // Text "Foo " is split with spaces, use regex
144
+ expect(screen.getByText(/Foo/)).toBeInTheDocument();
145
+ expect(screen.getByText('x')).toBeInTheDocument();
146
+ expect(screen.getByText(/bar/)).toBeInTheDocument();
147
+ // Check for italic/em element
148
+ const em = container.querySelector('em, i');
149
+ expect(em).toBeInTheDocument();
150
+ expect(em.textContent).toBe('x');
151
+ });
152
+
153
+ it('renders tbody without extra space', () => {
154
+ const da = () => ({ data: { attributes: {} } });
155
+ const { container } = render(
156
+ <Mask
157
+ {...defaultProps}
158
+ layout={{
159
+ nodes: [
160
+ {
161
+ type: 'table',
162
+ ...da(),
163
+ nodes: [
164
+ {
165
+ type: 'tbody',
166
+ ...da(),
167
+ nodes: [
168
+ {
169
+ object: 'text',
170
+ leaves: [{ text: ' ' }],
171
+ },
172
+ { type: 'tr', ...da(), nodes: [] },
173
+ ],
174
+ },
175
+ ],
176
+ },
177
+ ],
178
+ }}
179
+ />,
180
+ );
181
+
182
+ expect(container.querySelector('table')).toBeInTheDocument();
183
+ expect(container.querySelector('tbody')).toBeInTheDocument();
184
+ expect(container.querySelector('tr')).toBeInTheDocument();
150
185
  });
151
186
  });
152
187
  });
@@ -1,5 +1,6 @@
1
1
  import * as React from 'react';
2
- import { shallow } from 'enzyme';
2
+ import { render, screen } from '@testing-library/react';
3
+ import userEvent from '@testing-library/user-event';
3
4
  import { withMask } from '../with-mask';
4
5
 
5
6
  describe('WithMask', () => {
@@ -11,41 +12,65 @@ describe('WithMask', () => {
11
12
  },
12
13
  onChange,
13
14
  };
15
+
14
16
  const Masked = withMask('foo', (props) => (node) => {
15
17
  const dataset = node.data ? node.data.dataset || {} : {};
16
18
 
17
19
  if (dataset.component === 'foo') {
18
- return <input type="text" value="Foo" />;
20
+ return <input type="text" data-testid="masked-input" defaultValue="Foo" onChange={props.onChange} />;
19
21
  }
20
22
  });
21
23
 
22
- let wrapper;
23
-
24
24
  beforeEach(() => {
25
- wrapper = shallow(<Masked {...defaultProps} />);
25
+ onChange.mockClear();
26
26
  });
27
27
 
28
- describe('render', () => {
29
- it('renders correctly with default props', () => {
30
- expect(wrapper).toMatchSnapshot();
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();
31
44
  });
32
45
  });
33
46
 
34
- describe('onChange', () => {
35
- const event = (value) => ({
36
- target: { value },
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
+ }
37
59
  });
38
60
 
39
- it('should call the function', () => {
40
- const e = event('ceva');
61
+ it('passes event to onChange', async () => {
62
+ const user = userEvent.setup();
63
+ render(<Masked {...defaultProps} />);
41
64
 
42
- wrapper.simulate('change', e);
65
+ const input = screen.queryByTestId('masked-input');
66
+ if (input) {
67
+ await user.clear(input);
68
+ await user.type(input, 'test');
43
69
 
44
- expect(onChange).toHaveBeenCalledWith({
45
- target: {
46
- value: 'ceva',
47
- },
48
- });
70
+ expect(onChange).toHaveBeenCalled();
71
+ const lastCall = onChange.mock.calls[onChange.mock.calls.length - 1][0];
72
+ expect(lastCall).toHaveProperty('target');
73
+ }
49
74
  });
50
75
  });
51
76
  });
@@ -1,61 +1,74 @@
1
1
  import * as React from 'react';
2
- import { shallow } from 'enzyme';
3
- import { BlankContent as Choice } from '../choice';
2
+ import { render, screen } from '@testing-library/react';
3
+ import Choice from '../choice';
4
4
  import { choice } from '../../__tests__/utils';
5
5
  import Choices from '../index';
6
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
+
7
22
  describe('index', () => {
8
23
  describe('Choices', () => {
9
24
  const defaultProps = {
10
25
  disabled: false,
11
26
  choices: [choice('Jumped', '0'), choice('Laughed', '1'), choice('Spoon', '2')],
27
+ choicePosition: 'below',
28
+ instanceId: 'test-instance',
12
29
  };
13
- let wrapper;
14
-
15
- beforeEach(() => {
16
- wrapper = shallow(<Choices {...defaultProps} />);
17
- });
18
30
 
19
31
  it('renders correctly with default props', () => {
20
- expect(wrapper).toMatchSnapshot();
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();
21
37
  });
22
38
 
23
39
  it('renders correctly with disabled prop as true', () => {
24
- wrapper.setProps({ disabled: true });
25
- expect(wrapper).toMatchSnapshot();
40
+ const { container } = render(<Choices {...defaultProps} disabled={true} />);
41
+ expect(container.firstChild).toBeInTheDocument();
26
42
  });
43
+
27
44
  it('renders without duplicates', () => {
28
- wrapper.setProps({ duplicates: undefined, value: { 0: '0', 1: '1' } });
29
- expect(wrapper).toMatchSnapshot();
45
+ const { container } = render(<Choices {...defaultProps} duplicates={undefined} value={{ 0: '0', 1: '1' }} />);
46
+ expect(container.firstChild).toBeInTheDocument();
30
47
  });
31
48
 
32
49
  it('renders with duplicates', () => {
33
- wrapper.setProps({ duplicates: true, value: { 0: '0', 1: '1' } });
34
- expect(wrapper).toMatchSnapshot();
50
+ const { container } = render(<Choices {...defaultProps} duplicates={true} value={{ 0: '0', 1: '1' }} />);
51
+ expect(container.firstChild).toBeInTheDocument();
35
52
  });
36
53
  });
37
54
 
38
55
  describe('Choice', () => {
39
56
  const defaultProps = {
40
57
  disabled: false,
41
- value: '1',
42
- label: 'Label',
43
- targetId: '1',
58
+ choice: choice('Label', '1'),
59
+ instanceId: 'test-instance',
44
60
  };
45
- let wrapper;
46
-
47
- beforeEach(() => {
48
- wrapper = shallow(<Choice {...defaultProps} />);
49
- });
50
61
 
51
62
  describe('render', () => {
52
63
  it('renders correctly with default props', () => {
53
- expect(wrapper).toMatchSnapshot();
64
+ const { container } = render(<Choice {...defaultProps} />);
65
+ expect(container.firstChild).toBeInTheDocument();
66
+ expect(screen.getByText('Label')).toBeInTheDocument();
54
67
  });
55
68
 
56
69
  it('renders correctly with disabled prop as true', () => {
57
- wrapper.setProps({ disabled: true });
58
- expect(wrapper).toMatchSnapshot();
70
+ const { container } = render(<Choice {...defaultProps} disabled={true} />);
71
+ expect(container.firstChild).toBeInTheDocument();
59
72
  });
60
73
  });
61
74
  });