@pie-element/hotspot 4.8.4-next.1099 → 4.8.4-next.1113
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/lib/hotspot/container.js +12 -4
- package/lib/hotspot/container.js.map +1 -1
- package/lib/hotspot/index.js +12 -2
- package/lib/hotspot/index.js.map +1 -1
- package/lib/hotspot/polygon.js +37 -17
- package/lib/hotspot/polygon.js.map +1 -1
- package/lib/hotspot/rectangle.js +37 -17
- package/lib/hotspot/rectangle.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/__snapshots__/{container-test.jsx.snap → container.test.jsx.snap} +8 -0
- package/src/__tests__/__snapshots__/image.test.jsx.snap +43 -0
- package/src/__tests__/__snapshots__/{polygon-test.jsx.snap → polygon.test.jsx.snap} +11 -0
- package/src/__tests__/__snapshots__/{rectangle-test.jsx.snap → rectangle.test.jsx.snap} +11 -0
- package/src/__tests__/{container-test.jsx → container.test.jsx} +57 -0
- package/src/__tests__/{image-test.jsx → image.test.jsx} +0 -0
- package/src/__tests__/polygon.test.jsx +224 -0
- package/src/__tests__/rectangle.test.jsx +233 -0
- package/src/__tests__/{session-updater-test.jsx → session-updater.test.jsx} +0 -0
- package/src/hotspot/container.jsx +10 -2
- package/src/hotspot/index.jsx +14 -2
- package/src/hotspot/polygon.jsx +35 -15
- package/src/hotspot/rectangle.jsx +35 -15
- package/src/__tests__/__snapshots__/image-test.jsx.snap +0 -21
- package/src/__tests__/polygon-test.jsx +0 -77
- package/src/__tests__/rectangle-test.jsx +0 -78
|
@@ -8,6 +8,8 @@ exports[`Polygon snapshots evaluate with correct answer renders 1`] = `
|
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
disabled={false}
|
|
11
|
+
evaluateText="Correctly
|
|
12
|
+
selected"
|
|
11
13
|
height={200}
|
|
12
14
|
hotspotColor="rgba(137, 183, 244, 0.65)"
|
|
13
15
|
id="1"
|
|
@@ -31,6 +33,7 @@ exports[`Polygon snapshots evaluate with correct answer renders 1`] = `
|
|
|
31
33
|
},
|
|
32
34
|
]
|
|
33
35
|
}
|
|
36
|
+
scale={1}
|
|
34
37
|
selected={false}
|
|
35
38
|
strokeWidth={5}
|
|
36
39
|
/>
|
|
@@ -44,6 +47,7 @@ exports[`Polygon snapshots hotspot color renders 1`] = `
|
|
|
44
47
|
}
|
|
45
48
|
}
|
|
46
49
|
disabled={false}
|
|
50
|
+
evaluateText={null}
|
|
47
51
|
height={200}
|
|
48
52
|
hotspotColor="rgba(217, 30, 24, 0.65)"
|
|
49
53
|
id="1"
|
|
@@ -67,6 +71,7 @@ exports[`Polygon snapshots hotspot color renders 1`] = `
|
|
|
67
71
|
},
|
|
68
72
|
]
|
|
69
73
|
}
|
|
74
|
+
scale={1}
|
|
70
75
|
selected={false}
|
|
71
76
|
strokeWidth={5}
|
|
72
77
|
/>
|
|
@@ -80,6 +85,7 @@ exports[`Polygon snapshots outline color renders 1`] = `
|
|
|
80
85
|
}
|
|
81
86
|
}
|
|
82
87
|
disabled={false}
|
|
88
|
+
evaluateText={null}
|
|
83
89
|
height={200}
|
|
84
90
|
hotspotColor="rgba(137, 183, 244, 0.65)"
|
|
85
91
|
id="1"
|
|
@@ -103,6 +109,7 @@ exports[`Polygon snapshots outline color renders 1`] = `
|
|
|
103
109
|
},
|
|
104
110
|
]
|
|
105
111
|
}
|
|
112
|
+
scale={1}
|
|
106
113
|
selected={false}
|
|
107
114
|
strokeWidth={5}
|
|
108
115
|
/>
|
|
@@ -116,6 +123,7 @@ exports[`Polygon snapshots outline width renders with default border width 1`] =
|
|
|
116
123
|
}
|
|
117
124
|
}
|
|
118
125
|
disabled={false}
|
|
126
|
+
evaluateText={null}
|
|
119
127
|
height={200}
|
|
120
128
|
hotspotColor="rgba(137, 183, 244, 0.65)"
|
|
121
129
|
id="1"
|
|
@@ -139,6 +147,7 @@ exports[`Polygon snapshots outline width renders with default border width 1`] =
|
|
|
139
147
|
},
|
|
140
148
|
]
|
|
141
149
|
}
|
|
150
|
+
scale={1}
|
|
142
151
|
selected={false}
|
|
143
152
|
strokeWidth={5}
|
|
144
153
|
/>
|
|
@@ -152,6 +161,7 @@ exports[`Polygon snapshots outline width renders with given border width 1`] = `
|
|
|
152
161
|
}
|
|
153
162
|
}
|
|
154
163
|
disabled={false}
|
|
164
|
+
evaluateText={null}
|
|
155
165
|
height={200}
|
|
156
166
|
hotspotColor="rgba(137, 183, 244, 0.65)"
|
|
157
167
|
id="1"
|
|
@@ -175,6 +185,7 @@ exports[`Polygon snapshots outline width renders with given border width 1`] = `
|
|
|
175
185
|
},
|
|
176
186
|
]
|
|
177
187
|
}
|
|
188
|
+
scale={1}
|
|
178
189
|
selected={false}
|
|
179
190
|
strokeWidth={10}
|
|
180
191
|
/>
|
|
@@ -8,6 +8,8 @@ exports[`Rectangle snapshots evaluate with correct answer renders 1`] = `
|
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
disabled={false}
|
|
11
|
+
evaluateText="Correctly
|
|
12
|
+
selected"
|
|
11
13
|
height={200}
|
|
12
14
|
hotspotColor="rgba(137, 183, 244, 0.65)"
|
|
13
15
|
id="1"
|
|
@@ -15,6 +17,7 @@ exports[`Rectangle snapshots evaluate with correct answer renders 1`] = `
|
|
|
15
17
|
isEvaluateMode={true}
|
|
16
18
|
onClick={[MockFunction]}
|
|
17
19
|
outlineColor="blue"
|
|
20
|
+
scale={1}
|
|
18
21
|
selected={false}
|
|
19
22
|
strokeWidth={5}
|
|
20
23
|
width={300}
|
|
@@ -31,6 +34,7 @@ exports[`Rectangle snapshots hotspot color renders 1`] = `
|
|
|
31
34
|
}
|
|
32
35
|
}
|
|
33
36
|
disabled={false}
|
|
37
|
+
evaluateText={null}
|
|
34
38
|
height={200}
|
|
35
39
|
hotspotColor="rgba(217, 30, 24, 0.65)"
|
|
36
40
|
id="1"
|
|
@@ -38,6 +42,7 @@ exports[`Rectangle snapshots hotspot color renders 1`] = `
|
|
|
38
42
|
isEvaluateMode={false}
|
|
39
43
|
onClick={[MockFunction]}
|
|
40
44
|
outlineColor="blue"
|
|
45
|
+
scale={1}
|
|
41
46
|
selected={false}
|
|
42
47
|
strokeWidth={5}
|
|
43
48
|
width={300}
|
|
@@ -54,6 +59,7 @@ exports[`Rectangle snapshots outline color renders 1`] = `
|
|
|
54
59
|
}
|
|
55
60
|
}
|
|
56
61
|
disabled={false}
|
|
62
|
+
evaluateText={null}
|
|
57
63
|
height={200}
|
|
58
64
|
hotspotColor="rgba(137, 183, 244, 0.65)"
|
|
59
65
|
id="1"
|
|
@@ -61,6 +67,7 @@ exports[`Rectangle snapshots outline color renders 1`] = `
|
|
|
61
67
|
isEvaluateMode={false}
|
|
62
68
|
onClick={[MockFunction]}
|
|
63
69
|
outlineColor="red"
|
|
70
|
+
scale={1}
|
|
64
71
|
selected={false}
|
|
65
72
|
strokeWidth={5}
|
|
66
73
|
width={300}
|
|
@@ -77,6 +84,7 @@ exports[`Rectangle snapshots outline width renders with default border width 1`]
|
|
|
77
84
|
}
|
|
78
85
|
}
|
|
79
86
|
disabled={false}
|
|
87
|
+
evaluateText={null}
|
|
80
88
|
height={200}
|
|
81
89
|
hotspotColor="rgba(137, 183, 244, 0.65)"
|
|
82
90
|
id="1"
|
|
@@ -84,6 +92,7 @@ exports[`Rectangle snapshots outline width renders with default border width 1`]
|
|
|
84
92
|
isEvaluateMode={false}
|
|
85
93
|
onClick={[MockFunction]}
|
|
86
94
|
outlineColor="blue"
|
|
95
|
+
scale={1}
|
|
87
96
|
selected={false}
|
|
88
97
|
strokeWidth={5}
|
|
89
98
|
width={300}
|
|
@@ -100,6 +109,7 @@ exports[`Rectangle snapshots outline width renders with given border width 1`] =
|
|
|
100
109
|
}
|
|
101
110
|
}
|
|
102
111
|
disabled={false}
|
|
112
|
+
evaluateText={null}
|
|
103
113
|
height={200}
|
|
104
114
|
hotspotColor="rgba(137, 183, 244, 0.65)"
|
|
105
115
|
id="1"
|
|
@@ -107,6 +117,7 @@ exports[`Rectangle snapshots outline width renders with given border width 1`] =
|
|
|
107
117
|
isEvaluateMode={false}
|
|
108
118
|
onClick={[MockFunction]}
|
|
109
119
|
outlineColor="blue"
|
|
120
|
+
scale={1}
|
|
110
121
|
selected={false}
|
|
111
122
|
strokeWidth={10}
|
|
112
123
|
width={300}
|
|
@@ -4,9 +4,18 @@ import { shallow } from 'enzyme';
|
|
|
4
4
|
import toJson from 'enzyme-to-json';
|
|
5
5
|
import Konva from 'konva';
|
|
6
6
|
|
|
7
|
+
import { shallowChild } from '@pie-lib/test-utils';
|
|
8
|
+
import CorrectAnswerToggle from '@pie-lib/correct-answer-toggle';
|
|
9
|
+
|
|
7
10
|
import Container, { Container as ContainerComp } from '../hotspot/container';
|
|
8
11
|
import HotspotComponent from '../hotspot/index';
|
|
9
12
|
|
|
13
|
+
global.MutationObserver = class {
|
|
14
|
+
constructor(callback) {}
|
|
15
|
+
disconnect() {}
|
|
16
|
+
observe(element, initObject) {}
|
|
17
|
+
};
|
|
18
|
+
|
|
10
19
|
Konva.isBrowser = false;
|
|
11
20
|
|
|
12
21
|
describe('HotspotComponent', () => {
|
|
@@ -61,6 +70,54 @@ describe('HotspotComponent', () => {
|
|
|
61
70
|
});
|
|
62
71
|
});
|
|
63
72
|
|
|
73
|
+
describe('CorrectAnswerToggle', () => {
|
|
74
|
+
let testWrapper, component, toggle;
|
|
75
|
+
const model = {
|
|
76
|
+
mode: 'evaluate',
|
|
77
|
+
responseCorrect: false,
|
|
78
|
+
};
|
|
79
|
+
const testWrapperFn = (props) => shallowChild(HotspotComponent, {
|
|
80
|
+
model: {
|
|
81
|
+
...model,
|
|
82
|
+
...props
|
|
83
|
+
}
|
|
84
|
+
}, 1);
|
|
85
|
+
|
|
86
|
+
beforeEach(() => {
|
|
87
|
+
testWrapper = testWrapperFn({});
|
|
88
|
+
component = testWrapper();
|
|
89
|
+
toggle = component.find(CorrectAnswerToggle);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('renders when the mode is evaluate and the response is incorrect', () => {
|
|
93
|
+
expect(toggle.length).toEqual(1);
|
|
94
|
+
expect(toggle.prop('show')).toEqual(true);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('does not render outside of evaluate mode', () => {
|
|
98
|
+
const tw = testWrapperFn({ mode: 'gather' });
|
|
99
|
+
const c = tw();
|
|
100
|
+
const t = c.find(CorrectAnswerToggle);
|
|
101
|
+
expect(t.length).toEqual(0);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('does not render if the response is correct', () => {
|
|
105
|
+
const tw = testWrapperFn({ responseCorrect: true });
|
|
106
|
+
const c = tw();
|
|
107
|
+
const t = c.find(CorrectAnswerToggle);
|
|
108
|
+
expect(t.length).toEqual(0);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('toggles the state', () => {
|
|
112
|
+
component.setState({ showCorrect: false });
|
|
113
|
+
expect(component.state('showCorrect')).toEqual(false);
|
|
114
|
+
expect(toggle.prop('toggled')).toEqual(false);
|
|
115
|
+
component.instance().onToggle();
|
|
116
|
+
expect(component.state('showCorrect')).toEqual(true);
|
|
117
|
+
expect(component.find(CorrectAnswerToggle).prop('toggled')).toEqual(true);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
64
121
|
describe('Container', () => {
|
|
65
122
|
let onSelectChoice, wrapper;
|
|
66
123
|
|
|
File without changes
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import _ from 'lodash';
|
|
3
|
+
import { shallow } from 'enzyme';
|
|
4
|
+
import toJson from 'enzyme-to-json';
|
|
5
|
+
import Konva from 'konva';
|
|
6
|
+
import { Line } from 'react-konva';
|
|
7
|
+
|
|
8
|
+
import { shallowChild } from '@pie-lib/test-utils';
|
|
9
|
+
|
|
10
|
+
import Polygon from '../hotspot/polygon';
|
|
11
|
+
import Image from '../hotspot/image';
|
|
12
|
+
import { faCorrect, faWrong } from '../hotspot/icons';
|
|
13
|
+
|
|
14
|
+
Konva.isBrowser = false;
|
|
15
|
+
|
|
16
|
+
describe('Polygon', () => {
|
|
17
|
+
let onClick, wrapper;
|
|
18
|
+
|
|
19
|
+
const mkWrapper = (opts = {}) => {
|
|
20
|
+
opts = _.extend(
|
|
21
|
+
{
|
|
22
|
+
classes: {
|
|
23
|
+
base: 'base'
|
|
24
|
+
},
|
|
25
|
+
height: 200,
|
|
26
|
+
hotspotColor: 'rgba(137, 183, 244, 0.65)',
|
|
27
|
+
id: '1',
|
|
28
|
+
isCorrect: false,
|
|
29
|
+
isEvaluateMode: false,
|
|
30
|
+
evaluateText: null,
|
|
31
|
+
disabled: false,
|
|
32
|
+
outlineColor: 'blue',
|
|
33
|
+
selected: false,
|
|
34
|
+
points: [{ x: 94, y: 4 }, { x: 89, y: 4 }, { x: 36, y: 40 }]
|
|
35
|
+
},
|
|
36
|
+
opts
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
return shallow(<Polygon {...opts} onClick={onClick} />);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
beforeEach(() => {
|
|
43
|
+
onClick = jest.fn();
|
|
44
|
+
wrapper = mkWrapper();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe('snapshots', () => {
|
|
48
|
+
describe('outline color', () => {
|
|
49
|
+
it('renders', () => {
|
|
50
|
+
const wrapper = mkWrapper({ outlineColor: 'red' });
|
|
51
|
+
expect(toJson(wrapper)).toMatchSnapshot();
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
describe('outline width', () => {
|
|
56
|
+
it('renders with default border width', () => {
|
|
57
|
+
const wrapper = mkWrapper();
|
|
58
|
+
expect(toJson(wrapper)).toMatchSnapshot();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('renders with given border width', () => {
|
|
62
|
+
const wrapper = mkWrapper({ strokeWidth: 10 });
|
|
63
|
+
expect(toJson(wrapper)).toMatchSnapshot();
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
describe('hotspot color', () => {
|
|
69
|
+
it('renders', () => {
|
|
70
|
+
const wrapper = mkWrapper({ hotspotColor: 'rgba(217, 30, 24, 0.65)' });
|
|
71
|
+
expect(toJson(wrapper)).toMatchSnapshot();
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe('evaluate with correct answer', () => {
|
|
76
|
+
it('renders', () => {
|
|
77
|
+
const wrapper = mkWrapper({ isEvaluateMode: true, isCorrect: true, evaluateText: 'Correctly\nselected' });
|
|
78
|
+
expect(toJson(wrapper)).toMatchSnapshot();
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe('in evaluate mode', () => {
|
|
84
|
+
const defaultModel = {
|
|
85
|
+
height: 200,
|
|
86
|
+
hotspotColor: 'rgba(137, 183, 244, 0.65)',
|
|
87
|
+
id: '1',
|
|
88
|
+
isCorrect: false,
|
|
89
|
+
isEvaluateMode: true,
|
|
90
|
+
evaluateText: null,
|
|
91
|
+
disabled: true,
|
|
92
|
+
outlineColor: 'blue',
|
|
93
|
+
strokeWidth: 5,
|
|
94
|
+
selected: false,
|
|
95
|
+
points: [{ x: 94, y: 4 }, { x: 89, y: 4 }, { x: 36, y: 40 }],
|
|
96
|
+
markAsCorrect: false,
|
|
97
|
+
showCorrectEnabled: false,
|
|
98
|
+
onClick
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const getComponents = (model) => {
|
|
102
|
+
const testWrapper = shallowChild(Polygon, {
|
|
103
|
+
...defaultModel,
|
|
104
|
+
...model
|
|
105
|
+
}, 1);
|
|
106
|
+
const polygonComponent = testWrapper();
|
|
107
|
+
const lineComponent = polygonComponent.find(Line);
|
|
108
|
+
return {
|
|
109
|
+
polygonComponent,
|
|
110
|
+
lineComponent
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
describe('when correctly selected', () => {
|
|
115
|
+
const { polygonComponent, lineComponent } = getComponents({
|
|
116
|
+
selected: true,
|
|
117
|
+
isCorrect: true
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('should have a blue outline', () => {
|
|
121
|
+
expect(lineComponent.prop('stroke')).toEqual('blue');
|
|
122
|
+
expect(lineComponent.prop('strokeWidth')).toEqual(defaultModel.strokeWidth);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('should have a green checkmark icon', () => {
|
|
126
|
+
const imgComponent = polygonComponent.find(Image);
|
|
127
|
+
expect(imgComponent.length).toEqual(1);
|
|
128
|
+
expect(imgComponent.prop('src')).toEqual(faCorrect);
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
describe('when correctly not selected', () => {
|
|
133
|
+
const { polygonComponent, lineComponent } = getComponents({
|
|
134
|
+
selected: false,
|
|
135
|
+
isCorrect: true
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('should have no outline', () => {
|
|
139
|
+
expect(lineComponent.prop('strokeWidth')).toEqual(0);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('should have no icon', () => {
|
|
143
|
+
const imgComponent = polygonComponent.find(Image);
|
|
144
|
+
expect(imgComponent.length).toEqual(0);
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
describe('when incorrectly selected', () => {
|
|
149
|
+
const { polygonComponent, lineComponent } = getComponents({
|
|
150
|
+
selected: true,
|
|
151
|
+
isCorrect: false
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('should have a red outline', () => {
|
|
155
|
+
expect(lineComponent.prop('stroke')).toEqual('red');
|
|
156
|
+
expect(lineComponent.prop('strokeWidth')).toEqual(defaultModel.strokeWidth);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('should have a red x icon', () => {
|
|
160
|
+
const imgComponent = polygonComponent.find(Image);
|
|
161
|
+
expect(imgComponent.length).toEqual(1);
|
|
162
|
+
expect(imgComponent.prop('src')).toEqual(faWrong);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
describe('when incorrectly not selected', () => {
|
|
167
|
+
const { polygonComponent, lineComponent } = getComponents({
|
|
168
|
+
selected: false,
|
|
169
|
+
isCorrect: false
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it('should have no outline', () => {
|
|
173
|
+
expect(lineComponent.prop('strokeWidth')).toEqual(0);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it('should have a red x icon', () => {
|
|
177
|
+
const imgComponent = polygonComponent.find(Image);
|
|
178
|
+
expect(imgComponent.length).toEqual(1);
|
|
179
|
+
expect(imgComponent.prop('src')).toEqual(faWrong);
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
describe('when showing correct answer (showCorrectEnabled = true)', () => {
|
|
184
|
+
it('should have a green outline', () => {
|
|
185
|
+
const { lineComponent } = getComponents({
|
|
186
|
+
showCorrectEnabled: true,
|
|
187
|
+
markAsCorrect: true
|
|
188
|
+
});
|
|
189
|
+
expect(lineComponent.prop('stroke')).toEqual('green');
|
|
190
|
+
expect(lineComponent.prop('strokeWidth')).toEqual(defaultModel.strokeWidth);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('should have a green checkmark icon', () => {
|
|
194
|
+
const { polygonComponent } = getComponents({
|
|
195
|
+
showCorrectEnabled: true,
|
|
196
|
+
markAsCorrect: true
|
|
197
|
+
});
|
|
198
|
+
const imgComponent = polygonComponent.find(Image);
|
|
199
|
+
expect(imgComponent.prop('src')).toEqual(faCorrect);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it('should not be selected if the answer is incorrect', () => {
|
|
203
|
+
const { lineComponent } = getComponents({
|
|
204
|
+
showCorrectEnabled: true,
|
|
205
|
+
markAsCorrect: false,
|
|
206
|
+
selected: true,
|
|
207
|
+
isCorrect: false
|
|
208
|
+
});
|
|
209
|
+
expect(lineComponent.prop('strokeWidth')).toEqual(0);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it('should not render an icon if the answer is incorrect', () => {
|
|
213
|
+
const { polygonComponent } = getComponents({
|
|
214
|
+
showCorrectEnabled: true,
|
|
215
|
+
markAsCorrect: false,
|
|
216
|
+
selected: true,
|
|
217
|
+
isCorrect: false
|
|
218
|
+
});
|
|
219
|
+
const imgComponent = polygonComponent.find(Image);
|
|
220
|
+
expect(imgComponent.length).toEqual(0);
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
});
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import _ from 'lodash';
|
|
3
|
+
import { shallow } from 'enzyme';
|
|
4
|
+
import toJson from 'enzyme-to-json';
|
|
5
|
+
import Konva from 'konva';
|
|
6
|
+
import { Rect } from 'react-konva';
|
|
7
|
+
|
|
8
|
+
import { shallowChild } from '@pie-lib/test-utils';
|
|
9
|
+
|
|
10
|
+
import Rectangle from '../hotspot/rectangle';
|
|
11
|
+
import Image from '../hotspot/image';
|
|
12
|
+
import { faCorrect, faWrong } from '../hotspot/icons';
|
|
13
|
+
|
|
14
|
+
global.MutationObserver = class {
|
|
15
|
+
constructor(callback) {}
|
|
16
|
+
disconnect() {}
|
|
17
|
+
observe(element, initObject) {}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
Konva.isBrowser = false;
|
|
21
|
+
|
|
22
|
+
describe('Rectangle', () => {
|
|
23
|
+
let onClick, wrapper;
|
|
24
|
+
|
|
25
|
+
const mkWrapper = (opts = {}) => {
|
|
26
|
+
opts = _.extend(
|
|
27
|
+
{
|
|
28
|
+
classes: {
|
|
29
|
+
base: 'base'
|
|
30
|
+
},
|
|
31
|
+
height: 200,
|
|
32
|
+
hotspotColor: 'rgba(137, 183, 244, 0.65)',
|
|
33
|
+
id: '1',
|
|
34
|
+
isCorrect: false,
|
|
35
|
+
isEvaluateMode: false,
|
|
36
|
+
evaluateText: null,
|
|
37
|
+
disabled: false,
|
|
38
|
+
outlineColor: 'blue',
|
|
39
|
+
selected: false,
|
|
40
|
+
width: 300,
|
|
41
|
+
x: 5,
|
|
42
|
+
y: 5
|
|
43
|
+
},
|
|
44
|
+
opts
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
return shallow(<Rectangle {...opts} onClick={onClick} />);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
beforeEach(() => {
|
|
51
|
+
onClick = jest.fn();
|
|
52
|
+
wrapper = mkWrapper();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
describe('snapshots', () => {
|
|
56
|
+
describe('outline color', () => {
|
|
57
|
+
it('renders', () => {
|
|
58
|
+
const wrapper = mkWrapper({ outlineColor: 'red' });
|
|
59
|
+
expect(toJson(wrapper)).toMatchSnapshot();
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe('outline width', () => {
|
|
64
|
+
it('renders with default border width', () => {
|
|
65
|
+
const wrapper = mkWrapper();
|
|
66
|
+
expect(toJson(wrapper)).toMatchSnapshot();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('renders with given border width', () => {
|
|
70
|
+
const wrapper = mkWrapper({ strokeWidth: 10 });
|
|
71
|
+
expect(toJson(wrapper)).toMatchSnapshot();
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe('hotspot color', () => {
|
|
76
|
+
it('renders', () => {
|
|
77
|
+
const wrapper = mkWrapper({ hotspotColor: 'rgba(217, 30, 24, 0.65)' });
|
|
78
|
+
expect(toJson(wrapper)).toMatchSnapshot();
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
describe('evaluate with correct answer', () => {
|
|
83
|
+
it('renders', () => {
|
|
84
|
+
const wrapper = mkWrapper({ isEvaluateMode: true, isCorrect: true, evaluateText: 'Correctly\nselected' });
|
|
85
|
+
expect(toJson(wrapper)).toMatchSnapshot();
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
describe('in evaluate mode', () => {
|
|
91
|
+
const defaultModel = {
|
|
92
|
+
onClick,
|
|
93
|
+
id: '1',
|
|
94
|
+
height: 200,
|
|
95
|
+
hotspotColor: 'rgba(137, 183, 244, 0.65)',
|
|
96
|
+
disabled: true,
|
|
97
|
+
width: 300,
|
|
98
|
+
x: 5,
|
|
99
|
+
y: 5,
|
|
100
|
+
selected: false,
|
|
101
|
+
isCorrect: false,
|
|
102
|
+
isEvaluateMode: true,
|
|
103
|
+
evaluateText: null,
|
|
104
|
+
strokeWidth: 5,
|
|
105
|
+
outlineColor: 'blue',
|
|
106
|
+
markAsCorrect: false,
|
|
107
|
+
showCorrectEnabled: false
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const getComponents = (model) => {
|
|
111
|
+
const testWrapper = shallowChild(Rectangle, {
|
|
112
|
+
...defaultModel,
|
|
113
|
+
...model
|
|
114
|
+
}, 1);
|
|
115
|
+
const rectangleComponent = testWrapper();
|
|
116
|
+
const rectComponent = rectangleComponent.find(Rect);
|
|
117
|
+
return {
|
|
118
|
+
rectangleComponent,
|
|
119
|
+
rectComponent
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
describe('when correctly selected', () => {
|
|
124
|
+
const { rectangleComponent, rectComponent } = getComponents({
|
|
125
|
+
selected: true,
|
|
126
|
+
isCorrect: true
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('should have a blue outline', () => {
|
|
130
|
+
expect(rectComponent.prop('stroke')).toEqual('blue');
|
|
131
|
+
expect(rectComponent.prop('strokeWidth')).toEqual(defaultModel.strokeWidth);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('should have a green checkmark icon', () => {
|
|
135
|
+
const imgComponent = rectangleComponent.find(Image);
|
|
136
|
+
expect(imgComponent.length).toEqual(1);
|
|
137
|
+
expect(imgComponent.prop('src')).toEqual(faCorrect);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
describe('when correctly not selected', () => {
|
|
142
|
+
const { rectangleComponent, rectComponent } = getComponents({
|
|
143
|
+
selected: false,
|
|
144
|
+
isCorrect: true
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it('should have no outline', () => {
|
|
148
|
+
expect(rectComponent.prop('strokeWidth')).toEqual(0);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('should have no icon', () => {
|
|
152
|
+
const imgComponent = rectangleComponent.find(Image);
|
|
153
|
+
expect(imgComponent.length).toEqual(0);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
describe('when incorrectly selected', () => {
|
|
158
|
+
const { rectangleComponent, rectComponent } = getComponents({
|
|
159
|
+
selected: true,
|
|
160
|
+
isCorrect: false
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it('should have a red outline', () => {
|
|
164
|
+
expect(rectComponent.prop('stroke')).toEqual('red');
|
|
165
|
+
expect(rectComponent.prop('strokeWidth')).toEqual(defaultModel.strokeWidth);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it('should have a red x icon', () => {
|
|
169
|
+
const imgComponent = rectangleComponent.find(Image);
|
|
170
|
+
expect(imgComponent.length).toEqual(1);
|
|
171
|
+
expect(imgComponent.prop('src')).toEqual(faWrong);
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
describe('when incorrectly not selected', () => {
|
|
176
|
+
const { rectangleComponent, rectComponent } = getComponents({
|
|
177
|
+
selected: false,
|
|
178
|
+
isCorrect: false
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it('should have no outline', () => {
|
|
182
|
+
expect(rectComponent.prop('strokeWidth')).toEqual(0);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('should have a red x icon', () => {
|
|
186
|
+
const imgComponent = rectangleComponent.find(Image);
|
|
187
|
+
expect(imgComponent.length).toEqual(1);
|
|
188
|
+
expect(imgComponent.prop('src')).toEqual(faWrong);
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
describe('when showing correct answer (showCorrectEnabled = true)', () => {
|
|
193
|
+
it('should have a green outline', () => {
|
|
194
|
+
const { rectComponent } = getComponents({
|
|
195
|
+
showCorrectEnabled: true,
|
|
196
|
+
markAsCorrect: true
|
|
197
|
+
});
|
|
198
|
+
expect(rectComponent.prop('stroke')).toEqual('green');
|
|
199
|
+
expect(rectComponent.prop('strokeWidth')).toEqual(defaultModel.strokeWidth);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it('should have a green checkmark icon', () => {
|
|
203
|
+
const { rectangleComponent } = getComponents({
|
|
204
|
+
showCorrectEnabled: true,
|
|
205
|
+
markAsCorrect: true
|
|
206
|
+
});
|
|
207
|
+
const imgComponent = rectangleComponent.find(Image);
|
|
208
|
+
expect(imgComponent.prop('src')).toEqual(faCorrect);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it('should not be selected if the answer is incorrect', () => {
|
|
212
|
+
const { rectComponent } = getComponents({
|
|
213
|
+
showCorrectEnabled: true,
|
|
214
|
+
markAsCorrect: false,
|
|
215
|
+
selected: true,
|
|
216
|
+
isCorrect: false
|
|
217
|
+
});
|
|
218
|
+
expect(rectComponent.prop('strokeWidth')).toEqual(0);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it('should not render an icon if the answer is incorrect', () => {
|
|
222
|
+
const { rectangleComponent } = getComponents({
|
|
223
|
+
showCorrectEnabled: true,
|
|
224
|
+
markAsCorrect: false,
|
|
225
|
+
selected: true,
|
|
226
|
+
isCorrect: false
|
|
227
|
+
});
|
|
228
|
+
const imgComponent = rectangleComponent.find(Image);
|
|
229
|
+
expect(imgComponent.length).toEqual(0);
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
});
|
|
File without changes
|