1
1
import { expect } from '../../util/configuredChai' ;
2
2
import sinon from 'sinon' ;
3
3
import React from 'react' ;
4
- import ReactTestUtils from 'react-addons-test-utils ' ;
4
+ import { shallow } from 'enzyme ' ;
5
5
import AppLabCrosshairOverlay from '@cdo/apps/applab/AppLabCrosshairOverlay' ;
6
- import CrosshairOverlay from '@cdo/apps/templates/CrosshairOverlay' ;
7
6
// ES5-style require necessary to stub gridUtils.draggedElementDropPoint
8
7
var gridUtils = require ( '@cdo/apps/applab/gridUtils' ) ;
9
8
@@ -12,10 +11,9 @@ describe('AppLabCrosshairOverlay', () => {
12
11
TEST_APP_HEIGHT = Math . random ( ) ,
13
12
TEST_MOUSE_X = Math . random ( ) ,
14
13
TEST_MOUSE_Y = Math . random ( ) ;
15
- var renderer , stubDraggedElementDropPoint ;
14
+ var stubDraggedElementDropPoint ;
16
15
17
16
beforeEach ( ( ) => {
18
- renderer = ReactTestUtils . createRenderer ( ) ;
19
17
stubDraggedElementDropPoint = sinon . stub ( gridUtils , 'draggedElementDropPoint' ) ;
20
18
} ) ;
21
19
@@ -25,45 +23,43 @@ describe('AppLabCrosshairOverlay', () => {
25
23
26
24
it ( 'renders to CrosshairOverlay with unmodified properties when not dragging' , ( ) => {
27
25
stubDraggedElementDropPoint . returns ( null ) ;
28
- renderer . render (
26
+ var element = shallow (
29
27
< AppLabCrosshairOverlay
30
28
width = { TEST_APP_WIDTH }
31
29
height = { TEST_APP_HEIGHT }
32
30
mouseX = { TEST_MOUSE_X }
33
31
mouseY = { TEST_MOUSE_Y }
34
32
/>
35
33
) ;
36
- const result = renderer . getRenderOutput ( ) ;
37
- expect ( result ) . to . deep . equal (
38
- < CrosshairOverlay
39
- width = { TEST_APP_WIDTH }
40
- height = { TEST_APP_HEIGHT }
41
- mouseX = { TEST_MOUSE_X }
42
- mouseY = { TEST_MOUSE_Y }
43
- />
44
- ) ;
34
+
35
+ var overlay = element . find ( 'CrosshairOverlay' ) ;
36
+ var props = overlay . props ( ) ;
37
+ expect ( overlay . length ) . to . equal ( 1 ) ;
38
+ expect ( props . width ) . to . equal ( TEST_APP_WIDTH ) ;
39
+ expect ( props . height ) . to . equal ( TEST_APP_HEIGHT ) ;
40
+ expect ( props . mouseX ) . to . equal ( TEST_MOUSE_X ) ;
41
+ expect ( props . mouseY ) . to . equal ( TEST_MOUSE_Y ) ;
45
42
} ) ;
46
43
47
44
it ( 'renders to CrosshairOverlay with overridden mouse coordinates when dragging' , ( ) => {
48
45
const dropPointX = 42 ;
49
46
const dropPointY = 43 ;
50
47
stubDraggedElementDropPoint . returns ( { left : dropPointX , top : dropPointY } ) ;
51
- renderer . render (
48
+ var element = shallow (
52
49
< AppLabCrosshairOverlay
53
50
width = { TEST_APP_WIDTH }
54
51
height = { TEST_APP_HEIGHT }
55
52
mouseX = { TEST_MOUSE_X }
56
53
mouseY = { TEST_MOUSE_Y }
57
54
/>
58
55
) ;
59
- const result = renderer . getRenderOutput ( ) ;
60
- expect ( result ) . to . deep . equal (
61
- < CrosshairOverlay
62
- width = { TEST_APP_WIDTH }
63
- height = { TEST_APP_HEIGHT }
64
- mouseX = { dropPointX }
65
- mouseY = { dropPointY }
66
- />
67
- ) ;
56
+
57
+ var overlay = element . find ( 'CrosshairOverlay' ) ;
58
+ var props = overlay . props ( ) ;
59
+ expect ( overlay . length ) . to . equal ( 1 ) ;
60
+ expect ( props . width ) . to . equal ( TEST_APP_WIDTH ) ;
61
+ expect ( props . height ) . to . equal ( TEST_APP_HEIGHT ) ;
62
+ expect ( props . mouseX ) . to . equal ( dropPointX ) ;
63
+ expect ( props . mouseY ) . to . equal ( dropPointY ) ;
68
64
} ) ;
69
65
} ) ;
0 commit comments