@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.
- package/CHANGELOG.md +6 -76
- package/lib/__tests__/drag-in-the-blank.test.js +129 -0
- package/lib/__tests__/index.test.js +42 -0
- package/lib/__tests__/mask.test.js +163 -0
- package/lib/__tests__/serialization.test.js +44 -0
- package/lib/__tests__/utils.js +14 -0
- package/lib/__tests__/with-mask.test.js +110 -0
- package/lib/choices/__tests__/index.test.js +101 -0
- package/lib/choices/choice.js +99 -204
- package/lib/choices/choice.js.map +1 -1
- package/lib/choices/index.js +22 -54
- package/lib/choices/index.js.map +1 -1
- package/lib/componentize.js +2 -6
- package/lib/componentize.js.map +1 -1
- package/lib/components/__tests__/blank.test.js +189 -0
- package/lib/components/__tests__/correct-input.test.js +132 -0
- package/lib/components/__tests__/dropdown.test.js +134 -0
- package/lib/components/__tests__/input.test.js +129 -0
- package/lib/components/blank.js +304 -362
- package/lib/components/blank.js.map +1 -1
- package/lib/components/correct-input.js +42 -66
- package/lib/components/correct-input.js.map +1 -1
- package/lib/components/dropdown.js +219 -258
- package/lib/components/dropdown.js.map +1 -1
- package/lib/components/input.js +11 -18
- package/lib/components/input.js.map +1 -1
- package/lib/constructed-response.js +39 -53
- package/lib/constructed-response.js.map +1 -1
- package/lib/customizable.js +6 -10
- package/lib/customizable.js.map +1 -1
- package/lib/drag-in-the-blank.js +141 -106
- package/lib/drag-in-the-blank.js.map +1 -1
- package/lib/index.js +1 -8
- package/lib/index.js.map +1 -1
- package/lib/inline-dropdown.js +5 -13
- package/lib/inline-dropdown.js.map +1 -1
- package/lib/mask.js +61 -119
- package/lib/mask.js.map +1 -1
- package/lib/serialization.js +9 -49
- package/lib/serialization.js.map +1 -1
- package/lib/with-mask.js +31 -59
- package/lib/with-mask.js.map +1 -1
- package/package.json +12 -20
- package/src/__tests__/drag-in-the-blank.test.js +66 -26
- package/src/__tests__/mask.test.js +147 -112
- package/src/__tests__/with-mask.test.js +44 -19
- package/src/choices/__tests__/index.test.js +38 -25
- package/src/choices/choice.jsx +86 -153
- package/src/choices/index.jsx +9 -3
- package/src/components/__tests__/blank.test.js +92 -156
- package/src/components/__tests__/correct-input.test.js +60 -19
- package/src/components/__tests__/dropdown.test.js +61 -19
- package/src/components/__tests__/input.test.js +72 -20
- package/src/components/blank.jsx +273 -272
- package/src/components/correct-input.jsx +33 -39
- package/src/components/dropdown.jsx +173 -161
- package/src/constructed-response.jsx +22 -18
- package/src/drag-in-the-blank.jsx +131 -42
- package/src/mask.jsx +38 -29
- package/src/with-mask.jsx +7 -4
- package/esm/index.css +0 -847
- package/esm/index.js +0 -195939
- package/esm/index.js.map +0 -1
- package/esm/package.json +0 -3
- package/src/__tests__/__snapshots__/drag-in-the-blank.test.js.snap +0 -316
- package/src/__tests__/__snapshots__/mask.test.js.snap +0 -55
- package/src/__tests__/__snapshots__/with-mask.test.js.snap +0 -62
- package/src/choices/__tests__/__snapshots__/index.test.js.snap +0 -209
- package/src/components/__tests__/__snapshots__/blank.test.js.snap +0 -111
- package/src/components/__tests__/__snapshots__/correct-input.test.js.snap +0 -64
- package/src/components/__tests__/__snapshots__/dropdown.test.js.snap +0 -136
- package/src/components/__tests__/__snapshots__/input.test.js.snap +0 -34
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
3
|
import Mask from '../mask';
|
|
4
4
|
|
|
5
5
|
describe('Mask', () => {
|
|
6
|
-
|
|
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
|
-
|
|
26
|
+
onChange.mockClear();
|
|
29
27
|
});
|
|
30
28
|
|
|
31
|
-
describe('
|
|
32
|
-
it('renders
|
|
33
|
-
|
|
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
|
|
37
|
-
|
|
38
|
-
|
|
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
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
},
|
|
82
|
-
],
|
|
83
|
-
},
|
|
84
|
-
],
|
|
85
|
-
},
|
|
86
|
-
],
|
|
87
|
-
},
|
|
88
|
-
],
|
|
89
|
-
},
|
|
90
|
-
});
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
}}
|
|
61
|
+
/>,
|
|
62
|
+
);
|
|
91
63
|
|
|
92
|
-
|
|
64
|
+
// Paragraph is rendered as a styled div, not a <p> tag
|
|
65
|
+
expect(screen.getByText('Foo')).toBeInTheDocument();
|
|
93
66
|
});
|
|
94
67
|
|
|
95
|
-
it
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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(
|
|
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
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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 {
|
|
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"
|
|
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
|
-
|
|
25
|
+
onChange.mockClear();
|
|
26
26
|
});
|
|
27
27
|
|
|
28
|
-
describe('
|
|
29
|
-
it('renders
|
|
30
|
-
|
|
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
|
-
|
|
36
|
-
|
|
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('
|
|
40
|
-
const
|
|
61
|
+
it('passes event to onChange', async () => {
|
|
62
|
+
const user = userEvent.setup();
|
|
63
|
+
render(<Masked {...defaultProps} />);
|
|
41
64
|
|
|
42
|
-
|
|
65
|
+
const input = screen.queryByTestId('masked-input');
|
|
66
|
+
if (input) {
|
|
67
|
+
await user.clear(input);
|
|
68
|
+
await user.type(input, 'test');
|
|
43
69
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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 {
|
|
3
|
-
import
|
|
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
|
-
|
|
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
|
-
|
|
25
|
-
expect(
|
|
40
|
+
const { container } = render(<Choices {...defaultProps} disabled={true} />);
|
|
41
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
26
42
|
});
|
|
43
|
+
|
|
27
44
|
it('renders without duplicates', () => {
|
|
28
|
-
|
|
29
|
-
expect(
|
|
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
|
-
|
|
34
|
-
expect(
|
|
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
|
-
|
|
42
|
-
|
|
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
|
-
|
|
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
|
-
|
|
58
|
-
expect(
|
|
70
|
+
const { container } = render(<Choice {...defaultProps} disabled={true} />);
|
|
71
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
59
72
|
});
|
|
60
73
|
});
|
|
61
74
|
});
|