@@ -977,6 +977,133 @@ it.live(
977977 ) . pipe ( Effect . provide ( layer ) ) ,
978978) ;
979979
980+ it . effect . each ( [
981+ {
982+ name : "hover burst before a click" ,
983+ inputs : [
984+ ...Array . from ( { length : 120 } , ( _ , x ) => ( {
985+ type : "mouse" ,
986+ action : "move" ,
987+ x,
988+ buttons : 0 ,
989+ button : "none" ,
990+ } ) ) ,
991+ { type : "mouse" , action : "down" , x : 119 , buttons : 1 , button : "left" } ,
992+ { type : "mouse" , action : "up" , x : 119 , buttons : 0 , button : "left" } ,
993+ ] ,
994+ expected : [
995+ { type : "mouseMoved" , x : - 1 } ,
996+ { type : "mouseMoved" , x : 119 } ,
997+ { type : "mousePressed" , x : 119 } ,
998+ { type : "mouseReleased" , x : 119 } ,
999+ ] ,
1000+ } ,
1001+ {
1002+ name : "modifier changes and drag points" ,
1003+ inputs : [
1004+ { type : "mouse" , action : "move" , x : 1 , buttons : 0 , button : "none" } ,
1005+ { type : "mouse" , action : "move" , x : 2 , buttons : 0 , button : "none" , modifiers : 2 } ,
1006+ { type : "mouse" , action : "move" , x : 3 , buttons : 0 , button : "none" , modifiers : 2 } ,
1007+ { type : "mouse" , action : "down" , x : 3 , buttons : 1 , button : "left" } ,
1008+ { type : "mouse" , action : "move" , x : 4 , buttons : 1 , button : "left" } ,
1009+ { type : "mouse" , action : "move" , x : 5 , buttons : 1 , button : "left" } ,
1010+ { type : "mouse" , action : "up" , x : 5 , buttons : 0 , button : "left" } ,
1011+ ] ,
1012+ expected : [
1013+ { type : "mouseMoved" , x : - 1 } ,
1014+ { type : "mouseMoved" , x : 1 , modifiers : 0 } ,
1015+ { type : "mouseMoved" , x : 3 , modifiers : 2 } ,
1016+ { type : "mousePressed" , x : 3 } ,
1017+ { type : "mouseMoved" , x : 4 } ,
1018+ { type : "mouseMoved" , x : 5 } ,
1019+ { type : "mouseReleased" , x : 5 } ,
1020+ ] ,
1021+ } ,
1022+ {
1023+ name : "wheel and keyboard boundaries" ,
1024+ inputs : [
1025+ { type : "mouse" , action : "move" , x : 1 , buttons : 0 , button : "none" } ,
1026+ { type : "wheel" , x : 1 , deltaY : 20 } ,
1027+ { type : "wheel" , x : 1 , deltaY : 30 } ,
1028+ { type : "mouse" , action : "move" , x : 2 , buttons : 0 , button : "none" } ,
1029+ { type : "key" , action : "down" , key : "a" , code : "KeyA" , text : "a" } ,
1030+ { type : "mouse" , action : "move" , x : 3 , buttons : 0 , button : "none" } ,
1031+ ] ,
1032+ expected : [
1033+ { type : "mouseMoved" , x : - 1 } ,
1034+ { type : "mouseMoved" , x : 1 } ,
1035+ { type : "mouseWheel" , deltaY : 20 } ,
1036+ { type : "mouseWheel" , deltaY : 30 } ,
1037+ { type : "mouseMoved" , x : 2 } ,
1038+ { type : "keyDown" , key : "a" } ,
1039+ { type : "mouseMoved" , x : 3 } ,
1040+ ] ,
1041+ } ,
1042+ {
1043+ name : "text, navigation and resize boundaries" ,
1044+ inputs : [
1045+ { type : "mouse" , action : "move" , x : 1 , buttons : 0 , button : "none" } ,
1046+ { type : "text" , text : "typed" } ,
1047+ { type : "mouse" , action : "move" , x : 2 , buttons : 0 , button : "none" } ,
1048+ { type : "navigate" , url : "http://localhost:5173/next" } ,
1049+ { type : "mouse" , action : "move" , x : 3 , buttons : 0 , button : "none" } ,
1050+ { type : "resize" , width : 640 , height : 480 } ,
1051+ { type : "mouse" , action : "move" , x : 4 , buttons : 0 , button : "none" } ,
1052+ ] ,
1053+ expected : [
1054+ { type : "mouseMoved" , x : - 1 } ,
1055+ { type : "mouseMoved" , x : 1 } ,
1056+ { text : "typed" } ,
1057+ { type : "mouseMoved" , x : 2 } ,
1058+ { type : "mouseMoved" , x : 3 } ,
1059+ { type : "mouseMoved" , x : 4 } ,
1060+ ] ,
1061+ } ,
1062+ {
1063+ name : "ambiguous button fields" ,
1064+ inputs : [
1065+ { type : "mouse" , action : "move" , x : 1 , button : "none" } ,
1066+ { type : "mouse" , action : "move" , x : 2 , button : "none" } ,
1067+ { type : "mouse" , action : "move" , x : 3 , buttons : 0 } ,
1068+ { type : "mouse" , action : "move" , x : 4 , buttons : 0 } ,
1069+ ] ,
1070+ expected : [ - 1 , 1 , 2 , 3 , 4 ] . map ( ( x ) => ( { type : "mouseMoved" , x } ) ) ,
1071+ } ,
1072+ ] ) ( "orders streamed input correctly for $name" , ( testCase ) =>
1073+ Effect . scoped (
1074+ Effect . gen ( function * ( ) {
1075+ const { browser, tabId } = yield * ready ;
1076+ const viewer = yield * browser . attachViewer ( viewerInput ( tabId , true ) ) ;
1077+ yield * viewer . input ( { type : "takeControl" } ) ;
1078+ const session = contexts [ 0 ] ! . sessions . at ( - 1 ) ! ;
1079+ const send = session . send . getMockImplementation ( ) ! ;
1080+ const started = Promise . withResolvers < void > ( ) ;
1081+ const finish = Promise . withResolvers < void > ( ) ;
1082+ yield * Effect . addFinalizer ( ( ) => Effect . sync ( ( ) => finish . resolve ( ) ) ) ;
1083+ session . send . mockClear ( ) ;
1084+ session . send . mockImplementationOnce ( async ( method , input ) => {
1085+ started . resolve ( ) ;
1086+ await finish . promise ;
1087+ return send ( method , input ) ;
1088+ } ) ;
1089+ const running = yield * viewer
1090+ . input ( { type : "mouse" , action : "move" , x : - 1 , button : "none" , buttons : 0 } )
1091+ . pipe ( Effect . forkScoped ( { startImmediately : true } ) ) ;
1092+ yield * Effect . promise ( ( ) => started . promise ) ;
1093+ const waiting = yield * Effect . forEach ( testCase . inputs , ( input ) =>
1094+ viewer . input ( input ) . pipe ( Effect . forkScoped ( { startImmediately : true } ) ) ,
1095+ ) ;
1096+ finish . resolve ( ) ;
1097+ yield * Effect . forEach ( [ running , ...waiting ] , Fiber . join ) ;
1098+ const dispatched = session . send . mock . calls . flatMap ( ( [ method , input ] ) =>
1099+ method . startsWith ( "Input." ) ? [ input ] : [ ] ,
1100+ ) ;
1101+ expect ( dispatched ) . toHaveLength ( testCase . expected . length ) ;
1102+ expect ( dispatched ) . toMatchObject ( testCase . expected ) ;
1103+ } ) ,
1104+ ) . pipe ( Effect . provide ( layer ) ) ,
1105+ ) ;
1106+
9801107it . live ( "only the controlling viewer's copy and cut keys reach its clipboard" , ( ) =>
9811108 Effect . scoped (
9821109 Effect . gen ( function * ( ) {
0 commit comments