@pie-lib/mask-markup 1.13.47-next.1 → 1.14.0-beta.2
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 +22 -47
- package/NEXT.CHANGELOG.json +1 -0
- package/package.json +9 -5
- package/src/__tests__/__snapshots__/drag-in-the-blank.test.js.snap +316 -0
- package/src/__tests__/__snapshots__/mask.test.js.snap +55 -0
- package/src/__tests__/__snapshots__/with-mask.test.js.snap +62 -0
- package/src/__tests__/drag-in-the-blank.test.js +71 -0
- package/src/__tests__/index.test.js +39 -0
- package/src/__tests__/mask.test.js +152 -0
- package/src/__tests__/serialization.test.js +54 -0
- package/src/__tests__/utils.js +1 -0
- package/src/__tests__/with-mask.test.js +51 -0
- package/src/choices/__tests__/__snapshots__/index.test.js.snap +209 -0
- package/src/choices/__tests__/index.test.js +62 -0
- package/src/choices/choice.jsx +60 -6
- package/src/choices/index.jsx +2 -2
- package/src/components/__tests__/__snapshots__/blank.test.js.snap +111 -0
- package/src/components/__tests__/__snapshots__/correct-input.test.js.snap +64 -0
- package/src/components/__tests__/__snapshots__/dropdown.test.js.snap +133 -0
- package/src/components/__tests__/__snapshots__/input.test.js.snap +34 -0
- package/src/components/__tests__/blank.test.js +202 -0
- package/src/components/__tests__/correct-input.test.js +49 -0
- package/src/components/__tests__/dropdown.test.js +51 -0
- package/src/components/__tests__/input.test.js +50 -0
- package/src/components/blank.jsx +139 -28
- package/src/components/correct-input.jsx +6 -1
- package/src/components/dropdown.jsx +192 -71
- package/src/constructed-response.jsx +76 -18
- package/src/customizable.jsx +35 -0
- package/src/drag-in-the-blank.jsx +26 -3
- package/src/index.js +10 -1
- package/src/inline-dropdown.jsx +2 -0
- package/src/mask.jsx +30 -5
- package/src/with-mask.jsx +39 -2
- package/README.md +0 -14
- package/lib/choices/choice.js +0 -158
- package/lib/choices/choice.js.map +0 -1
- package/lib/choices/index.js +0 -127
- package/lib/choices/index.js.map +0 -1
- package/lib/componentize.js +0 -25
- package/lib/componentize.js.map +0 -1
- package/lib/components/blank.js +0 -303
- package/lib/components/blank.js.map +0 -1
- package/lib/components/correct-input.js +0 -113
- package/lib/components/correct-input.js.map +0 -1
- package/lib/components/dropdown.js +0 -216
- package/lib/components/dropdown.js.map +0 -1
- package/lib/components/input.js +0 -57
- package/lib/components/input.js.map +0 -1
- package/lib/constructed-response.js +0 -52
- package/lib/constructed-response.js.map +0 -1
- package/lib/drag-in-the-blank.js +0 -191
- package/lib/drag-in-the-blank.js.map +0 -1
- package/lib/index.js +0 -54
- package/lib/index.js.map +0 -1
- package/lib/inline-dropdown.js +0 -46
- package/lib/inline-dropdown.js.map +0 -1
- package/lib/mask.js +0 -215
- package/lib/mask.js.map +0 -1
- package/lib/serialization.js +0 -207
- package/lib/serialization.js.map +0 -1
- package/lib/with-mask.js +0 -93
- package/lib/with-mask.js.map +0 -1
package/src/choices/choice.jsx
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import ReactDOM from 'react-dom';
|
|
2
3
|
import PropTypes from 'prop-types';
|
|
3
|
-
import { DragSource } from '@pie-lib/drag';
|
|
4
4
|
import { withStyles } from '@material-ui/core/styles';
|
|
5
5
|
import Chip from '@material-ui/core/Chip';
|
|
6
6
|
import classnames from 'classnames';
|
|
7
|
-
|
|
7
|
+
|
|
8
8
|
import { renderMath } from '@pie-lib/math-rendering';
|
|
9
9
|
import { color } from '@pie-lib/render-ui';
|
|
10
|
+
import { DragSource } from '@pie-lib/drag';
|
|
10
11
|
|
|
11
12
|
export const DRAG_TYPE = 'MaskBlank';
|
|
12
13
|
|
|
@@ -18,6 +19,45 @@ class BlankContentComp extends React.Component {
|
|
|
18
19
|
connectDragSource: PropTypes.func,
|
|
19
20
|
};
|
|
20
21
|
|
|
22
|
+
startDrag = () => {
|
|
23
|
+
const { connectDragSource, disabled } = this.props;
|
|
24
|
+
if (!disabled) {
|
|
25
|
+
connectDragSource(this.dragContainerRef);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// start drag after 500ms (touch and hold duration) for chromebooks and other touch devices PD-4888
|
|
30
|
+
handleTouchStart = (e) => {
|
|
31
|
+
e.preventDefault();
|
|
32
|
+
this.longPressTimer = setTimeout(() => {
|
|
33
|
+
this.startDrag(e);
|
|
34
|
+
}, 500);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
handleTouchEnd = () => {
|
|
38
|
+
clearTimeout(this.longPressTimer);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
handleTouchMove = () => {
|
|
42
|
+
clearTimeout(this.longPressTimer);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
componentDidMount() {
|
|
46
|
+
if (this.dragContainerRef) {
|
|
47
|
+
this.dragContainerRef.addEventListener('touchstart', this.handleTouchStart, { passive: false });
|
|
48
|
+
this.dragContainerRef.addEventListener('touchend', this.handleTouchEnd);
|
|
49
|
+
this.dragContainerRef.addEventListener('touchmove', this.handleTouchMove);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
componentWillUnmount() {
|
|
54
|
+
if (this.dragContainerRef) {
|
|
55
|
+
this.dragContainerRef.removeEventListener('touchstart', this.handleTouchStart);
|
|
56
|
+
this.dragContainerRef.removeEventListener('touchend', this.handleTouchEnd);
|
|
57
|
+
this.dragContainerRef.removeEventListener('touchmove', this.handleTouchMove);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
21
61
|
componentDidUpdate() {
|
|
22
62
|
renderMath(this.rootRef);
|
|
23
63
|
}
|
|
@@ -28,7 +68,13 @@ class BlankContentComp extends React.Component {
|
|
|
28
68
|
// TODO the Chip element is causing drag problems on touch devices. Avoid using Chip and consider refactoring the code. Keep in mind that Chip is a span with a button role, which interferes with seamless touch device dragging.
|
|
29
69
|
|
|
30
70
|
return connectDragSource(
|
|
31
|
-
<span
|
|
71
|
+
<span
|
|
72
|
+
className={classnames(classes.choice, disabled && classes.disabled)}
|
|
73
|
+
ref={(ref) => {
|
|
74
|
+
//eslint-disable-next-line
|
|
75
|
+
this.dragContainerRef = ReactDOM.findDOMNode(ref);
|
|
76
|
+
}}
|
|
77
|
+
>
|
|
32
78
|
<Chip
|
|
33
79
|
clickable={false}
|
|
34
80
|
disabled={true}
|
|
@@ -65,7 +111,7 @@ export const BlankContent = withStyles((theme) => ({
|
|
|
65
111
|
transform: 'translate(0, 0)',
|
|
66
112
|
},
|
|
67
113
|
chip: {
|
|
68
|
-
backgroundColor: color.
|
|
114
|
+
backgroundColor: color.white(),
|
|
69
115
|
border: `1px solid ${color.text()}`,
|
|
70
116
|
color: color.text(),
|
|
71
117
|
alignItems: 'center',
|
|
@@ -79,15 +125,23 @@ export const BlankContent = withStyles((theme) => ({
|
|
|
79
125
|
// This will prevent the context menu from appearing and not allowing other interactions with the image.
|
|
80
126
|
// If interactions with the image in the token will be requested we should handle only the context Menu.
|
|
81
127
|
pointerEvents: 'none',
|
|
128
|
+
borderRadius: '3px',
|
|
129
|
+
paddingTop: '12px',
|
|
130
|
+
paddingBottom: '12px',
|
|
82
131
|
},
|
|
83
132
|
chipLabel: {
|
|
84
|
-
whiteSpace: '
|
|
133
|
+
whiteSpace: 'normal',
|
|
85
134
|
'& img': {
|
|
86
135
|
display: 'block',
|
|
87
136
|
padding: '2px 0',
|
|
88
137
|
},
|
|
138
|
+
'& mjx-frac': {
|
|
139
|
+
fontSize: '120% !important',
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
disabled: {
|
|
143
|
+
opacity: 0.6,
|
|
89
144
|
},
|
|
90
|
-
disabled: {},
|
|
91
145
|
}))(BlankContentComp);
|
|
92
146
|
|
|
93
147
|
const tileSource = {
|
package/src/choices/index.jsx
CHANGED
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import findKey from 'lodash/findKey';
|
|
4
4
|
import Choice from './choice';
|
|
5
|
-
import DragDroppablePlaceholder from '@pie-lib/drag
|
|
5
|
+
import { DragDroppablePlaceholder } from '@pie-lib/drag';
|
|
6
6
|
|
|
7
7
|
export default class Choices extends React.Component {
|
|
8
8
|
static propTypes = {
|
|
@@ -48,7 +48,7 @@ export default class Choices extends React.Component {
|
|
|
48
48
|
const foundChoice = findKey(value, (v) => v === c.id);
|
|
49
49
|
return foundChoice === undefined;
|
|
50
50
|
});
|
|
51
|
-
const elementStyle = this.getStyleForWrapper();
|
|
51
|
+
const elementStyle = { ...this.getStyleForWrapper(), minWidth: '100px' };
|
|
52
52
|
|
|
53
53
|
return (
|
|
54
54
|
<div style={elementStyle}>
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`Blank render renders correctly with default props 1`] = `
|
|
4
|
+
<WithStyles(Chip)
|
|
5
|
+
className="undefined"
|
|
6
|
+
clickable={false}
|
|
7
|
+
component="span"
|
|
8
|
+
disabled={true}
|
|
9
|
+
label={
|
|
10
|
+
<React.Fragment>
|
|
11
|
+
<span
|
|
12
|
+
className=""
|
|
13
|
+
>
|
|
14
|
+
|
|
15
|
+
</span>
|
|
16
|
+
</React.Fragment>
|
|
17
|
+
}
|
|
18
|
+
style={
|
|
19
|
+
Object {
|
|
20
|
+
"height": 0,
|
|
21
|
+
"minHeight": 32,
|
|
22
|
+
"minWidth": 90,
|
|
23
|
+
"width": 0,
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/>
|
|
27
|
+
`;
|
|
28
|
+
|
|
29
|
+
exports[`Blank render renders correctly with disabled prop as true 1`] = `
|
|
30
|
+
<WithStyles(Chip)
|
|
31
|
+
className="undefined"
|
|
32
|
+
clickable={false}
|
|
33
|
+
component="span"
|
|
34
|
+
disabled={true}
|
|
35
|
+
label={
|
|
36
|
+
<React.Fragment>
|
|
37
|
+
<span
|
|
38
|
+
className=""
|
|
39
|
+
>
|
|
40
|
+
|
|
41
|
+
</span>
|
|
42
|
+
</React.Fragment>
|
|
43
|
+
}
|
|
44
|
+
style={
|
|
45
|
+
Object {
|
|
46
|
+
"height": 0,
|
|
47
|
+
"minHeight": 32,
|
|
48
|
+
"minWidth": 90,
|
|
49
|
+
"width": 0,
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
variant="outlined"
|
|
53
|
+
/>
|
|
54
|
+
`;
|
|
55
|
+
|
|
56
|
+
exports[`Blank render renders correctly with draggedItem 1`] = `
|
|
57
|
+
<WithStyles(Chip)
|
|
58
|
+
className="undefined"
|
|
59
|
+
clickable={false}
|
|
60
|
+
component="span"
|
|
61
|
+
disabled={true}
|
|
62
|
+
label={
|
|
63
|
+
<React.Fragment>
|
|
64
|
+
<span
|
|
65
|
+
className=""
|
|
66
|
+
>
|
|
67
|
+
|
|
68
|
+
</span>
|
|
69
|
+
</React.Fragment>
|
|
70
|
+
}
|
|
71
|
+
style={
|
|
72
|
+
Object {
|
|
73
|
+
"height": 0,
|
|
74
|
+
"minHeight": 32,
|
|
75
|
+
"minWidth": 90,
|
|
76
|
+
"width": 0,
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/>
|
|
80
|
+
`;
|
|
81
|
+
|
|
82
|
+
exports[`Blank render renders correctly with draggedItem and isOver 1`] = `
|
|
83
|
+
<WithStyles(Chip)
|
|
84
|
+
className="undefined"
|
|
85
|
+
clickable={false}
|
|
86
|
+
component="span"
|
|
87
|
+
disabled={true}
|
|
88
|
+
label={
|
|
89
|
+
<React.Fragment>
|
|
90
|
+
<span
|
|
91
|
+
className="undefined"
|
|
92
|
+
>
|
|
93
|
+
|
|
94
|
+
</span>
|
|
95
|
+
<span
|
|
96
|
+
className=""
|
|
97
|
+
>
|
|
98
|
+
|
|
99
|
+
</span>
|
|
100
|
+
</React.Fragment>
|
|
101
|
+
}
|
|
102
|
+
style={
|
|
103
|
+
Object {
|
|
104
|
+
"height": 0,
|
|
105
|
+
"minHeight": 32,
|
|
106
|
+
"minWidth": 90,
|
|
107
|
+
"width": 0,
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/>
|
|
111
|
+
`;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`CorrectInput render renders correctly with correct as false 1`] = `
|
|
4
|
+
<Component
|
|
5
|
+
classes={
|
|
6
|
+
Object {
|
|
7
|
+
"box": "Component-box-5",
|
|
8
|
+
"correct": "Component-correct-3",
|
|
9
|
+
"crInput": "Component-crInput-2",
|
|
10
|
+
"incorrect": "Component-incorrect-4",
|
|
11
|
+
"input": "Component-input-1",
|
|
12
|
+
"notchedOutline": "Component-notchedOutline-7",
|
|
13
|
+
"outlinedInput": "Component-outlinedInput-6",
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
correct={false}
|
|
17
|
+
disabled={false}
|
|
18
|
+
onChange={[MockFunction]}
|
|
19
|
+
value="Cow"
|
|
20
|
+
variant="outlined"
|
|
21
|
+
/>
|
|
22
|
+
`;
|
|
23
|
+
|
|
24
|
+
exports[`CorrectInput render renders correctly with default props 1`] = `
|
|
25
|
+
<Component
|
|
26
|
+
classes={
|
|
27
|
+
Object {
|
|
28
|
+
"box": "Component-box-5",
|
|
29
|
+
"correct": "Component-correct-3",
|
|
30
|
+
"crInput": "Component-crInput-2",
|
|
31
|
+
"incorrect": "Component-incorrect-4",
|
|
32
|
+
"input": "Component-input-1",
|
|
33
|
+
"notchedOutline": "Component-notchedOutline-7",
|
|
34
|
+
"outlinedInput": "Component-outlinedInput-6",
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
correct={false}
|
|
38
|
+
disabled={false}
|
|
39
|
+
onChange={[MockFunction]}
|
|
40
|
+
value="Cow"
|
|
41
|
+
variant="outlined"
|
|
42
|
+
/>
|
|
43
|
+
`;
|
|
44
|
+
|
|
45
|
+
exports[`CorrectInput render renders correctly with disabled prop as true 1`] = `
|
|
46
|
+
<Component
|
|
47
|
+
classes={
|
|
48
|
+
Object {
|
|
49
|
+
"box": "Component-box-5",
|
|
50
|
+
"correct": "Component-correct-3",
|
|
51
|
+
"crInput": "Component-crInput-2",
|
|
52
|
+
"incorrect": "Component-incorrect-4",
|
|
53
|
+
"input": "Component-input-1",
|
|
54
|
+
"notchedOutline": "Component-notchedOutline-7",
|
|
55
|
+
"outlinedInput": "Component-outlinedInput-6",
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
correct={false}
|
|
59
|
+
disabled={true}
|
|
60
|
+
onChange={[MockFunction]}
|
|
61
|
+
value="Cow"
|
|
62
|
+
variant="outlined"
|
|
63
|
+
/>
|
|
64
|
+
`;
|
|
@@ -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
|
+
});
|