@@ -10,21 +10,27 @@ const [startServer, stopServer, expectPage] = getServerFunctions(8801);
1010beforeAll ( startServer ) ;
1111afterAll ( stopServer ) ;
1212
13+ const getCanvasOffset = async ( ) => {
14+ const { x = 0 , y = 0 } =
15+ ( await ( await expectedFramedElement ( '#canvas' ) ) . boundingBox ( ) ) ?? { } ;
16+ return { x, y} ;
17+ } ;
18+
1319test ( 'drawing' , async ( ) => {
20+ let offset ;
21+
1422 await expectPage ( `/demos/drawing` ) ;
1523 await expectedElement ( 'h1' , 'Drawing' ) ;
1624 await expectedFramedElement ( '#toolbar' ) ;
17- await expectedFramedElement ( '#canvas' ) ;
1825 await expectedFramedElement ( '#sidebar' ) ;
1926
20- let style ;
21- style = await ( await expectedFramedElement ( '.shape' ) ) . getProperty ( 'style' ) ;
22- expect ( await ( await style . getProperty ( 'left' ) ) . jsonValue ( ) ) . toEqual ( '100px' ) ;
23- expect ( await ( await style . getProperty ( 'top' ) ) . jsonValue ( ) ) . toEqual ( '100px' ) ;
24- expect ( await ( await style . getProperty ( 'width' ) ) . jsonValue ( ) ) . toEqual ( '200px' ) ;
25- expect ( await ( await style . getProperty ( 'height' ) ) . jsonValue ( ) ) . toEqual (
26- '100px' ,
27- ) ;
27+ offset = await getCanvasOffset ( ) ;
28+ expect ( await ( await expectedFramedElement ( '.shape' ) ) . boundingBox ( ) ) . toEqual ( {
29+ x : offset . x + 100 ,
30+ y : offset . y + 100 ,
31+ width : 200 ,
32+ height : 100 ,
33+ } ) ;
2834
2935 await ( await expectedFramedElement ( '.shape' , 'text' ) ) . click ( { clickCount : 2 } ) ;
3036 await ( await expectedFramedElement ( '.shape input' ) ) . type ( '42' ) ;
@@ -33,27 +39,33 @@ test('drawing', async () => {
3339
3440 await expectNoFramedElement ( '.grip' ) ;
3541 await ( await expectedFramedElement ( '.shape' , 'text' ) ) . click ( ) ;
36- const { x : gripX , y : gripY } = ( await (
37- await expectedFramedElement ( '.grip' )
38- ) . boundingBox ( ) ) ?? { x : 0 , y : 0 } ;
42+
43+ const { x : gripX = 0 , y : gripY = 0 } =
44+ ( await ( await expectedFramedElement ( '.grip' ) ) . boundingBox ( ) ) ?? { } ;
3945
4046 await page . mouse . move ( gripX , gripY ) ;
4147 await page . mouse . down ( ) ;
4248 await page . mouse . move ( gripX + 10 , gripY + 20 ) ;
4349 await page . mouse . up ( ) ;
44- style = await ( await expectedFramedElement ( '.shape' ) ) . getProperty ( 'style' ) ;
45- expect ( await ( await style . getProperty ( 'left' ) ) . jsonValue ( ) ) . toEqual ( '110px' ) ;
46- expect ( await ( await style . getProperty ( 'top' ) ) . jsonValue ( ) ) . toEqual ( '120px' ) ;
47- expect ( await ( await style . getProperty ( 'width' ) ) . jsonValue ( ) ) . toEqual ( '190px' ) ;
48- expect ( await ( await style . getProperty ( 'height' ) ) . jsonValue ( ) ) . toEqual ( '80px' ) ;
50+
51+ offset = await getCanvasOffset ( ) ;
52+ expect ( await ( await expectedFramedElement ( '.shape' ) ) . boundingBox ( ) ) . toEqual ( {
53+ x : offset . x + 110 ,
54+ y : offset . y + 120 ,
55+ width : 190 ,
56+ height : 80 ,
57+ } ) ;
4958
5059 await page . mouse . move ( gripX + 20 , gripY + 30 ) ;
5160 await page . mouse . down ( ) ;
5261 await page . mouse . move ( gripX + 10 , gripY + 10 ) ;
5362 await page . mouse . up ( ) ;
54- style = await ( await expectedFramedElement ( '.shape' ) ) . getProperty ( 'style' ) ;
55- expect ( await ( await style . getProperty ( 'left' ) ) . jsonValue ( ) ) . toEqual ( '100px' ) ;
56- expect ( await ( await style . getProperty ( 'top' ) ) . jsonValue ( ) ) . toEqual ( '100px' ) ;
57- expect ( await ( await style . getProperty ( 'width' ) ) . jsonValue ( ) ) . toEqual ( '190px' ) ;
58- expect ( await ( await style . getProperty ( 'height' ) ) . jsonValue ( ) ) . toEqual ( '80px' ) ;
63+
64+ offset = await getCanvasOffset ( ) ;
65+ expect ( await ( await expectedFramedElement ( '.shape' ) ) . boundingBox ( ) ) . toEqual ( {
66+ x : offset . x + 100 ,
67+ y : offset . y + 100 ,
68+ width : 190 ,
69+ height : 80 ,
70+ } ) ;
5971} ) ;
0 commit comments