@@ -919,6 +919,133 @@ it.live(
919919 ) . pipe ( Effect . provide ( layer ) ) ,
920920) ;
921921
922+ it . effect . each ( [
923+ {
924+ name : "hover burst before a click" ,
925+ inputs : [
926+ ...Array . from ( { length : 120 } , ( _ , x ) => ( {
927+ type : "mouse" ,
928+ action : "move" ,
929+ x,
930+ buttons : 0 ,
931+ button : "none" ,
932+ } ) ) ,
933+ { type : "mouse" , action : "down" , x : 119 , buttons : 1 , button : "left" } ,
934+ { type : "mouse" , action : "up" , x : 119 , buttons : 0 , button : "left" } ,
935+ ] ,
936+ expected : [
937+ { type : "mouseMoved" , x : - 1 } ,
938+ { type : "mouseMoved" , x : 119 } ,
939+ { type : "mousePressed" , x : 119 } ,
940+ { type : "mouseReleased" , x : 119 } ,
941+ ] ,
942+ } ,
943+ {
944+ name : "modifier changes and drag points" ,
945+ inputs : [
946+ { type : "mouse" , action : "move" , x : 1 , buttons : 0 , button : "none" } ,
947+ { type : "mouse" , action : "move" , x : 2 , buttons : 0 , button : "none" , modifiers : 2 } ,
948+ { type : "mouse" , action : "move" , x : 3 , buttons : 0 , button : "none" , modifiers : 2 } ,
949+ { type : "mouse" , action : "down" , x : 3 , buttons : 1 , button : "left" } ,
950+ { type : "mouse" , action : "move" , x : 4 , buttons : 1 , button : "left" } ,
951+ { type : "mouse" , action : "move" , x : 5 , buttons : 1 , button : "left" } ,
952+ { type : "mouse" , action : "up" , x : 5 , buttons : 0 , button : "left" } ,
953+ ] ,
954+ expected : [
955+ { type : "mouseMoved" , x : - 1 } ,
956+ { type : "mouseMoved" , x : 1 , modifiers : 0 } ,
957+ { type : "mouseMoved" , x : 3 , modifiers : 2 } ,
958+ { type : "mousePressed" , x : 3 } ,
959+ { type : "mouseMoved" , x : 4 } ,
960+ { type : "mouseMoved" , x : 5 } ,
961+ { type : "mouseReleased" , x : 5 } ,
962+ ] ,
963+ } ,
964+ {
965+ name : "wheel and keyboard boundaries" ,
966+ inputs : [
967+ { type : "mouse" , action : "move" , x : 1 , buttons : 0 , button : "none" } ,
968+ { type : "wheel" , x : 1 , deltaY : 20 } ,
969+ { type : "wheel" , x : 1 , deltaY : 30 } ,
970+ { type : "mouse" , action : "move" , x : 2 , buttons : 0 , button : "none" } ,
971+ { type : "key" , action : "down" , key : "a" , code : "KeyA" , text : "a" } ,
972+ { type : "mouse" , action : "move" , x : 3 , buttons : 0 , button : "none" } ,
973+ ] ,
974+ expected : [
975+ { type : "mouseMoved" , x : - 1 } ,
976+ { type : "mouseMoved" , x : 1 } ,
977+ { type : "mouseWheel" , deltaY : 20 } ,
978+ { type : "mouseWheel" , deltaY : 30 } ,
979+ { type : "mouseMoved" , x : 2 } ,
980+ { type : "keyDown" , key : "a" } ,
981+ { type : "mouseMoved" , x : 3 } ,
982+ ] ,
983+ } ,
984+ {
985+ name : "text, navigation and resize boundaries" ,
986+ inputs : [
987+ { type : "mouse" , action : "move" , x : 1 , buttons : 0 , button : "none" } ,
988+ { type : "text" , text : "typed" } ,
989+ { type : "mouse" , action : "move" , x : 2 , buttons : 0 , button : "none" } ,
990+ { type : "navigate" , url : "http://localhost:5173/next" } ,
991+ { type : "mouse" , action : "move" , x : 3 , buttons : 0 , button : "none" } ,
992+ { type : "resize" , width : 640 , height : 480 } ,
993+ { type : "mouse" , action : "move" , x : 4 , buttons : 0 , button : "none" } ,
994+ ] ,
995+ expected : [
996+ { type : "mouseMoved" , x : - 1 } ,
997+ { type : "mouseMoved" , x : 1 } ,
998+ { text : "typed" } ,
999+ { type : "mouseMoved" , x : 2 } ,
1000+ { type : "mouseMoved" , x : 3 } ,
1001+ { type : "mouseMoved" , x : 4 } ,
1002+ ] ,
1003+ } ,
1004+ {
1005+ name : "ambiguous button fields" ,
1006+ inputs : [
1007+ { type : "mouse" , action : "move" , x : 1 , button : "none" } ,
1008+ { type : "mouse" , action : "move" , x : 2 , button : "none" } ,
1009+ { type : "mouse" , action : "move" , x : 3 , buttons : 0 } ,
1010+ { type : "mouse" , action : "move" , x : 4 , buttons : 0 } ,
1011+ ] ,
1012+ expected : [ - 1 , 1 , 2 , 3 , 4 ] . map ( ( x ) => ( { type : "mouseMoved" , x } ) ) ,
1013+ } ,
1014+ ] ) ( "orders streamed input correctly for $name" , ( testCase ) =>
1015+ Effect . scoped (
1016+ Effect . gen ( function * ( ) {
1017+ const { browser, tabId } = yield * ready ;
1018+ const viewer = yield * browser . attachViewer ( viewerInput ( tabId , true ) ) ;
1019+ yield * viewer . input ( { type : "takeControl" } ) ;
1020+ const session = contexts [ 0 ] ! . sessions . at ( - 1 ) ! ;
1021+ const send = session . send . getMockImplementation ( ) ! ;
1022+ const started = Promise . withResolvers < void > ( ) ;
1023+ const finish = Promise . withResolvers < void > ( ) ;
1024+ yield * Effect . addFinalizer ( ( ) => Effect . sync ( ( ) => finish . resolve ( ) ) ) ;
1025+ session . send . mockClear ( ) ;
1026+ session . send . mockImplementationOnce ( async ( method , input ) => {
1027+ started . resolve ( ) ;
1028+ await finish . promise ;
1029+ return send ( method , input ) ;
1030+ } ) ;
1031+ const running = yield * viewer
1032+ . input ( { type : "mouse" , action : "move" , x : - 1 , button : "none" , buttons : 0 } )
1033+ . pipe ( Effect . forkScoped ( { startImmediately : true } ) ) ;
1034+ yield * Effect . promise ( ( ) => started . promise ) ;
1035+ const waiting = yield * Effect . forEach ( testCase . inputs , ( input ) =>
1036+ viewer . input ( input ) . pipe ( Effect . forkScoped ( { startImmediately : true } ) ) ,
1037+ ) ;
1038+ finish . resolve ( ) ;
1039+ yield * Effect . forEach ( [ running , ...waiting ] , Fiber . join ) ;
1040+ const dispatched = session . send . mock . calls . flatMap ( ( [ method , input ] ) =>
1041+ method . startsWith ( "Input." ) ? [ input ] : [ ] ,
1042+ ) ;
1043+ expect ( dispatched ) . toHaveLength ( testCase . expected . length ) ;
1044+ expect ( dispatched ) . toMatchObject ( testCase . expected ) ;
1045+ } ) ,
1046+ ) . pipe ( Effect . provide ( layer ) ) ,
1047+ ) ;
1048+
9221049it . live ( "only the controlling viewer's copy and cut keys reach its clipboard" , ( ) =>
9231050 Effect . scoped (
9241051 Effect . gen ( function * ( ) {
0 commit comments