@pie-lib/mask-markup 1.13.46 → 1.15.0-beta.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 (76) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/NEXT.CHANGELOG.json +1 -0
  3. package/lib/__tests__/drag-in-the-blank.test.js +71 -0
  4. package/lib/__tests__/index.test.js +50 -0
  5. package/lib/__tests__/mask.test.js +149 -0
  6. package/lib/__tests__/serialization.test.js +45 -0
  7. package/lib/__tests__/utils.js +17 -0
  8. package/lib/__tests__/with-mask.test.js +65 -0
  9. package/lib/choices/__tests__/index.test.js +85 -0
  10. package/lib/choices/choice.js +81 -18
  11. package/lib/choices/index.js +12 -4
  12. package/lib/componentize.js +1 -1
  13. package/lib/components/__tests__/blank.test.js +234 -0
  14. package/lib/components/__tests__/correct-input.test.js +63 -0
  15. package/lib/components/__tests__/dropdown.test.js +70 -0
  16. package/lib/components/__tests__/input.test.js +64 -0
  17. package/lib/components/blank.js +147 -35
  18. package/lib/components/correct-input.js +9 -4
  19. package/lib/components/dropdown.js +183 -50
  20. package/lib/components/input.js +1 -1
  21. package/lib/constructed-response.js +88 -24
  22. package/lib/customizable.js +48 -0
  23. package/lib/drag-in-the-blank.js +35 -9
  24. package/lib/index.js +9 -1
  25. package/lib/inline-dropdown.js +4 -2
  26. package/lib/mask.js +46 -7
  27. package/lib/serialization.js +1 -1
  28. package/lib/with-mask.js +35 -3
  29. package/package.json +5 -5
  30. package/src/__tests__/__snapshots__/drag-in-the-blank.test.js.snap +316 -0
  31. package/src/__tests__/__snapshots__/mask.test.js.snap +55 -0
  32. package/src/__tests__/__snapshots__/with-mask.test.js.snap +62 -0
  33. package/src/__tests__/drag-in-the-blank.test.js +71 -0
  34. package/src/__tests__/index.test.js +39 -0
  35. package/src/__tests__/mask.test.js +152 -0
  36. package/src/__tests__/serialization.test.js +54 -0
  37. package/src/__tests__/utils.js +1 -0
  38. package/src/__tests__/with-mask.test.js +51 -0
  39. package/src/choices/__tests__/__snapshots__/index.test.js.snap +209 -0
  40. package/src/choices/__tests__/index.test.js +62 -0
  41. package/src/choices/choice.jsx +60 -6
  42. package/src/choices/index.jsx +2 -2
  43. package/src/components/__tests__/__snapshots__/blank.test.js.snap +111 -0
  44. package/src/components/__tests__/__snapshots__/correct-input.test.js.snap +64 -0
  45. package/src/components/__tests__/__snapshots__/dropdown.test.js.snap +133 -0
  46. package/src/components/__tests__/__snapshots__/input.test.js.snap +34 -0
  47. package/src/components/__tests__/blank.test.js +202 -0
  48. package/src/components/__tests__/correct-input.test.js +49 -0
  49. package/src/components/__tests__/dropdown.test.js +51 -0
  50. package/src/components/__tests__/input.test.js +50 -0
  51. package/src/components/blank.jsx +139 -28
  52. package/src/components/correct-input.jsx +6 -1
  53. package/src/components/dropdown.jsx +192 -71
  54. package/src/constructed-response.jsx +76 -18
  55. package/src/customizable.jsx +35 -0
  56. package/src/drag-in-the-blank.jsx +26 -3
  57. package/src/index.js +10 -1
  58. package/src/inline-dropdown.jsx +2 -0
  59. package/src/mask.jsx +30 -5
  60. package/src/serialization.js +1 -1
  61. package/src/with-mask.jsx +39 -2
  62. package/README.md +0 -14
  63. package/lib/choices/choice.js.map +0 -1
  64. package/lib/choices/index.js.map +0 -1
  65. package/lib/componentize.js.map +0 -1
  66. package/lib/components/blank.js.map +0 -1
  67. package/lib/components/correct-input.js.map +0 -1
  68. package/lib/components/dropdown.js.map +0 -1
  69. package/lib/components/input.js.map +0 -1
  70. package/lib/constructed-response.js.map +0 -1
  71. package/lib/drag-in-the-blank.js.map +0 -1
  72. package/lib/index.js.map +0 -1
  73. package/lib/inline-dropdown.js.map +0 -1
  74. package/lib/mask.js.map +0 -1
  75. package/lib/serialization.js.map +0 -1
  76. package/lib/with-mask.js.map +0 -1
