@pie-lib/mask-markup 2.0.0-beta.2 → 2.1.0-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.json +1 -871
- package/CHANGELOG.md +296 -2
- package/LICENSE.md +5 -0
- package/NEXT.CHANGELOG.json +1 -0
- 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 +100 -119
- package/lib/choices/choice.js.map +1 -1
- package/lib/choices/index.js +24 -20
- package/lib/choices/index.js.map +1 -1
- package/lib/componentize.js +2 -3
- 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 +316 -222
- package/lib/components/blank.js.map +1 -1
- package/lib/components/correct-input.js +40 -43
- package/lib/components/correct-input.js.map +1 -1
- package/lib/components/dropdown.js +394 -125
- package/lib/components/dropdown.js.map +1 -1
- package/lib/components/input.js +2 -3
- package/lib/components/input.js.map +1 -1
- package/lib/constructed-response.js +83 -27
- package/lib/constructed-response.js.map +1 -1
- package/lib/customizable.js +44 -0
- package/lib/customizable.js.map +1 -0
- package/lib/drag-in-the-blank.js +155 -62
- package/lib/drag-in-the-blank.js.map +1 -1
- package/lib/index.js +8 -1
- package/lib/index.js.map +1 -1
- package/lib/inline-dropdown.js +5 -4
- package/lib/inline-dropdown.js.map +1 -1
- package/lib/mask.js +90 -57
- package/lib/mask.js.map +1 -1
- package/lib/serialization.js +31 -43
- package/lib/serialization.js.map +1 -1
- package/lib/with-mask.js +49 -21
- package/lib/with-mask.js.map +1 -1
- package/package.json +18 -15
- package/src/__tests__/drag-in-the-blank.test.js +111 -0
- package/src/__tests__/index.test.js +39 -0
- package/src/__tests__/mask.test.js +187 -0
- package/src/__tests__/serialization.test.js +54 -0
- package/src/__tests__/utils.js +1 -0
- package/src/__tests__/with-mask.test.js +76 -0
- package/src/choices/__tests__/index.test.js +75 -0
- package/src/choices/choice.jsx +83 -96
- package/src/choices/index.jsx +11 -5
- package/src/components/__tests__/blank.test.js +138 -0
- package/src/components/__tests__/correct-input.test.js +90 -0
- package/src/components/__tests__/dropdown.test.js +93 -0
- package/src/components/__tests__/input.test.js +102 -0
- package/src/components/blank.jsx +316 -204
- package/src/components/correct-input.jsx +37 -38
- package/src/components/dropdown.jsx +371 -125
- package/src/constructed-response.jsx +71 -18
- package/src/customizable.jsx +35 -0
- package/src/drag-in-the-blank.jsx +152 -40
- package/src/index.js +10 -1
- package/src/inline-dropdown.jsx +2 -0
- package/src/mask.jsx +71 -25
- package/src/serialization.js +22 -34
- package/src/with-mask.jsx +43 -3
- package/README.md +0 -14
- package/lib/new-serialization.js +0 -267
- package/lib/new-serialization.js.map +0 -1
- package/lib/parse-html.js +0 -17
- package/lib/parse-html.js.map +0 -1
- package/lib/test-serializer.js +0 -164
- package/lib/test-serializer.js.map +0 -1
- package/src/new-serialization.jsx +0 -291
- package/src/parse-html.js +0 -8
- package/src/test-serializer.js +0 -163
|
@@ -0,0 +1,93 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import userEvent from '@testing-library/user-event';
|
|
4
|
+
import Input from '../input';
|
|
5
|
+
|
|
6
|
+
// Mock CorrectInput to simplify testing
|
|
7
|
+
jest.mock('../correct-input', () => {
|
|
8
|
+
return function CorrectInput({ value, onChange, disabled, correct, variant }) {
|
|
9
|
+
return (
|
|
10
|
+
<input
|
|
11
|
+
data-testid="correct-input"
|
|
12
|
+
value={value || ''}
|
|
13
|
+
onChange={onChange}
|
|
14
|
+
disabled={disabled}
|
|
15
|
+
data-correct={correct}
|
|
16
|
+
data-variant={variant}
|
|
17
|
+
/>
|
|
18
|
+
);
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe('Input', () => {
|
|
23
|
+
const onChange = jest.fn();
|
|
24
|
+
const defaultProps = {
|
|
25
|
+
disabled: false,
|
|
26
|
+
correct: false,
|
|
27
|
+
value: 'Cow',
|
|
28
|
+
id: '1',
|
|
29
|
+
onChange,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
beforeEach(() => {
|
|
33
|
+
onChange.mockClear();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe('rendering', () => {
|
|
37
|
+
it('renders with default props', () => {
|
|
38
|
+
render(<Input {...defaultProps} />);
|
|
39
|
+
const input = screen.getByTestId('correct-input');
|
|
40
|
+
|
|
41
|
+
expect(input).toBeInTheDocument();
|
|
42
|
+
expect(input).toHaveValue('Cow');
|
|
43
|
+
expect(input).not.toBeDisabled();
|
|
44
|
+
expect(input).toHaveAttribute('data-correct', 'false');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('renders as disabled when disabled prop is true', () => {
|
|
48
|
+
render(<Input {...defaultProps} disabled={true} />);
|
|
49
|
+
const input = screen.getByTestId('correct-input');
|
|
50
|
+
|
|
51
|
+
expect(input).toBeDisabled();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('renders with correct state', () => {
|
|
55
|
+
render(<Input {...defaultProps} correct={true} />);
|
|
56
|
+
const input = screen.getByTestId('correct-input');
|
|
57
|
+
|
|
58
|
+
expect(input).toHaveAttribute('data-correct', 'true');
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('shows correct answer when showCorrectAnswer is true', () => {
|
|
62
|
+
render(<Input {...defaultProps} showCorrectAnswer={true} />);
|
|
63
|
+
const input = screen.getByTestId('correct-input');
|
|
64
|
+
|
|
65
|
+
expect(input).toHaveAttribute('data-correct', 'true');
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
describe('user interactions', () => {
|
|
70
|
+
it('calls onChange with id and value when user types', async () => {
|
|
71
|
+
const user = userEvent.setup();
|
|
72
|
+
render(<Input {...defaultProps} value="" />);
|
|
73
|
+
|
|
74
|
+
const input = screen.getByTestId('correct-input');
|
|
75
|
+
await user.type(input, '20');
|
|
76
|
+
|
|
77
|
+
// userEvent.type types character by character, so onChange is called for each character
|
|
78
|
+
expect(onChange).toHaveBeenCalled();
|
|
79
|
+
expect(onChange).toHaveBeenCalledTimes(2);
|
|
80
|
+
// Check the last call has both characters
|
|
81
|
+
expect(onChange).toHaveBeenLastCalledWith('1', '0');
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('calls onChange with updated value', async () => {
|
|
85
|
+
const user = userEvent.setup();
|
|
86
|
+
render(<Input {...defaultProps} />);
|
|
87
|
+
|
|
88
|
+
const input = screen.getByTestId('correct-input');
|
|
89
|
+
await user.clear(input);
|
|
90
|
+
await user.type(input, 'New Value');
|
|
91
|
+
|
|
92
|
+
// userEvent.type types character by character
|
|
93
|
+
// After clear, we start with empty string, and each character is typed
|
|
94
|
+
// The last call should have the full accumulated value up to the last character
|
|
95
|
+
expect(onChange).toHaveBeenCalled();
|
|
96
|
+
// With clear + "New Value", onChange is called for clearing ("") and each typed character
|
|
97
|
+
// The value accumulated in the input element after typing will be "CowNew Value"
|
|
98
|
+
// because the component starts with value="Cow" and we clear then type
|
|
99
|
+
expect(onChange.mock.calls.length).toBeGreaterThan(0);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
});
|