@@ -52,6 +52,15 @@ const commit = async page => {
5252
5353const switchToInk = switchToEditor . bind ( null , "Ink" ) ;
5454
55+ const drawLine = async ( page , x0 , y0 , x1 , y1 ) => {
56+ const clickHandle = await waitForPointerUp ( page ) ;
57+ await page . mouse . move ( x0 , y0 ) ;
58+ await page . mouse . down ( ) ;
59+ await page . mouse . move ( x1 , y1 ) ;
60+ await page . mouse . up ( ) ;
61+ await awaitPromise ( clickHandle ) ;
62+ } ;
63+
5564describe ( "Ink Editor" , ( ) => {
5665 describe ( "Basic operations" , ( ) => {
5766 let pages ;
@@ -74,13 +83,7 @@ describe("Ink Editor", () => {
7483 for ( let i = 0 ; i < 3 ; i ++ ) {
7584 const x = rect . x + 100 + i * 100 ;
7685 const y = rect . y + 100 + i * 100 ;
77- const clickHandle = await waitForPointerUp ( page ) ;
78- await page . mouse . move ( x , y ) ;
79- await page . mouse . down ( ) ;
80- await page . mouse . move ( x + 50 , y + 50 ) ;
81- await page . mouse . up ( ) ;
82- await awaitPromise ( clickHandle ) ;
83-
86+ await drawLine ( page , x , y , x + 50 , y + 50 ) ;
8487 await commit ( page ) ;
8588 }
8689
@@ -107,15 +110,9 @@ describe("Ink Editor", () => {
107110
108111 const rect = await getRect ( page , ".annotationEditorLayer" ) ;
109112
110- const xStart = rect . x + 300 ;
111- const yStart = rect . y + 300 ;
112- const clickHandle = await waitForPointerUp ( page ) ;
113- await page . mouse . move ( xStart , yStart ) ;
114- await page . mouse . down ( ) ;
115- await page . mouse . move ( xStart + 50 , yStart + 50 ) ;
116- await page . mouse . up ( ) ;
117- await awaitPromise ( clickHandle ) ;
118-
113+ const x = rect . x + 300 ;
114+ const y = rect . y + 300 ;
115+ await drawLine ( page , x , y , x + 50 , y + 50 ) ;
119116 await commit ( page ) ;
120117
121118 const rectBefore = await getRect ( page , ".canvasWrapper .draw" ) ;
@@ -149,13 +146,7 @@ describe("Ink Editor", () => {
149146
150147 const x = rect . x + 100 ;
151148 const y = rect . y + 100 ;
152- const clickHandle = await waitForPointerUp ( page ) ;
153- await page . mouse . move ( x , y ) ;
154- await page . mouse . down ( ) ;
155- await page . mouse . move ( x + 50 , y + 50 ) ;
156- await page . mouse . up ( ) ;
157- await awaitPromise ( clickHandle ) ;
158-
149+ await drawLine ( page , x , y , x + 50 , y + 50 ) ;
159150 await commit ( page ) ;
160151
161152 const editorSelector = getEditorSelector ( 0 ) ;
@@ -205,13 +196,7 @@ describe("Ink Editor", () => {
205196
206197 const x = rect . x + 20 ;
207198 const y = rect . y + 20 ;
208- const clickHandle = await waitForPointerUp ( page ) ;
209- await page . mouse . move ( x , y ) ;
210- await page . mouse . down ( ) ;
211- await page . mouse . move ( x + 50 , y + 50 ) ;
212- await page . mouse . up ( ) ;
213- await awaitPromise ( clickHandle ) ;
214-
199+ await drawLine ( page , x , y , x + 50 , y + 50 ) ;
215200 await commit ( page ) ;
216201
217202 await selectAll ( page ) ;
@@ -244,13 +229,7 @@ describe("Ink Editor", () => {
244229
245230 const x = rect . x + 20 ;
246231 const y = rect . y + 20 ;
247- const clickHandle = await waitForPointerUp ( page ) ;
248- await page . mouse . move ( x , y ) ;
249- await page . mouse . down ( ) ;
250- await page . mouse . move ( x + 50 , y + 50 ) ;
251- await page . mouse . up ( ) ;
252- await awaitPromise ( clickHandle ) ;
253-
232+ await drawLine ( page , x , y , x + 50 , y + 50 ) ;
254233 await commit ( page ) ;
255234
256235 const oneToFourteen = Array . from ( new Array ( 13 ) . keys ( ) , n => n + 2 ) ;
@@ -299,12 +278,7 @@ describe("Ink Editor", () => {
299278
300279 const x = rect . x + 20 ;
301280 const y = rect . y + 20 ;
302- const clickHandle = await waitForPointerUp ( page ) ;
303- await page . mouse . move ( x , y ) ;
304- await page . mouse . down ( ) ;
305- await page . mouse . move ( x + 50 , y + 50 ) ;
306- await page . mouse . up ( ) ;
307- await awaitPromise ( clickHandle ) ;
281+ await drawLine ( page , x , y , x + 50 , y + 50 ) ;
308282
309283 await page . mouse . click ( rect . x - 10 , rect . y + 10 ) ;
310284 await page . waitForSelector ( `${ getEditorSelector ( 0 ) } .disabled` ) ;
@@ -331,14 +305,9 @@ describe("Ink Editor", () => {
331305
332306 const rect = await getRect ( page , ".annotationEditorLayer" ) ;
333307
334- const xStart = rect . x + 300 ;
335- const yStart = rect . y + 300 ;
336- const clickHandle = await waitForPointerUp ( page ) ;
337- await page . mouse . move ( xStart , yStart ) ;
338- await page . mouse . down ( ) ;
339- await page . mouse . move ( xStart + 50 , yStart + 50 ) ;
340- await page . mouse . up ( ) ;
341- await awaitPromise ( clickHandle ) ;
308+ const x = rect . x + 300 ;
309+ const y = rect . y + 300 ;
310+ await drawLine ( page , x , y , x + 50 , y + 50 ) ;
342311 await commit ( page ) ;
343312
344313 const editorSelector = getEditorSelector ( 0 ) ;
@@ -375,14 +344,9 @@ describe("Ink Editor", () => {
375344
376345 const rect = await getRect ( page , ".annotationEditorLayer" ) ;
377346
378- const xStart = rect . x + 300 ;
379- const yStart = rect . y + 300 ;
380- const clickHandle = await waitForPointerUp ( page ) ;
381- await page . mouse . move ( xStart , yStart ) ;
382- await page . mouse . down ( ) ;
383- await page . mouse . move ( xStart + 50 , yStart + 50 ) ;
384- await page . mouse . up ( ) ;
385- await awaitPromise ( clickHandle ) ;
347+ const x = rect . x + 300 ;
348+ const y = rect . y + 300 ;
349+ await drawLine ( page , x , y , x + 50 , y + 50 ) ;
386350 await commit ( page ) ;
387351
388352 const editorSelector = getEditorSelector ( 0 ) ;
@@ -432,14 +396,9 @@ describe("Ink Editor", () => {
432396
433397 const rect = await getRect ( page , ".annotationEditorLayer" ) ;
434398
435- const xStart = rect . x + 300 ;
436- const yStart = rect . y + 300 ;
437- const clickHandle = await waitForPointerUp ( page ) ;
438- await page . mouse . move ( xStart , yStart ) ;
439- await page . mouse . down ( ) ;
440- await page . mouse . move ( xStart + 50 , yStart + 50 ) ;
441- await page . mouse . up ( ) ;
442- await awaitPromise ( clickHandle ) ;
399+ const x = rect . x + 300 ;
400+ const y = rect . y + 300 ;
401+ await drawLine ( page , x , y , x + 50 , y + 50 ) ;
443402 await commit ( page ) ;
444403
445404 const editorSelector = getEditorSelector ( 0 ) ;
@@ -483,16 +442,11 @@ describe("Ink Editor", () => {
483442 await switchToInk ( page ) ;
484443 const rect = await getRect ( page , ".annotationEditorLayer" ) ;
485444
486- let xStart = rect . x + 10 ;
487- const yStart = rect . y + 10 ;
445+ let x = rect . x + 10 ;
446+ const y = rect . y + 10 ;
488447 for ( let i = 0 ; i < 5 ; i ++ ) {
489- const clickHandle = await waitForPointerUp ( page ) ;
490- await page . mouse . move ( xStart , yStart ) ;
491- await page . mouse . down ( ) ;
492- await page . mouse . move ( xStart + 50 , yStart + 50 ) ;
493- await page . mouse . up ( ) ;
494- await awaitPromise ( clickHandle ) ;
495- xStart += 70 ;
448+ await drawLine ( page , x , y , x + 50 , y + 50 ) ;
449+ x += 70 ;
496450 }
497451 await commit ( page ) ;
498452
@@ -561,13 +515,7 @@ describe("Ink Editor", () => {
561515
562516 const x = rect . x + 20 ;
563517 const y = rect . y + 20 ;
564- const clickHandle = await waitForPointerUp ( page ) ;
565- await page . mouse . move ( x , y ) ;
566- await page . mouse . down ( ) ;
567- await page . mouse . move ( x + 50 , y + 50 ) ;
568- await page . mouse . up ( ) ;
569- await awaitPromise ( clickHandle ) ;
570-
518+ await drawLine ( page , x , y , x + 50 , y + 50 ) ;
571519 await commit ( page ) ;
572520
573521 const drawSelector = `.page[data-page-number = "1"] .canvasWrapper .draw` ;
@@ -636,12 +584,7 @@ describe("Ink Editor", () => {
636584
637585 const x = rect . x + 20 ;
638586 const y = rect . y + 20 ;
639- const clickHandle = await waitForPointerUp ( page ) ;
640- await page . mouse . move ( x , y ) ;
641- await page . mouse . down ( ) ;
642- await page . mouse . move ( x + 50 , y + 50 ) ;
643- await page . mouse . up ( ) ;
644- await awaitPromise ( clickHandle ) ;
587+ await drawLine ( page , x , y , x + 50 , y + 50 ) ;
645588
646589 const drawSelector = `.canvasWrapper svg.draw path[d]:not([d=""])` ;
647590 await page . waitForSelector ( drawSelector ) ;
@@ -680,12 +623,7 @@ describe("Ink Editor", () => {
680623
681624 const x = rect . x + 20 ;
682625 const y = rect . y + 20 ;
683- const clickHandle = await waitForPointerUp ( page ) ;
684- await page . mouse . move ( x , y ) ;
685- await page . mouse . down ( ) ;
686- await page . mouse . move ( x + 50 , y + 50 ) ;
687- await page . mouse . up ( ) ;
688- await awaitPromise ( clickHandle ) ;
626+ await drawLine ( page , x , y , x + 50 , y + 50 ) ;
689627
690628 await page . evaluate ( ( ) => {
691629 window . focusedIds = [ ] ;
@@ -884,14 +822,9 @@ describe("Ink Editor", () => {
884822 await switchToInk ( page ) ;
885823
886824 const rect = await getRect ( page , ".annotationEditorLayer" ) ;
887- const xStart = rect . x + 300 ;
888- const yStart = rect . y + 300 ;
889- const clickHandle = await waitForPointerUp ( page ) ;
890- await page . mouse . move ( xStart , yStart ) ;
891- await page . mouse . down ( ) ;
892- await page . mouse . move ( xStart + 50 , yStart + 50 ) ;
893- await page . mouse . up ( ) ;
894- await awaitPromise ( clickHandle ) ;
825+ const x = rect . x + 300 ;
826+ const y = rect . y + 300 ;
827+ await drawLine ( page , x , y , x + 50 , y + 50 ) ;
895828 await commit ( page ) ;
896829
897830 await page . waitForSelector ( editorSelector ) ;
@@ -918,14 +851,9 @@ describe("Ink Editor", () => {
918851 await switchToInk ( page ) ;
919852
920853 const rect = await getRect ( page , ".annotationEditorLayer" ) ;
921- const xStart = rect . x + 300 ;
922- const yStart = rect . y + 300 ;
923- const clickHandle = await waitForPointerUp ( page ) ;
924- await page . mouse . move ( xStart , yStart ) ;
925- await page . mouse . down ( ) ;
926- await page . mouse . move ( xStart + 50 , yStart + 50 ) ;
927- await page . mouse . up ( ) ;
928- await awaitPromise ( clickHandle ) ;
854+ const x = rect . x + 300 ;
855+ const y = rect . y + 300 ;
856+ await drawLine ( page , x , y , x + 50 , y + 50 ) ;
929857 await commit ( page ) ;
930858
931859 await page . waitForSelector ( editorSelector ) ;
@@ -957,14 +885,9 @@ describe("Ink Editor", () => {
957885 await switchToInk ( page ) ;
958886
959887 const rect = await getRect ( page , ".annotationEditorLayer" ) ;
960- const xStart = rect . x + 300 ;
961- const yStart = rect . y + 300 ;
962- const clickHandle = await waitForPointerUp ( page ) ;
963- await page . mouse . move ( xStart , yStart ) ;
964- await page . mouse . down ( ) ;
965- await page . mouse . move ( xStart + 50 , yStart + 50 ) ;
966- await page . mouse . up ( ) ;
967- await awaitPromise ( clickHandle ) ;
888+ const x = rect . x + 300 ;
889+ const y = rect . y + 300 ;
890+ await drawLine ( page , x , y , x + 50 , y + 50 ) ;
968891 await commit ( page ) ;
969892
970893 await page . waitForSelector ( editorSelector ) ;
@@ -976,14 +899,9 @@ describe("Ink Editor", () => {
976899 await page . waitForSelector ( "#editorUndoBar" , { visible : true } ) ;
977900
978901 const newRect = await getRect ( page , ".annotationEditorLayer" ) ;
979- const newXStart = newRect . x + 300 ;
980- const newYStart = newRect . y + 300 ;
981- const newClickHandle = await waitForPointerUp ( page ) ;
982- await page . mouse . move ( newXStart , newYStart ) ;
983- await page . mouse . down ( ) ;
984- await page . mouse . move ( newXStart + 50 , newYStart + 50 ) ;
985- await page . mouse . up ( ) ;
986- await awaitPromise ( newClickHandle ) ;
902+ const newX = newRect . x + 300 ;
903+ const newY = newRect . y + 300 ;
904+ await drawLine ( page , newX , newY , newX + 50 , newY + 50 ) ;
987905 await commit ( page ) ;
988906
989907 await page . waitForSelector ( getEditorSelector ( 1 ) ) ;
@@ -1014,12 +932,7 @@ describe("Ink Editor", () => {
1014932
1015933 const x = rect . x + 20 ;
1016934 const y = rect . y + 20 ;
1017- const clickHandle = await waitForPointerUp ( page ) ;
1018- await page . mouse . move ( x , y ) ;
1019- await page . mouse . down ( ) ;
1020- await page . mouse . move ( x + 50 , y + 50 ) ;
1021- await page . mouse . up ( ) ;
1022- await awaitPromise ( clickHandle ) ;
935+ await drawLine ( page , x , y , x + 50 , y + 50 ) ;
1023936
1024937 const svgSelector = ".canvasWrapper svg.draw" ;
1025938 const strokeWidth = await page . $eval ( svgSelector , el =>
@@ -1082,14 +995,9 @@ describe("Ink Editor", () => {
1082995 page ,
1083996 `${ pageSelector } .annotationEditorLayer`
1084997 ) ;
1085- const xStart = rect . x + 10 ;
1086- const yStart = rect . y + 10 ;
1087- const clickHandle = await waitForPointerUp ( page ) ;
1088- await page . mouse . move ( xStart , yStart ) ;
1089- await page . mouse . down ( ) ;
1090- await page . mouse . move ( xStart + 10 , yStart + 10 ) ;
1091- await page . mouse . up ( ) ;
1092- await awaitPromise ( clickHandle ) ;
998+ const x = rect . x + 10 ;
999+ const y = rect . y + 10 ;
1000+ await drawLine ( page , x , y , x + 10 , y + 10 ) ;
10931001 await commit ( page ) ;
10941002 }
10951003
@@ -1148,15 +1056,10 @@ describe("Ink Editor", () => {
11481056 await switchToInk ( page ) ;
11491057
11501058 const editorLayerRect = await getRect ( page , ".annotationEditorLayer" ) ;
1151- const drawStartX = editorLayerRect . x + 100 ;
1152- const drawStartY = editorLayerRect . y + 100 ;
1153-
1154- const clickHandle = await waitForPointerUp ( page ) ;
1155- await page . mouse . move ( drawStartX , drawStartY ) ;
1156- await page . mouse . down ( ) ;
1157- await page . mouse . move ( drawStartX + 50 , drawStartY + 50 ) ;
1158- await page . mouse . up ( ) ;
1159- await awaitPromise ( clickHandle ) ;
1059+
1060+ const x = editorLayerRect . x + 100 ;
1061+ const y = editorLayerRect . y + 100 ;
1062+ await drawLine ( page , x , y , x + 50 , y + 50 ) ;
11601063 await commit ( page ) ;
11611064
11621065 const pageFinalPosition = await getRect (
@@ -1257,16 +1160,10 @@ describe("Should switch from an editor and mode to others by double clicking", (
12571160 await switchToInk ( page ) ;
12581161
12591162 const editorLayerRect = await getRect ( page , ".annotationEditorLayer" ) ;
1260- const drawStartX = editorLayerRect . x + 100 ;
1261- const drawStartY = editorLayerRect . y + 100 ;
12621163
1263- const inkSelector = getEditorSelector ( 0 ) ;
1264- const clickHandle = await waitForPointerUp ( page ) ;
1265- await page . mouse . move ( drawStartX , drawStartY ) ;
1266- await page . mouse . down ( ) ;
1267- await page . mouse . move ( drawStartX + 50 , drawStartY + 50 ) ;
1268- await page . mouse . up ( ) ;
1269- await awaitPromise ( clickHandle ) ;
1164+ const x = editorLayerRect . x + 100 ;
1165+ const y = editorLayerRect . y + 100 ;
1166+ await drawLine ( page , x , y , x + 50 , y + 50 ) ;
12701167 await commit ( page ) ;
12711168
12721169 await switchToEditor ( "FreeText" , page ) ;
@@ -1286,6 +1183,7 @@ describe("Should switch from an editor and mode to others by double clicking", (
12861183
12871184 await page . waitForSelector ( "#editorInkButton:not(.toggled)" ) ;
12881185 let modeChangedHandle = await waitForAnnotationModeChanged ( page ) ;
1186+ const inkSelector = getEditorSelector ( 0 ) ;
12891187 await selectEditor ( page , inkSelector , 2 ) ;
12901188 await awaitPromise ( modeChangedHandle ) ;
12911189 await page . waitForSelector ( "#editorInkButton.toggled" ) ;
@@ -1322,12 +1220,7 @@ describe("Ink must update its color", () => {
13221220
13231221 const x = rect . x + 20 ;
13241222 const y = rect . y + 20 ;
1325- const clickHandle = await waitForPointerUp ( page ) ;
1326- await page . mouse . move ( x , y ) ;
1327- await page . mouse . down ( ) ;
1328- await page . mouse . move ( x + 50 , y + 50 ) ;
1329- await page . mouse . up ( ) ;
1330- await awaitPromise ( clickHandle ) ;
1223+ await drawLine ( page , x , y , x + 50 , y + 50 ) ;
13311224 await commit ( page ) ;
13321225
13331226 const editorSelector = getEditorSelector ( 0 ) ;
0 commit comments