@@ -0,0 +1,133 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Dropdown render renders correctly with correct as true 1`] = `
4
+ <Dropdown
5
+ choices={
6
+ Array [
7
+ Object {
8
+ "id": undefined,
9
+ "label": "Jumped",
10
+ "value": "Jumped",
11
+ },
12
+ Object {
13
+ "id": undefined,
14
+ "label": "Laughed",
15
+ "value": "Laughed",
16
+ },
17
+ Object {
18
+ "id": undefined,
19
+ "label": "Smiled",
20
+ "value": "Smiled",
21
+ },
22
+ ]
23
+ }
24
+ classes={
25
+ Object {
26
+ "correctIcon": "Dropdown-correctIcon-10",
27
+ "correctnessIndicatorIcon": "Dropdown-correctnessIndicatorIcon-9",
28
+ "disabledCorrect": "Dropdown-disabledCorrect-2",
29
+ "disabledIncorrect": "Dropdown-disabledIncorrect-3",
30
+ "incorrectIcon": "Dropdown-incorrectIcon-11",
31
+ "label": "Dropdown-label-7",
32
+ "menuRoot": "Dropdown-menuRoot-6",
33
+ "root": "Dropdown-root-1",
34
+ "selectMenu": "Dropdown-selectMenu-4",
35
+ "selected": "Dropdown-selected-5",
36
+ "srOnly": "Dropdown-srOnly-8",
37
+ }
38
+ }
39
+ correct={true}
40
+ disabled={false}
41
+ id="1"
42
+ onChange={[MockFunction]}
43
+ value="Jumped"
44
+ />
45
+ `;
46
+
47
+ exports[`Dropdown render renders correctly with default props 1`] = `
48
+ <Dropdown
49
+ choices={
50
+ Array [
51
+ Object {
52
+ "id": undefined,
53
+ "label": "Jumped",
54
+ "value": "Jumped",
55
+ },
56
+ Object {
57
+ "id": undefined,
58
+ "label": "Laughed",
59
+ "value": "Laughed",
60
+ },
61
+ Object {
62
+ "id": undefined,
63
+ "label": "Smiled",
64
+ "value": "Smiled",
65
+ },
66
+ ]
67
+ }
68
+ classes={
69
+ Object {
70
+ "correctIcon": "Dropdown-correctIcon-10",
71
+ "correctnessIndicatorIcon": "Dropdown-correctnessIndicatorIcon-9",
72
+ "disabledCorrect": "Dropdown-disabledCorrect-2",
73
+ "disabledIncorrect": "Dropdown-disabledIncorrect-3",
74
+ "incorrectIcon": "Dropdown-incorrectIcon-11",
75
+ "label": "Dropdown-label-7",
76
+ "menuRoot": "Dropdown-menuRoot-6",
77
+ "root": "Dropdown-root-1",
78
+ "selectMenu": "Dropdown-selectMenu-4",
79
+ "selected": "Dropdown-selected-5",
80
+ "srOnly": "Dropdown-srOnly-8",
81
+ }
82
+ }
83
+ correct={false}
84
+ disabled={false}
85
+ id="1"
86
+ onChange={[MockFunction]}
87
+ value="Jumped"
88
+ />
89
+ `;
90
+
91
+ exports[`Dropdown render renders correctly with disabled prop as true 1`] = `
92
+ <Dropdown
93
+ choices={
94
+ Array [
95
+ Object {
96
+ "id": undefined,
97
+ "label": "Jumped",
98
+ "value": "Jumped",
99
+ },
100
+ Object {
101
+ "id": undefined,
102
+ "label": "Laughed",
103
+ "value": "Laughed",
104
+ },
105
+ Object {
106
+ "id": undefined,
107
+ "label": "Smiled",
108
+ "value": "Smiled",
109
+ },
110
+ ]
111
+ }
112
+ classes={
113
+ Object {
114
+ "correctIcon": "Dropdown-correctIcon-10",
115
+ "correctnessIndicatorIcon": "Dropdown-correctnessIndicatorIcon-9",
116
+ "disabledCorrect": "Dropdown-disabledCorrect-2",
117
+ "disabledIncorrect": "Dropdown-disabledIncorrect-3",
118
+ "incorrectIcon": "Dropdown-incorrectIcon-11",
119
+ "label": "Dropdown-label-7",
120
+ "menuRoot": "Dropdown-menuRoot-6",
121
+ "root": "Dropdown-root-1",
122
+ "selectMenu": "Dropdown-selectMenu-4",
123
+ "selected": "Dropdown-selected-5",
124
+ "srOnly": "Dropdown-srOnly-8",
125
+ }
126
+ }
127
+ correct={false}
128
+ disabled={true}
129
+ id="1"
130
+ onChange={[MockFunction]}
131
+ value="Jumped"
132
+ />
133
+ `;
@@ -0,0 +1,34 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Input render renders correctly with correct as false 1`] = `
4
+ <WithStyles(Component)
5
+ correct={false}
6
+ disabled={false}
7
+ isBox={true}
8
+ onChange={[Function]}
9
+ value="Cow"
10
+ variant="outlined"
11
+ />
12
+ `;
13
+
14
+ exports[`Input render renders correctly with default props 1`] = `
15
+ <WithStyles(Component)
16
+ correct={false}
17
+ disabled={false}
18
+ isBox={true}
19
+ onChange={[Function]}
20
+ value="Cow"
21
+ variant="outlined"
22
+ />
23
+ `;
24
+
25
+ exports[`Input render renders correctly with disabled prop as true 1`] = `
26
+ <WithStyles(Component)
27
+ correct={false}
28
+ disabled={true}
29
+ isBox={true}
30
+ onChange={[Function]}
31
+ value="Cow"
32
+ variant="outlined"
33
+ />
34
+ `;
@@ -0,0 +1,202 @@
1
+ import * as React from 'react';
2
+ import { shallow } from 'enzyme';
3
+ import { BlankContent as Blank } from '../blank';
4
+
5
+ describe('Blank', () => {
6
+ const onChange = jest.fn();
7
+ const defaultProps = {
8
+ disabled: false,
9
+ value: 'Cow',
10
+ classes: {},
11
+ isOver: false,
12
+ dragItem: {},
13
+ correct: false,
14
+ onChange,
15
+ };
16
+ let wrapper;
17
+ let instance;
18
+
19
+ beforeEach(() => {
20
+ wrapper = shallow(<Blank {...defaultProps} />);
21
+ instance = wrapper.instance();
22
+ });
23
+
24
+ describe('render', () => {
25
+ it('renders correctly with default props', () => {
26
+ expect(wrapper).toMatchSnapshot();
27
+ });
28
+
29
+ it('renders correctly with disabled prop as true', () => {
30
+ wrapper.setProps({ disabled: true });
31
+ expect(wrapper).toMatchSnapshot();
32
+ });
33
+
34
+ it('renders correctly with draggedItem', () => {
35
+ wrapper.setProps({ dragItem: { choice: { value: 'Dog' } } });
36
+ expect(wrapper).toMatchSnapshot();
37
+ });
38
+
39
+ it('renders correctly with draggedItem and isOver', () => {
40
+ wrapper.setProps({ dragItem: { choice: { value: 'Dog' } }, isOver: true });
41
+ expect(wrapper).toMatchSnapshot();
42
+ });
43
+ });
44
+
45
+ describe('onDelete', () => {
46
+ it('should be undefined if disabled is true', () => {
47
+ wrapper.setProps({ disabled: true });
48
+
49
+ expect(wrapper.props().onDelete).toEqual(undefined);
50
+ });
51
+
52
+ it('should be undefined if no value is set', () => {
53
+ wrapper.setProps({ disabled: false, value: undefined });
54
+
55
+ expect(wrapper.props().onDelete).toEqual(undefined);
56
+ });
57
+ });
58
+
59
+ describe('updateDimensions', () => {
60
+ let span;
61
+ let rootRef;
62
+
63
+ const setSpanDimensions = (height, width) => {
64
+ Object.defineProperty(span, 'offsetHeight', { value: height, configurable: true });
65
+ Object.defineProperty(span, 'offsetWidth', { value: width, configurable: true });
66
+ };
67
+
68
+ beforeEach(() => {
69
+ wrapper = shallow(<Blank {...defaultProps} />);
70
+ instance = wrapper.instance();
71
+
72
+ span = document.createElement('span');
73
+ rootRef = document.createElement('span');
74
+
75
+ instance.spanRef = span;
76
+ instance.rootRef = rootRef;
77
+
78
+ Object.defineProperty(span, 'offsetHeight', { value: 0, configurable: true });
79
+ Object.defineProperty(span, 'offsetWidth', { value: 0, configurable: true });
80
+ });
81
+
82
+ it('should update dimensions if span size exceeds the response area size', () => {
83
+ setSpanDimensions(50, 50);
84
+
85
+ instance.updateDimensions();
86
+
87
+ expect(instance.state).toEqual({
88
+ width: 74,
89
+ height: 74,
90
+ });
91
+ });
92
+
93
+ it('should not update dimensions if span size does not exceed the response area size', () => {
94
+ wrapper.setProps({
95
+ emptyResponseAreaHeight: 50,
96
+ emptyResponseAreaWidth: 50,
97
+ });
98
+ setSpanDimensions(30, 30);
99
+
100
+ instance.updateDimensions();
101
+
102
+ expect(instance.state).toEqual({
103
+ width: 54, // with padding it does exceed (30 + 24 > 50) so it's updating
104
+ height: 54, // with padding it does exceed (30 + 24 > 50) so it's updating
105
+ });
106
+ });
107
+
108
+ it('should handle non-numeric emptyResponseAreaHeight and emptyResponseAreaWidth', () => {
109
+ wrapper.setProps({
110
+ emptyResponseAreaHeight: 'non-numeric',
111
+ emptyResponseAreaWidth: 'non-numeric',
112
+ });
113
+ setSpanDimensions(50, 50);
114
+
115
+ instance.updateDimensions();
116
+
117
+ expect(instance.state).toEqual({
118
+ width: 74,
119
+ height: 74,
120
+ });
121
+ });
122
+ });
123
+
124
+ describe('getRootDimensions', () => {
125
+ it('should return state dimensions if set', () => {
126
+ instance.setState({ height: 50, width: 50 });
127
+
128
+ const dimensions = instance.getRootDimensions();
129
+
130
+ expect(dimensions).toEqual({
131
+ height: 50,
132
+ width: 50,
133
+ minWidth: 90,
134
+ minHeight: 32,
135
+ });
136
+ });
137
+
138
+ it('should return state height and props width if state width is not set', () => {
139
+ instance.setState({ height: 50, width: 0 });
140
+
141
+ const dimensions = instance.getRootDimensions();
142
+
143
+ expect(dimensions).toEqual({
144
+ height: 50,
145
+ width: 0,
146
+ minWidth: 90,
147
+ minHeight: 32,
148
+ });
149
+ });
150
+
151
+ it('should return props height and state width if state height is not set', () => {
152
+ instance.setState({ height: 0, width: 50 });
153
+
154
+ const dimensions = instance.getRootDimensions();
155
+
156
+ expect(dimensions).toEqual({
157
+ height: 0,
158
+ width: 50,
159
+ minWidth: 90,
160
+ minHeight: 32,
161
+ });
162
+ });
163
+
164
+ it('should return props dimensions if state dimensions are zero', () => {
165
+ instance.setState({ height: 0, width: 0 });
166
+ wrapper.setProps({ emptyResponseAreaHeight: 60, emptyResponseAreaWidth: 60 });
167
+
168
+ const dimensions = instance.getRootDimensions();
169
+
170
+ expect(dimensions).toEqual({
171
+ height: 60,
172
+ width: 60,
173
+ });
174
+ });
175
+
176
+ it('should return state dimensions over props dimensions if both are set', () => {
177
+ instance.setState({ height: 50, width: 50 });
178
+ wrapper.setProps({ emptyResponseAreaHeight: 60, emptyResponseAreaWidth: 60 });
179
+
180
+ const dimensions = instance.getRootDimensions();
181
+
182
+ expect(dimensions).toEqual({
183
+ height: 50,
184
+ width: 50,
185
+ });
186
+ });
187
+
188
+ it('should return minWidth and minHeight if state and props dimensions are zero or undefined', () => {
189
+ instance.setState({ height: 0, width: 0 });
190
+ wrapper.setProps({ emptyResponseAreaHeight: undefined, emptyResponseAreaWidth: undefined });
191
+
192
+ const dimensions = instance.getRootDimensions();
193
+
194
+ expect(dimensions).toEqual({
195
+ height: 0,
196
+ width: 0,
197
+ minWidth: 90,
198
+ minHeight: 32,
199
+ });
200
+ });
201
+ });
202
+ });
@@ -0,0 +1,49 @@
1
+ import * as React from 'react';
2
+ import { shallow } from 'enzyme';
3
+ import CorrectInput from '../correct-input';
4
+
5
+ describe('CorrectInput', () => {
6
+ const onChange = jest.fn();
7
+ const defaultProps = {
8
+ disabled: false,
9
+ correct: false,
10
+ variant: 'outlined',
11
+ value: 'Cow',
12
+ onChange,
13
+ };
14
+ let wrapper;
15
+
16
+ beforeEach(() => {
17
+ wrapper = shallow(<CorrectInput {...defaultProps} />);
18
+ });
19
+
20
+ describe('render', () => {
21
+ it('renders correctly with default props', () => {
22
+ expect(wrapper).toMatchSnapshot();
23
+ });
24
+
25
+ it('renders correctly with disabled prop as true', () => {
26
+ wrapper.setProps({ disabled: true });
27
+ expect(wrapper).toMatchSnapshot();
28
+ });
29
+
30
+ it('renders correctly with correct as false', () => {
31
+ wrapper.setProps({ correct: false });
32
+ expect(wrapper).toMatchSnapshot();
33
+ });
34
+ });
35
+
36
+ describe('onChange', () => {
37
+ const event = (value) => ({
38
+ target: { value },
39
+ });
40
+
41
+ it('should be called', () => {
42
+ const e = event('1');
43
+
44
+ wrapper.simulate('change', e);
45
+
46
+ expect(onChange).toBeCalledWith(e);
47
+ });
48
+ });
49
+ });
@@ -0,0 +1,51 @@
1
+ import * as React from 'react';
2
+ import { shallow } from 'enzyme';
3
+ import { choice } from '../../__tests__/utils';
4
+ import Dropdown from '../dropdown';
5
+
6
+ describe('Dropdown', () => {
7
+ const onChange = jest.fn();
8
+ const defaultProps = {
9
+ onChange,
10
+ id: '1',
11
+ correct: false,
12
+ disabled: false,
13
+ value: 'Jumped',
14
+ choices: [choice('Jumped'), choice('Laughed'), choice('Smiled')],
15
+ };
16
+ let wrapper;
17
+
18
+ beforeEach(() => {
19
+ wrapper = shallow(<Dropdown {...defaultProps} />);
20
+ });
21
+
22
+ describe('render', () => {
23
+ it('renders correctly with default props', () => {
24
+ expect(wrapper).toMatchSnapshot();
25
+ });
26
+
27
+ it('renders correctly with disabled prop as true', () => {
28
+ wrapper.setProps({ disabled: true });
29
+ expect(wrapper).toMatchSnapshot();
30
+ });
31
+
32
+ it('renders correctly with correct as true', () => {
33
+ wrapper.setProps({ correct: true });
34
+ expect(wrapper).toMatchSnapshot();
35
+ });
36
+ });
37
+
38
+ describe('onChange', () => {
39
+ const event = (value) => ({
40
+ target: { value },
41
+ });
42
+
43
+ it('should be called with an appropriate value', () => {
44
+ const e = event('Laughed');
45
+
46
+ wrapper.simulate('change', e);
47
+
48
+ expect(onChange).toHaveBeenCalledWith({ target: { value: e.target.value } });
49
+ });
50
+ });
51
+ });
@@ -0,0 +1,50 @@
1
+ import * as React from 'react';
2
+ import { shallow } from 'enzyme';
3
+ import Input from '../input';
4
+
5
+ describe('Input', () => {
6
+ const onChange = jest.fn();
7
+ const defaultProps = {
8
+ disabled: false,
9
+ correct: false,
10
+ variant: 'outlined',
11
+ value: 'Cow',
12
+ id: '1',
13
+ onChange,
14
+ };
15
+ let wrapper;
16
+
17
+ beforeEach(() => {
18
+ wrapper = shallow(<Input {...defaultProps} />);
19
+ });
20
+
21
+ describe('render', () => {
22
+ it('renders correctly with default props', () => {
23
+ expect(wrapper).toMatchSnapshot();
24
+ });
25
+
26
+ it('renders correctly with disabled prop as true', () => {
27
+ wrapper.setProps({ disabled: true });
28
+ expect(wrapper).toMatchSnapshot();
29
+ });
30
+
31
+ it('renders correctly with correct as false', () => {
32
+ wrapper.setProps({ correct: false });
33
+ expect(wrapper).toMatchSnapshot();
34
+ });
35
+ });
36
+
37
+ describe('onChange', () => {
38
+ const event = (value) => ({
39
+ target: { value },
40
+ });
41
+
42
+ it('should be called', () => {
43
+ const e = event('20');
44
+
45
+ wrapper.simulate('change', e);
46
+
47
+ expect(onChange).toHaveBeenCalledWith('1', e.target.value);
48
+ });
49
+ });
50
+ });