1313 */
1414
1515import { Click , PointDataImpl } from "../../../src/interacto" ;
16- import { createMouseEvent2 } from "../StubEvents" ;
1716import { beforeEach , describe , expect , jest , test } from "@jest/globals" ;
1817import { robot } from "interacto-nono" ;
1918import { mock } from "jest-mock-extended" ;
2019import type { FSMHandler , Logger } from "../../../src/interacto" ;
2120import type { MockProxy } from "jest-mock-extended" ;
21+ import { createMouseEvent2 } from "../StubEvents" ;
2222
2323describe ( "using a click interaction" , ( ) => {
2424 let interaction : Click ;
@@ -36,22 +36,31 @@ describe("using a click interaction", () => {
3636
3737 test ( "click on a element starts and stops the interaction Click" , ( ) => {
3838 interaction . registerToNodes ( [ canvas ] ) ;
39- canvas . click ( ) ;
39+ robot ( canvas ) . click ( { "button" : 2 } , 1 , false ) ;
4040 expect ( handler . fsmStarts ) . toHaveBeenCalledTimes ( 1 ) ;
4141 expect ( handler . fsmStops ) . toHaveBeenCalledTimes ( 1 ) ;
4242 } ) ;
4343
44+ test ( "not same button does not trigger the click" , ( ) => {
45+ interaction . registerToNodes ( [ canvas ] ) ;
46+ robot ( canvas )
47+ . mousedown ( { "button" : 2 } )
48+ . mouseup ( { "button" : 1 } ) ;
49+ expect ( handler . fsmStarts ) . not . toHaveBeenCalled ( ) ;
50+ expect ( handler . fsmStops ) . not . toHaveBeenCalled ( ) ;
51+ } ) ;
52+
4453 test ( "log interaction is ok" , ( ) => {
4554 interaction . log ( true ) ;
4655 interaction . registerToNodes ( [ canvas ] ) ;
47- canvas . click ( ) ;
56+ robot ( canvas ) . click ( undefined , 1 , false ) ;
4857
49- expect ( logger . logInteractionMsg ) . toHaveBeenCalledTimes ( 4 ) ;
58+ expect ( logger . logInteractionMsg ) . toHaveBeenCalledTimes ( 5 ) ;
5059 } ) ;
5160
5261 test ( "no log interaction is ok" , ( ) => {
5362 interaction . registerToNodes ( [ canvas ] ) ;
54- canvas . click ( ) ;
63+ robot ( canvas ) . click ( undefined , 1 , false ) ;
5564
5665 expect ( logger . logInteractionMsg ) . not . toHaveBeenCalled ( ) ;
5766 } ) ;
@@ -65,18 +74,11 @@ describe("using a click interaction", () => {
6574 test ( "press on a canvas then move don't starts the interaction" , ( ) => {
6675 interaction . registerToNodes ( [ canvas ] ) ;
6776 robot ( canvas )
68- . mousedown ( )
69- . mousemove ( ) ;
77+ . mousedown ( { "button" : 3 } )
78+ . mousemove ( { "button" : 3 } ) ;
7079 expect ( handler . fsmStarts ) . not . toHaveBeenCalled ( ) ;
7180 } ) ;
7281
73- test ( "specific mouse button checking OK" , ( ) => {
74- interaction . registerToNodes ( [ canvas ] ) ;
75- robot ( ) . auxclick ( { "target" : canvas , "button" : 2 } ) ;
76- expect ( handler . fsmStarts ) . toHaveBeenCalledTimes ( 1 ) ;
77- expect ( handler . fsmStops ) . toHaveBeenCalledTimes ( 1 ) ;
78- } ) ;
79-
8082 test ( "click Data" , ( ) => {
8183 const data = new PointDataImpl ( ) ;
8284 const expected = new PointDataImpl ( ) ;
@@ -106,7 +108,8 @@ describe("using a click interaction", () => {
106108 handler . fsmStops = jest . fn ( ( ) => {
107109 data . copy ( interaction . data ) ;
108110 } ) ;
109- interaction . processEvent ( createMouseEvent2 ( "click" , expected ) ) ;
111+ interaction . processEvent ( createMouseEvent2 ( "mousedown" , expected ) ) ;
112+ interaction . processEvent ( createMouseEvent2 ( "mouseup" , expected ) ) ;
110113 expect ( data ) . toStrictEqual ( expected ) ;
111114 } ) ;
112115
@@ -117,7 +120,8 @@ describe("using a click interaction", () => {
117120 data . copy ( interaction . data ) ;
118121 } ) ;
119122 interaction . registerToNodes ( [ canvas ] ) ;
120- robot ( ) . click ( { "target" : canvas , "button" : 1 , "screenX" : 111 , "screenY" : 222 , "clientX" : 11 , "clientY" : 22 } ) ;
123+ robot ( ) . click ( { "target" : canvas , "button" : 1 , "screenX" : 111 , "screenY" : 222 , "clientX" : 11 , "clientY" : 22 } , 1 , false ) ;
124+
121125 expect ( data . clientX ) . toBe ( 11 ) ;
122126 expect ( data . clientY ) . toBe ( 22 ) ;
123127 expect ( data . screenX ) . toBe ( 111 ) ;
@@ -129,7 +133,8 @@ describe("using a click interaction", () => {
129133 const newHandler = mock < FSMHandler > ( ) ;
130134 interaction . fsm . addHandler ( newHandler ) ;
131135 interaction . registerToNodes ( [ canvas ] ) ;
132- robot ( ) . click ( { "target" : canvas , "button" : 1 , "screenX" : 111 , "screenY" : 222 , "clientX" : 11 , "clientY" : 22 } ) ;
136+ robot ( ) . click ( { "target" : canvas , "button" : 1 , "screenX" : 111 , "screenY" : 222 , "clientX" : 11 , "clientY" : 22 } , 1 , false ) ;
137+
133138 expect ( newHandler . fsmReinit ) . toHaveBeenCalledTimes ( 1 ) ;
134139 expect ( interaction . data . clientX ) . toBe ( 0 ) ;
135140 expect ( interaction . data . clientY ) . toBe ( 0 ) ;
0 commit comments