@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,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 CorrectInput from '../correct-input';
4
5
 
5
6
  describe('CorrectInput', () => {
@@ -11,39 +12,79 @@ describe('CorrectInput', () => {
11
12
  value: 'Cow',
12
13
  onChange,
13
14
  };
14
- let wrapper;
15
15
 
16
16
  beforeEach(() => {
17
- wrapper = shallow(<CorrectInput {...defaultProps} />);
17
+ onChange.mockClear();
18
18
  });
19
19
 
20
- describe('render', () => {
21
- it('renders correctly with default props', () => {
22
- expect(wrapper).toMatchSnapshot();
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');
23
26
  });
24
27
 
25
- it('renders correctly with disabled prop as true', () => {
26
- wrapper.setProps({ disabled: true });
27
- expect(wrapper).toMatchSnapshot();
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();
28
32
  });
29
33
 
30
- it('renders correctly with correct as false', () => {
31
- wrapper.setProps({ correct: false });
32
- expect(wrapper).toMatchSnapshot();
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();
33
51
  });
34
52
  });
35
53
 
36
- describe('onChange', () => {
37
- const event = (value) => ({
38
- target: { value },
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');
39
77
  });
40
78
 
41
- it('should be called', () => {
42
- const e = event('1');
79
+ it('updates value when user changes input', async () => {
80
+ const user = userEvent.setup();
81
+ render(<CorrectInput {...defaultProps} />);
43
82
 
44
- wrapper.simulate('change', e);
83
+ const input = screen.getByRole('textbox');
84
+ await user.clear(input);
85
+ await user.type(input, 'Dog');
45
86
 
46
- expect(onChange).toBeCalledWith(e);
87
+ expect(onChange).toHaveBeenCalled();
47
88
  });
48
89
  });
49
90
  });
@@ -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 { choice } from '../../__tests__/utils';
4
5
  import Dropdown from '../dropdown';
5
6
 
@@ -13,39 +14,80 @@ describe('Dropdown', () => {
13
14
  value: 'Jumped',
14
15
  choices: [choice('Jumped'), choice('Laughed'), choice('Smiled')],
15
16
  };
16
- let wrapper;
17
17
 
18
18
  beforeEach(() => {
19
- wrapper = shallow(<Dropdown {...defaultProps} />);
19
+ onChange.mockClear();
20
20
  });
21
21
 
22
- describe('render', () => {
23
- it('renders correctly with default props', () => {
24
- expect(wrapper).toMatchSnapshot();
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');
25
29
  });
26
30
 
27
- it('renders correctly with disabled prop as true', () => {
28
- wrapper.setProps({ disabled: true });
29
- expect(wrapper).toMatchSnapshot();
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();
30
51
  });
31
52
 
32
- it('renders correctly with correct as true', () => {
33
- wrapper.setProps({ correct: true });
34
- expect(wrapper).toMatchSnapshot();
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();
35
57
  });
36
58
  });
37
59
 
38
- describe('onChange', () => {
39
- const event = (value) => ({
40
- target: { value },
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');
41
75
  });
42
76
 
43
- it('should be called with an appropriate value', () => {
44
- const e = event('Laughed');
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);
45
84
 
46
- wrapper.simulate('change', e);
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);
47
89
 
48
- expect(onChange).toHaveBeenCalledWith({ target: { value: e.target.value } });
90
+ expect(onChange).toHaveBeenCalledWith('1', 'Smiled');
49
91
  });
50
92
  });
51
93
  });
@@ -1,50 +1,102 @@
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 Input from '../input';
4
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
+
5
22
  describe('Input', () => {
6
23
  const onChange = jest.fn();
7
24
  const defaultProps = {
8
25
  disabled: false,
9
26
  correct: false,
10
- variant: 'outlined',
11
27
  value: 'Cow',
12
28
  id: '1',
13
29
  onChange,
14
30
  };
15
- let wrapper;
16
31
 
17
32
  beforeEach(() => {
18
- wrapper = shallow(<Input {...defaultProps} />);
33
+ onChange.mockClear();
19
34
  });
20
35
 
21
- describe('render', () => {
22
- it('renders correctly with default props', () => {
23
- expect(wrapper).toMatchSnapshot();
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');
24
45
  });
25
46
 
26
- it('renders correctly with disabled prop as true', () => {
27
- wrapper.setProps({ disabled: true });
28
- expect(wrapper).toMatchSnapshot();
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();
29
52
  });
30
53
 
31
- it('renders correctly with correct as false', () => {
32
- wrapper.setProps({ correct: false });
33
- expect(wrapper).toMatchSnapshot();
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');
34
66
  });
35
67
  });
36
68
 
37
- describe('onChange', () => {
38
- const event = (value) => ({
39
- target: { value },
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');
40
82
  });
41
83
 
42
- it('should be called', () => {
43
- const e = event('20');
84
+ it('calls onChange with updated value', async () => {
85
+ const user = userEvent.setup();
86
+ render(<Input {...defaultProps} />);
44
87
 
45
- wrapper.simulate('change', e);
88
+ const input = screen.getByTestId('correct-input');
89
+ await user.clear(input);
90
+ await user.type(input, 'New Value');
46
91
 
47
- expect(onChange).toHaveBeenCalledWith('1', e.target.value);
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);
48
100
  });
49
101
  });
50
102
  });