@pie-element/hotspot 5.4.3-next.5 → 5.4.3-next.57
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/configure/lib/button.js.map +1 -1
- package/configure/lib/defaults.js.map +1 -1
- package/configure/lib/hotspot-container.js.map +1 -1
- package/configure/lib/hotspot-drawable.js.map +1 -1
- package/configure/lib/hotspot-palette.js.map +1 -1
- package/configure/lib/hotspot-polygon.js.map +1 -1
- package/configure/lib/hotspot-rectangle.js.map +1 -1
- package/configure/lib/index.js.map +1 -1
- package/configure/lib/root.js +1 -1
- package/configure/lib/root.js.map +1 -1
- package/configure/lib/upload-control.js.map +1 -1
- package/configure/lib/utils.js.map +1 -1
- package/configure/package.json +2 -2
- package/configure/src/__tests__/hotspot-container.test.js +98 -71
- package/configure/src/__tests__/hotspot-drawable.test.js +48 -49
- package/configure/src/__tests__/index.test.js +28 -51
- package/configure/src/__tests__/root.test.js +162 -82
- package/configure/src/__tests__/utils.test.js +112 -98
- package/configure/src/button.jsx +4 -4
- package/configure/src/defaults.js +16 -20
- package/configure/src/hotspot-container.jsx +72 -89
- package/configure/src/hotspot-drawable.jsx +55 -55
- package/configure/src/hotspot-palette.jsx +12 -25
- package/configure/src/hotspot-polygon.jsx +20 -22
- package/configure/src/hotspot-rectangle.jsx +5 -15
- package/configure/src/index.js +20 -20
- package/configure/src/root.jsx +38 -67
- package/configure/src/upload-control.jsx +9 -20
- package/configure/src/utils.js +35 -28
- package/controller/lib/defaults.js.map +1 -1
- package/controller/lib/index.js.map +1 -1
- package/controller/lib/utils.js.map +1 -1
- package/controller/package.json +1 -1
- package/controller/src/__tests__/index.test.js +29 -50
- package/controller/src/defaults.js +4 -8
- package/controller/src/index.js +22 -34
- package/controller/src/utils.js +9 -6
- package/docs/config-schema.json.md +1 -1
- package/docs/demo/config.js +2 -2
- package/docs/demo/generate.js +49 -37
- package/docs/demo/session.js +2 -2
- package/docs/pie-schema.json.md +1 -1
- package/lib/hotspot/container.js.map +1 -1
- package/lib/hotspot/icons.js.map +1 -1
- package/lib/hotspot/image.js.map +1 -1
- package/lib/hotspot/index.js.map +1 -1
- package/lib/hotspot/polygon.js.map +1 -1
- package/lib/hotspot/rectangle.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/session-updater.js.map +1 -1
- package/package.json +6 -6
- package/src/__tests__/container.test.jsx +57 -43
- package/src/__tests__/image.test.jsx +2 -2
- package/src/__tests__/polygon.test.jsx +31 -20
- package/src/__tests__/rectangle.test.jsx +22 -18
- package/src/__tests__/session-updater.test.jsx +22 -31
- package/src/hotspot/container.jsx +20 -23
- package/src/hotspot/icons.js +4 -2
- package/src/hotspot/image.jsx +4 -8
- package/src/hotspot/index.jsx +27 -47
- package/src/hotspot/polygon.jsx +13 -18
- package/src/hotspot/rectangle.jsx +11 -16
- package/src/index.js +5 -18
- package/src/session-updater.js +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils.js"],"names":["updateImageDimensions","initialDim","nextDim","keepAspectRatio","resizeType","imageAspectRatio","width","height","getDelta","referenceInitialValue","referenceNextValue","currentValue","getUpdatedRectangle","shape","x","y","getUpdatedPlygon","points","map","point","getUpdatedShapes","shapes","group","getAllShapes","shapesMap","shapesArray","shapesKeys","Object","keys","length","reduce","acc","currentShapeKey","concat","index","groupShapes","rectangles","polygons","shapeProps","generateValidationMessage","config","minShapes","maxShapes","maxSelections","shapesMessage","selectionsMessage","message"],"mappings":";;;;;;;;;;;;;;;AAAA;;;;;;;;AAEA,IAAMA,qBAAqB,GAAG,SAAxBA,qBAAwB,CAACC,UAAD,EAAaC,OAAb,EAAsBC,eAAtB,EAAuCC,UAAvC,EAAsD;AAClF;AACA,MAAID,eAAJ,EAAqB;AACnB,QAAME,gBAAgB,GAAGJ,UAAU,CAACK,KAAX,GAAmBL,UAAU,CAACM,MAAvD;;AAEA,QAAIH,UAAU,KAAK,QAAnB,EAA6B;AAC3B;AACA,aAAO;AACLE,QAAAA,KAAK,EAAEJ,OAAO,CAACK,MAAR,GAAiBF,gBADnB;AAELE,QAAAA,MAAM,EAAEL,OAAO,CAACK;AAFX,OAAP;AAID,KATkB,CAWnB;;;AACA,WAAO;AACLD,MAAAA,KAAK,EAAEJ,OAAO,CAACI,KADV;AAELC,MAAAA,MAAM,EAAEL,OAAO,CAACI,KAAR,GAAgBD;AAFnB,KAAP;AAID,GAlBiF,CAoBlF;;;AACA,SAAO;AACLC,IAAAA,KAAK,EAAEJ,OAAO,CAACI,KADV;AAELC,IAAAA,MAAM,EAAEL,OAAO,CAACK;AAFX,GAAP;AAID,CAzBD,C,CA2BA;AACA;AACA;;;;;AACA,IAAMC,QAAQ,GAAG,SAAXA,QAAW,CAACC,qBAAD,EAAwBC,kBAAxB,EAA4CC,YAA5C;AAAA,
|
|
1
|
+
{"version":3,"sources":["../src/utils.js"],"names":["updateImageDimensions","initialDim","nextDim","keepAspectRatio","resizeType","imageAspectRatio","width","height","getDelta","referenceInitialValue","referenceNextValue","currentValue","getUpdatedRectangle","shape","x","y","getUpdatedPlygon","points","map","point","getUpdatedShapes","shapes","group","getAllShapes","shapesMap","shapesArray","shapesKeys","Object","keys","length","reduce","acc","currentShapeKey","concat","index","groupShapes","rectangles","polygons","shapeProps","generateValidationMessage","config","minShapes","maxShapes","maxSelections","shapesMessage","selectionsMessage","message"],"mappings":";;;;;;;;;;;;;;;AAAA;;;;;;;;AAEA,IAAMA,qBAAqB,GAAG,SAAxBA,qBAAwB,CAACC,UAAD,EAAaC,OAAb,EAAsBC,eAAtB,EAAuCC,UAAvC,EAAsD;AAClF;AACA,MAAID,eAAJ,EAAqB;AACnB,QAAME,gBAAgB,GAAGJ,UAAU,CAACK,KAAX,GAAmBL,UAAU,CAACM,MAAvD;;AAEA,QAAIH,UAAU,KAAK,QAAnB,EAA6B;AAC3B;AACA,aAAO;AACLE,QAAAA,KAAK,EAAEJ,OAAO,CAACK,MAAR,GAAiBF,gBADnB;AAELE,QAAAA,M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mCACCF,aAAa,yBAAkBA,aAAlB,SAAqC,EADnD,IAEA,OAFA,IAGCA,aAAa,GAAG,GAAH,GAAS,EAHvB,IAIA,YALF;AAOA,MAAMG,OAAO,GAAG,6BAA6BF,aAA7B,GAA6CC,iBAA7D;AAEA,SAAOC,OAAP;AACD,CAhBD","sourcesContent":["import cloneDeep from 'lodash/cloneDeep';\n\nconst updateImageDimensions = (initialDim, nextDim, keepAspectRatio, resizeType) => {\n // if we want to keep image aspect ratio\n if (keepAspectRatio) {\n const imageAspectRatio = initialDim.width / initialDim.height;\n\n if (resizeType === 'height') {\n // if we want to change image height => we update the width accordingly\n return {\n width: nextDim.height * imageAspectRatio,\n height: nextDim.height,\n };\n }\n\n // if we want to change image width => we update the height accordingly\n return {\n width: nextDim.width,\n height: nextDim.width / imageAspectRatio,\n };\n }\n\n // if we don't want to keep aspect ratio, we just update both values\n return {\n width: nextDim.width,\n height: nextDim.height,\n };\n};\n\n// referenceInitialValue = the initial value of the Stage\n// referenceNextValue = the next value of the Stage\n// currentValue = the value that has to be re-sized influenced by the changes that were made on the Stage\nconst getDelta = (referenceInitialValue, referenceNextValue, currentValue) =>\n (referenceNextValue / referenceInitialValue) * currentValue;\n\nconst getUpdatedRectangle = (initialDim, nextDim, shape) => ({\n ...shape,\n width: getDelta(initialDim.width, nextDim.width, shape.width),\n height: getDelta(initialDim.height, nextDim.height, shape.height),\n x: getDelta(initialDim.width, nextDim.width, shape.x),\n y: getDelta(initialDim.height, nextDim.height, shape.y),\n});\n\nconst getUpdatedPlygon = (initialDim, nextDim, shape) => ({\n ...shape,\n points: shape.points.map((point) => ({\n x: getDelta(initialDim.width, nextDim.width, point.x),\n y: getDelta(initialDim.height, nextDim.height, point.y),\n })),\n});\n\n// initialDim = the initial dimensions: { width, height } of the Stage\n// nextDim = the next dimensions: { width, height } of the Stage\n// shapes = array of shapes that have to be re-sized and re-positioned\nconst getUpdatedShapes = (initialDim, nextDim, shapes) => {\n return shapes.map((shape) => {\n if (shape.group === 'rectangles') {\n return getUpdatedRectangle(initialDim, nextDim, shape);\n }\n\n if (shape.group === 'polygons') {\n return getUpdatedPlygon(initialDim, nextDim, shape);\n }\n });\n};\n\n// converts shapes map to shapes array\n// example:\n// from: { rectangles: [r1], polygons: [p1, p2]}\n// to: [{ ...r1, group: 'rectangles' }, { ...p1, group: 'polygons' }, { ...p2, group: 'polygons' }]\n// if a shape has index defined, keep it, otherwise initialize it\n// index is used for the UNDO function\nconst getAllShapes = (shapesMap) => {\n shapesMap = shapesMap || {};\n const shapesArray = [];\n const shapesKeys = Object.keys(shapesMap);\n\n return shapesKeys.length\n ? shapesKeys.reduce(\n (acc, currentShapeKey) =>\n acc.concat(\n shapesMap[currentShapeKey]\n ? shapesMap[currentShapeKey].map((shape, index) => ({\n ...shape,\n group: currentShapeKey,\n index: shape.index || acc.length + index,\n }))\n : [],\n ),\n shapesArray,\n )\n : shapesArray;\n};\n\n// converts shapes array to shapes map\n// is the reverse of getAllShapes function\n// example:\n// from: [{ ...r1, group: 'rectangles' }, { ...p1, group: 'polygons' }, { ...p2, group: 'polygons' }]\n// to: { rectangles: [r1], polygons: [p1, p2]}\nconst groupShapes = (shapesArray) => {\n shapesArray = shapesArray || [];\n const shapesMap = {\n rectangles: [],\n polygons: [],\n };\n\n if (shapesArray.length) {\n return shapesArray.reduce((acc, { group, ...shapeProps }) => {\n acc[group] = [...(acc[group] || []), shapeProps];\n return acc;\n }, shapesMap);\n }\n\n return cloneDeep(shapesMap);\n};\n\nconst generateValidationMessage = (config) => {\n const { minShapes, maxShapes, maxSelections } = config;\n\n const shapesMessage =\n `\\nThere should be at least ${minShapes} ` + (maxShapes ? `and at most ${maxShapes} ` : '') + 'shapes defined.';\n\n const selectionsMessage =\n `\\nThere should be at least 1 ` +\n (maxSelections ? `and at most ${maxSelections} ` : '') +\n 'shape' +\n (maxSelections ? 's' : '') +\n ' selected.';\n\n const message = 'Validation requirements:' + shapesMessage + selectionsMessage;\n\n return message;\n};\n\nexport {\n updateImageDimensions,\n generateValidationMessage,\n getUpdatedShapes,\n getAllShapes,\n groupShapes,\n getUpdatedRectangle,\n getUpdatedPlygon,\n};\n"],"file":"utils.js"}
|
package/configure/package.json
CHANGED
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"@material-ui/core": "^3.9.2",
|
|
11
11
|
"@material-ui/icons": "^3.0.2",
|
|
12
12
|
"@pie-framework/pie-configure-events": "^1.3.0",
|
|
13
|
-
"@pie-lib/config-ui": "^11.0.
|
|
14
|
-
"@pie-lib/editable-html": "^9.2.
|
|
13
|
+
"@pie-lib/config-ui": "^11.0.26",
|
|
14
|
+
"@pie-lib/editable-html": "^9.2.8",
|
|
15
15
|
"classnames": "^2.2.6",
|
|
16
16
|
"debug": "^3.1.0",
|
|
17
17
|
"konva": "^3.2.4",
|
|
@@ -5,50 +5,73 @@ import { getAllShapes, groupShapes } from '../utils';
|
|
|
5
5
|
|
|
6
6
|
const model = () => ({
|
|
7
7
|
imageUrl: 'https://cdn.fluence.net/image/0240eb1455ce4c4bb6180232347b6aef_W',
|
|
8
|
-
shapes: groupShapes(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
8
|
+
shapes: groupShapes(
|
|
9
|
+
getAllShapes({
|
|
10
|
+
rectangles: [
|
|
11
|
+
{
|
|
12
|
+
id: '0',
|
|
13
|
+
height: 140,
|
|
14
|
+
width: 130,
|
|
15
|
+
x: 1,
|
|
16
|
+
y: 1,
|
|
17
|
+
correct: true,
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
id: '1',
|
|
21
|
+
height: 140,
|
|
22
|
+
width: 130,
|
|
23
|
+
x: 140,
|
|
24
|
+
y: 1,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
id: '2',
|
|
28
|
+
height: 140,
|
|
29
|
+
width: 130,
|
|
30
|
+
x: 280,
|
|
31
|
+
y: 1,
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
polygons: [
|
|
35
|
+
{
|
|
36
|
+
id: '3',
|
|
37
|
+
points: [
|
|
38
|
+
{ x: 1, y: 148 },
|
|
39
|
+
{ x: 1, y: 288 },
|
|
40
|
+
{ y: 288, x: 129 },
|
|
41
|
+
{ y: 148, x: 129 },
|
|
42
|
+
],
|
|
43
|
+
correct: true,
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
id: '4',
|
|
47
|
+
points: [
|
|
48
|
+
{ y: 151, x: 141 },
|
|
49
|
+
{ y: 289, x: 141 },
|
|
50
|
+
{ y: 289, x: 269 },
|
|
51
|
+
{ x: 269, y: 151 },
|
|
52
|
+
],
|
|
53
|
+
correct: false,
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
id: '5',
|
|
57
|
+
points: [
|
|
58
|
+
{ x: 279, y: 150 },
|
|
59
|
+
{ x: 279, y: 289 },
|
|
60
|
+
{ x: 407, y: 289 },
|
|
61
|
+
{ x: 407, y: 150 },
|
|
62
|
+
],
|
|
63
|
+
correct: false,
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
}),
|
|
67
|
+
),
|
|
46
68
|
dimensions: {
|
|
47
|
-
height: 291,
|
|
69
|
+
height: 291,
|
|
70
|
+
width: 410,
|
|
48
71
|
},
|
|
49
72
|
hotspotColor: 'rgba(137, 183, 244, 0.65)',
|
|
50
73
|
outlineColor: 'blue',
|
|
51
|
-
multipleCorrect: true
|
|
74
|
+
multipleCorrect: true,
|
|
52
75
|
});
|
|
53
76
|
|
|
54
77
|
describe('HotspotContainer', () => {
|
|
@@ -56,11 +79,9 @@ describe('HotspotContainer', () => {
|
|
|
56
79
|
onImageUpload = jest.fn(),
|
|
57
80
|
onUpdateImageDimension = jest.fn(),
|
|
58
81
|
onUpdateShapes = jest.fn(),
|
|
59
|
-
initialModel = model()
|
|
60
|
-
;
|
|
61
|
-
|
|
82
|
+
initialModel = model();
|
|
62
83
|
beforeEach(() => {
|
|
63
|
-
w = extras => {
|
|
84
|
+
w = (extras) => {
|
|
64
85
|
const props = {
|
|
65
86
|
classes: {},
|
|
66
87
|
dimensions: initialModel.dimensions,
|
|
@@ -72,17 +93,17 @@ describe('HotspotContainer', () => {
|
|
|
72
93
|
onUpdateShapes: onUpdateShapes,
|
|
73
94
|
onImageUpload: onImageUpload,
|
|
74
95
|
shapes: initialModel.shapes,
|
|
75
|
-
...extras
|
|
96
|
+
...extras,
|
|
76
97
|
};
|
|
77
98
|
|
|
78
99
|
return shallow(<Container {...props} />);
|
|
79
|
-
}
|
|
100
|
+
};
|
|
80
101
|
});
|
|
81
102
|
|
|
82
103
|
describe('render', () => {
|
|
83
104
|
it('renders', () => {
|
|
84
105
|
expect(w()).toMatchSnapshot();
|
|
85
|
-
})
|
|
106
|
+
});
|
|
86
107
|
});
|
|
87
108
|
|
|
88
109
|
describe('logic', () => {
|
|
@@ -96,23 +117,25 @@ describe('HotspotContainer', () => {
|
|
|
96
117
|
y: 1,
|
|
97
118
|
correct: true,
|
|
98
119
|
group: 'rectangles',
|
|
99
|
-
index: 0
|
|
100
|
-
},
|
|
120
|
+
index: 0,
|
|
121
|
+
},
|
|
122
|
+
{
|
|
101
123
|
id: '1',
|
|
102
124
|
height: 140,
|
|
103
125
|
width: 130,
|
|
104
126
|
x: 140,
|
|
105
127
|
y: 1,
|
|
106
128
|
group: 'rectangles',
|
|
107
|
-
index: 1
|
|
108
|
-
},
|
|
129
|
+
index: 1,
|
|
130
|
+
},
|
|
131
|
+
{
|
|
109
132
|
id: '2',
|
|
110
133
|
height: 140,
|
|
111
134
|
width: 130,
|
|
112
135
|
x: 280,
|
|
113
136
|
y: 1,
|
|
114
137
|
group: 'rectangles',
|
|
115
|
-
index: 2
|
|
138
|
+
index: 2,
|
|
116
139
|
},
|
|
117
140
|
{
|
|
118
141
|
id: '3',
|
|
@@ -120,32 +143,36 @@ describe('HotspotContainer', () => {
|
|
|
120
143
|
{ x: 1, y: 148 },
|
|
121
144
|
{ x: 1, y: 288 },
|
|
122
145
|
{ y: 288, x: 129 },
|
|
123
|
-
{ y: 148, x: 129 }
|
|
146
|
+
{ y: 148, x: 129 },
|
|
147
|
+
],
|
|
124
148
|
correct: true,
|
|
125
149
|
group: 'polygons',
|
|
126
|
-
index: 3
|
|
127
|
-
},
|
|
150
|
+
index: 3,
|
|
151
|
+
},
|
|
152
|
+
{
|
|
128
153
|
id: '4',
|
|
129
154
|
points: [
|
|
130
155
|
{ y: 151, x: 141 },
|
|
131
156
|
{ y: 289, x: 141 },
|
|
132
157
|
{ y: 289, x: 269 },
|
|
133
|
-
{ x: 269, y: 151 }
|
|
158
|
+
{ x: 269, y: 151 },
|
|
159
|
+
],
|
|
134
160
|
correct: false,
|
|
135
161
|
group: 'polygons',
|
|
136
|
-
index: 4
|
|
137
|
-
},
|
|
162
|
+
index: 4,
|
|
163
|
+
},
|
|
164
|
+
{
|
|
138
165
|
id: '5',
|
|
139
166
|
points: [
|
|
140
167
|
{ x: 279, y: 150 },
|
|
141
168
|
{ x: 279, y: 289 },
|
|
142
169
|
{ x: 407, y: 289 },
|
|
143
|
-
{ x: 407, y: 150 }
|
|
170
|
+
{ x: 407, y: 150 },
|
|
144
171
|
],
|
|
145
172
|
correct: false,
|
|
146
173
|
group: 'polygons',
|
|
147
|
-
index: 5
|
|
148
|
-
}
|
|
174
|
+
index: 5,
|
|
175
|
+
},
|
|
149
176
|
];
|
|
150
177
|
|
|
151
178
|
beforeEach(() => {
|
|
@@ -163,7 +190,7 @@ describe('HotspotContainer', () => {
|
|
|
163
190
|
width: 130,
|
|
164
191
|
x: 280,
|
|
165
192
|
y: 1,
|
|
166
|
-
group: 'rectangles'
|
|
193
|
+
group: 'rectangles',
|
|
167
194
|
};
|
|
168
195
|
|
|
169
196
|
wrapper.instance().onUpdateShapes([...formattedShapes, newShape]);
|
|
@@ -177,10 +204,10 @@ describe('HotspotContainer', () => {
|
|
|
177
204
|
width: 130,
|
|
178
205
|
x: 280,
|
|
179
206
|
y: 1,
|
|
180
|
-
}
|
|
207
|
+
},
|
|
181
208
|
],
|
|
182
|
-
polygons: initialModel.shapes.polygons
|
|
183
|
-
})
|
|
209
|
+
polygons: initialModel.shapes.polygons,
|
|
210
|
+
});
|
|
184
211
|
});
|
|
185
212
|
|
|
186
213
|
it('onUpdateShapes with no shapes', () => {
|
|
@@ -188,15 +215,15 @@ describe('HotspotContainer', () => {
|
|
|
188
215
|
|
|
189
216
|
expect(onUpdateShapes).toHaveBeenLastCalledWith({
|
|
190
217
|
rectangles: [],
|
|
191
|
-
polygons: []
|
|
192
|
-
})
|
|
218
|
+
polygons: [],
|
|
219
|
+
});
|
|
193
220
|
});
|
|
194
221
|
|
|
195
222
|
it('handleUndo if no new shape was added', () => {
|
|
196
223
|
wrapper.instance().handleUndo();
|
|
197
224
|
expect(onUpdateShapes).toHaveBeenLastCalledWith({
|
|
198
225
|
...initialModel.shapes,
|
|
199
|
-
polygons: initialModel.shapes.polygons.slice(0, -1)
|
|
226
|
+
polygons: initialModel.shapes.polygons.slice(0, -1),
|
|
200
227
|
});
|
|
201
228
|
});
|
|
202
229
|
|
|
@@ -207,13 +234,13 @@ describe('HotspotContainer', () => {
|
|
|
207
234
|
width: 130,
|
|
208
235
|
x: 280,
|
|
209
236
|
y: 1,
|
|
210
|
-
index: 6
|
|
237
|
+
index: 6,
|
|
211
238
|
};
|
|
212
239
|
|
|
213
240
|
// first, add a new shape
|
|
214
241
|
wrapper.instance().state.shapes = getAllShapes({
|
|
215
242
|
...initialModel.shapes,
|
|
216
|
-
rectangles: [
|
|
243
|
+
rectangles: [...initialModel.shapes.rectangles, newShape],
|
|
217
244
|
});
|
|
218
245
|
wrapper.instance().handleUndo();
|
|
219
246
|
expect(onUpdateShapes).toBeCalledWith(initialModel.shapes);
|
|
@@ -223,7 +250,7 @@ describe('HotspotContainer', () => {
|
|
|
223
250
|
wrapper.instance().handleClearAll();
|
|
224
251
|
expect(onUpdateShapes).toHaveBeenLastCalledWith({
|
|
225
252
|
rectangles: [],
|
|
226
|
-
polygons: []
|
|
253
|
+
polygons: [],
|
|
227
254
|
});
|
|
228
255
|
});
|
|
229
256
|
});
|
|
@@ -12,21 +12,23 @@ const model = () => ({
|
|
|
12
12
|
x: 1,
|
|
13
13
|
y: 1,
|
|
14
14
|
correct: true,
|
|
15
|
-
group: 'rectangles'
|
|
16
|
-
},
|
|
15
|
+
group: 'rectangles',
|
|
16
|
+
},
|
|
17
|
+
{
|
|
17
18
|
id: '1',
|
|
18
19
|
height: 140,
|
|
19
20
|
width: 130,
|
|
20
21
|
x: 140,
|
|
21
22
|
y: 1,
|
|
22
|
-
group: 'rectangles'
|
|
23
|
-
},
|
|
23
|
+
group: 'rectangles',
|
|
24
|
+
},
|
|
25
|
+
{
|
|
24
26
|
id: '2',
|
|
25
27
|
height: 140,
|
|
26
28
|
width: 130,
|
|
27
29
|
x: 280,
|
|
28
30
|
y: 1,
|
|
29
|
-
group: 'rectangles'
|
|
31
|
+
group: 'rectangles',
|
|
30
32
|
},
|
|
31
33
|
{
|
|
32
34
|
id: '3',
|
|
@@ -34,32 +36,37 @@ const model = () => ({
|
|
|
34
36
|
{ x: 1, y: 148 },
|
|
35
37
|
{ x: 1, y: 288 },
|
|
36
38
|
{ y: 288, x: 129 },
|
|
37
|
-
{ y: 148, x: 129 }
|
|
39
|
+
{ y: 148, x: 129 },
|
|
40
|
+
],
|
|
38
41
|
correct: true,
|
|
39
|
-
group: 'polygons'
|
|
40
|
-
},
|
|
42
|
+
group: 'polygons',
|
|
43
|
+
},
|
|
44
|
+
{
|
|
41
45
|
id: '4',
|
|
42
46
|
points: [
|
|
43
47
|
{ y: 151, x: 141 },
|
|
44
48
|
{ y: 289, x: 141 },
|
|
45
49
|
{ y: 289, x: 269 },
|
|
46
|
-
{ x: 269, y: 151 }
|
|
50
|
+
{ x: 269, y: 151 },
|
|
51
|
+
],
|
|
47
52
|
correct: false,
|
|
48
|
-
group: 'polygons'
|
|
49
|
-
},
|
|
53
|
+
group: 'polygons',
|
|
54
|
+
},
|
|
55
|
+
{
|
|
50
56
|
id: '5',
|
|
51
57
|
points: [
|
|
52
58
|
{ x: 279, y: 150 },
|
|
53
59
|
{ x: 279, y: 289 },
|
|
54
60
|
{ x: 407, y: 289 },
|
|
55
|
-
{ x: 407, y: 150 }
|
|
61
|
+
{ x: 407, y: 150 },
|
|
56
62
|
],
|
|
57
63
|
correct: false,
|
|
58
|
-
group: 'polygons'
|
|
59
|
-
}
|
|
64
|
+
group: 'polygons',
|
|
65
|
+
},
|
|
60
66
|
],
|
|
61
67
|
dimensions: {
|
|
62
|
-
height: 291,
|
|
68
|
+
height: 291,
|
|
69
|
+
width: 410,
|
|
63
70
|
},
|
|
64
71
|
hotspotColor: 'rgba(137, 183, 244, 0.65)',
|
|
65
72
|
outlineColor: 'blue',
|
|
@@ -72,11 +79,9 @@ describe('HotspotDrawable', () => {
|
|
|
72
79
|
handleEnableDrag = jest.fn(),
|
|
73
80
|
onUpdateImageDimension = jest.fn(),
|
|
74
81
|
onUpdateShapes = jest.fn(),
|
|
75
|
-
initialModel = model()
|
|
76
|
-
;
|
|
77
|
-
|
|
82
|
+
initialModel = model();
|
|
78
83
|
beforeEach(() => {
|
|
79
|
-
w = extras => {
|
|
84
|
+
w = (extras) => {
|
|
80
85
|
const props = {
|
|
81
86
|
classes: {},
|
|
82
87
|
dimensions: initialModel.dimensions,
|
|
@@ -90,11 +95,11 @@ describe('HotspotDrawable', () => {
|
|
|
90
95
|
outlineColor: initialModel.outlineColor,
|
|
91
96
|
shapes: initialModel.shapes,
|
|
92
97
|
strokeWidth: 5,
|
|
93
|
-
...extras
|
|
98
|
+
...extras,
|
|
94
99
|
};
|
|
95
100
|
|
|
96
101
|
return shallow(<Drawable {...props} />);
|
|
97
|
-
}
|
|
102
|
+
};
|
|
98
103
|
});
|
|
99
104
|
|
|
100
105
|
describe('render', () => {
|
|
@@ -126,8 +131,8 @@ describe('HotspotDrawable', () => {
|
|
|
126
131
|
currentTarget: 'Stage',
|
|
127
132
|
evt: {
|
|
128
133
|
layerX: 20,
|
|
129
|
-
layerY: 30
|
|
130
|
-
}
|
|
134
|
+
layerY: 30,
|
|
135
|
+
},
|
|
131
136
|
};
|
|
132
137
|
|
|
133
138
|
wrapper.instance().handleOnMouseDown(event);
|
|
@@ -141,8 +146,8 @@ describe('HotspotDrawable', () => {
|
|
|
141
146
|
currentTarget: 'Stage',
|
|
142
147
|
evt: {
|
|
143
148
|
layerX: 20,
|
|
144
|
-
layerY: 30
|
|
145
|
-
}
|
|
149
|
+
layerY: 30,
|
|
150
|
+
},
|
|
146
151
|
};
|
|
147
152
|
|
|
148
153
|
wrapper.instance().handleOnMouseDown(event);
|
|
@@ -156,8 +161,8 @@ describe('HotspotDrawable', () => {
|
|
|
156
161
|
x: 20,
|
|
157
162
|
y: 30,
|
|
158
163
|
group: 'rectangles',
|
|
159
|
-
index: 6
|
|
160
|
-
}
|
|
164
|
+
index: 6,
|
|
165
|
+
},
|
|
161
166
|
]);
|
|
162
167
|
});
|
|
163
168
|
|
|
@@ -168,8 +173,8 @@ describe('HotspotDrawable', () => {
|
|
|
168
173
|
wrapper.instance().handleOnMouseUp({
|
|
169
174
|
evt: {
|
|
170
175
|
layerX: 20,
|
|
171
|
-
layerY: 30
|
|
172
|
-
}
|
|
176
|
+
layerY: 30,
|
|
177
|
+
},
|
|
173
178
|
});
|
|
174
179
|
|
|
175
180
|
expect(onUpdateShapes).toHaveBeenCalledWith([...initialModel.shapes.slice(0, 2)]);
|
|
@@ -180,48 +185,43 @@ describe('HotspotDrawable', () => {
|
|
|
180
185
|
wrapper.instance().handleOnMouseUp({
|
|
181
186
|
evt: {
|
|
182
187
|
layerX: 20,
|
|
183
|
-
layerY: 30
|
|
184
|
-
}
|
|
188
|
+
layerY: 30,
|
|
189
|
+
},
|
|
185
190
|
});
|
|
186
191
|
|
|
187
192
|
expect(onUpdateShapes).not.toBeCalledWith(false);
|
|
188
193
|
|
|
189
|
-
|
|
190
194
|
wrapper.instance().handleOnMouseUp({});
|
|
191
195
|
|
|
192
196
|
expect(onUpdateShapes).toHaveBeenCalledWith(initialModel.shapes.slice(0, 2));
|
|
193
197
|
});
|
|
194
198
|
|
|
195
199
|
it('handleOnSetAsCorrect correct', () => {
|
|
196
|
-
wrapper.instance().handleOnSetAsCorrect(
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
}
|
|
200
|
-
);
|
|
200
|
+
wrapper.instance().handleOnSetAsCorrect({
|
|
201
|
+
id: '1',
|
|
202
|
+
});
|
|
201
203
|
|
|
202
204
|
expect(onUpdateShapes).toHaveBeenCalledWith([
|
|
203
205
|
initialModel.shapes[0],
|
|
204
206
|
{
|
|
205
207
|
...initialModel.shapes[1],
|
|
206
|
-
correct: true
|
|
208
|
+
correct: true,
|
|
207
209
|
},
|
|
208
|
-
...initialModel.shapes.slice(2)
|
|
210
|
+
...initialModel.shapes.slice(2),
|
|
209
211
|
]);
|
|
210
212
|
});
|
|
211
213
|
|
|
212
214
|
it('handleOnSetAsCorrect incorrect', () => {
|
|
213
|
-
wrapper.instance().handleOnSetAsCorrect(
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
}
|
|
217
|
-
);
|
|
215
|
+
wrapper.instance().handleOnSetAsCorrect({
|
|
216
|
+
id: '0',
|
|
217
|
+
});
|
|
218
218
|
|
|
219
219
|
expect(onUpdateShapes).toHaveBeenCalledWith([
|
|
220
220
|
{
|
|
221
221
|
...initialModel.shapes[0],
|
|
222
|
-
correct: false
|
|
222
|
+
correct: false,
|
|
223
223
|
},
|
|
224
|
-
...initialModel.shapes.slice(1)
|
|
224
|
+
...initialModel.shapes.slice(1),
|
|
225
225
|
]);
|
|
226
226
|
});
|
|
227
227
|
|
|
@@ -232,9 +232,9 @@ describe('HotspotDrawable', () => {
|
|
|
232
232
|
{
|
|
233
233
|
...initialModel.shapes[0],
|
|
234
234
|
x: 1,
|
|
235
|
-
y: 1
|
|
235
|
+
y: 1,
|
|
236
236
|
},
|
|
237
|
-
...initialModel.shapes.slice(1)
|
|
237
|
+
...initialModel.shapes.slice(1),
|
|
238
238
|
]);
|
|
239
239
|
});
|
|
240
240
|
|
|
@@ -243,6 +243,5 @@ describe('HotspotDrawable', () => {
|
|
|
243
243
|
|
|
244
244
|
expect(onUpdateShapes).toHaveBeenCalledWith(initialModel.shapes);
|
|
245
245
|
});
|
|
246
|
-
|
|
247
246
|
});
|
|
248
247
|
});
|