1
1
import { expect } from '@vaadin/chai-plugins' ;
2
- import { resetMouse , sendKeys , sendMouse } from '@vaadin/test-runner-commands' ;
2
+ import { resetMouse , sendKeys , sendMouse , sendMouseToElement } from '@vaadin/test-runner-commands' ;
3
3
import { click , fixtureSync , listenOnce , mousedown , nextFrame , nextRender } from '@vaadin/testing-helpers' ;
4
4
import sinon from 'sinon' ;
5
5
import '../all-imports.js' ;
@@ -899,14 +899,6 @@ describe('multi selection column', () => {
899
899
describe ( 'item-toggle event' , ( ) => {
900
900
let itemSelectionSpy , rows , checkboxes ;
901
901
902
- async function mouseClick ( element ) {
903
- const { x, y, width, height } = element . getBoundingClientRect ( ) ;
904
- await sendMouse ( {
905
- type : 'click' ,
906
- position : [ x + width / 2 , y + height / 2 ] . map ( Math . floor ) ,
907
- } ) ;
908
- }
909
-
910
902
function assertEvent ( detail ) {
911
903
expect ( itemSelectionSpy ) . to . be . calledOnce ;
912
904
expect ( itemSelectionSpy . args [ 0 ] [ 0 ] . detail ) . to . eql ( detail ) ;
@@ -935,21 +927,37 @@ describe('multi selection column', () => {
935
927
} ) ;
936
928
937
929
it ( 'should fire the event when toggling an item with click' , async ( ) => {
938
- await mouseClick ( checkboxes [ 0 ] ) ;
930
+ await sendMouseToElement ( { type : 'click' , element : checkboxes [ 0 ] } ) ;
939
931
assertEvent ( { item : grid . items [ 0 ] , selected : true , shiftKey : false } ) ;
940
932
941
- await mouseClick ( checkboxes [ 0 ] ) ;
933
+ await sendMouseToElement ( { type : 'click' , element : checkboxes [ 0 ] } ) ;
942
934
assertEvent ( { item : grid . items [ 0 ] , selected : false , shiftKey : false } ) ;
943
935
} ) ;
944
936
945
937
it ( 'should fire the event when toggling an item with Shift + click' , async ( ) => {
946
938
await sendKeys ( { down : 'Shift' } ) ;
947
- await mouseClick ( checkboxes [ 0 ] ) ;
939
+ await sendMouseToElement ( { type : 'click' , element : checkboxes [ 0 ] } ) ;
948
940
await sendKeys ( { up : 'Shift' } ) ;
949
941
assertEvent ( { item : grid . items [ 0 ] , selected : true , shiftKey : true } ) ;
950
942
951
943
await sendKeys ( { down : 'Shift' } ) ;
952
- await mouseClick ( checkboxes [ 0 ] ) ;
944
+ await sendMouseToElement ( { type : 'click' , element : checkboxes [ 0 ] } ) ;
945
+ await sendKeys ( { up : 'Shift' } ) ;
946
+ assertEvent ( { item : grid . items [ 0 ] , selected : false , shiftKey : true } ) ;
947
+ } ) ;
948
+
949
+ it ( 'should fire the event when toggling an item with mousedown + Shift + mouseup' , async ( ) => {
950
+ await sendMouseToElement ( { type : 'move' , element : checkboxes [ 0 ] } ) ;
951
+
952
+ await sendMouse ( { type : 'down' } ) ;
953
+ await sendKeys ( { down : 'Shift' } ) ;
954
+ await sendMouse ( { type : 'up' } ) ;
955
+ await sendKeys ( { up : 'Shift' } ) ;
956
+ assertEvent ( { item : grid . items [ 0 ] , selected : true , shiftKey : true } ) ;
957
+
958
+ await sendMouse ( { type : 'down' } ) ;
959
+ await sendKeys ( { down : 'Shift' } ) ;
960
+ await sendMouse ( { type : 'up' } ) ;
953
961
await sendKeys ( { up : 'Shift' } ) ;
954
962
assertEvent ( { item : grid . items [ 0 ] , selected : false , shiftKey : true } ) ;
955
963
} ) ;
@@ -981,21 +989,37 @@ describe('multi selection column', () => {
981
989
} ) ;
982
990
983
991
it ( 'should fire the event when toggling an item with click' , async ( ) => {
984
- await mouseClick ( rows [ 0 ] ) ;
992
+ await sendMouseToElement ( { type : 'click' , element : rows [ 0 ] } ) ;
985
993
assertEvent ( { item : grid . items [ 0 ] , selected : true , shiftKey : false } ) ;
986
994
987
- await mouseClick ( rows [ 0 ] ) ;
995
+ await sendMouseToElement ( { type : 'click' , element : rows [ 0 ] } ) ;
988
996
assertEvent ( { item : grid . items [ 0 ] , selected : false , shiftKey : false } ) ;
989
997
} ) ;
990
998
991
999
it ( 'should fire the event when toggling an item with Shift + click' , async ( ) => {
992
1000
await sendKeys ( { down : 'Shift' } ) ;
993
- await mouseClick ( rows [ 0 ] ) ;
1001
+ await sendMouseToElement ( { type : 'click' , element : rows [ 0 ] } ) ;
1002
+ await sendKeys ( { up : 'Shift' } ) ;
1003
+ assertEvent ( { item : grid . items [ 0 ] , selected : true , shiftKey : true } ) ;
1004
+
1005
+ await sendKeys ( { down : 'Shift' } ) ;
1006
+ await sendMouseToElement ( { type : 'click' , element : rows [ 0 ] } ) ;
1007
+ await sendKeys ( { up : 'Shift' } ) ;
1008
+ assertEvent ( { item : grid . items [ 0 ] , selected : false , shiftKey : true } ) ;
1009
+ } ) ;
1010
+
1011
+ it ( 'should fire the event when toggling an item with mousedown + Shift + mouseup' , async ( ) => {
1012
+ await sendMouseToElement ( { type : 'move' , element : rows [ 0 ] } ) ;
1013
+
1014
+ await sendMouse ( { type : 'down' } ) ;
1015
+ await sendKeys ( { down : 'Shift' } ) ;
1016
+ await sendMouse ( { type : 'up' } ) ;
994
1017
await sendKeys ( { up : 'Shift' } ) ;
995
1018
assertEvent ( { item : grid . items [ 0 ] , selected : true , shiftKey : true } ) ;
996
1019
1020
+ await sendMouse ( { type : 'down' } ) ;
997
1021
await sendKeys ( { down : 'Shift' } ) ;
998
- await mouseClick ( rows [ 0 ] ) ;
1022
+ await sendMouse ( { type : 'up' } ) ;
999
1023
await sendKeys ( { up : 'Shift' } ) ;
1000
1024
assertEvent ( { item : grid . items [ 0 ] , selected : false , shiftKey : true } ) ;
1001
1025
} ) ;
@@ -1021,17 +1045,17 @@ describe('multi selection column', () => {
1021
1045
} ) ;
1022
1046
1023
1047
it ( 'should prevent text selection when selecting a range of items with Shift + click' , async ( ) => {
1024
- await mouseClick ( rows [ 0 ] ) ;
1048
+ await sendMouseToElement ( { type : 'click' , element : rows [ 0 ] } ) ;
1025
1049
await sendKeys ( { down : 'Shift' } ) ;
1026
- await mouseClick ( rows [ 1 ] ) ;
1050
+ await sendMouseToElement ( { type : 'click' , element : rows [ 1 ] } ) ;
1027
1051
await sendKeys ( { up : 'Shift' } ) ;
1028
1052
expect ( document . getSelection ( ) . toString ( ) ) . to . be . empty ;
1029
1053
} ) ;
1030
1054
1031
1055
it ( 'should allow text selection after selecting a range of items with Shift + click' , async ( ) => {
1032
- await mouseClick ( rows [ 0 ] ) ;
1056
+ await sendMouseToElement ( { type : 'click' , element : rows [ 0 ] } ) ;
1033
1057
await sendKeys ( { down : 'Shift' } ) ;
1034
- await mouseClick ( rows [ 1 ] ) ;
1058
+ await sendMouseToElement ( { type : 'click' , element : rows [ 1 ] } ) ;
1035
1059
await sendKeys ( { up : 'Shift' } ) ;
1036
1060
1037
1061
const row2CellContent1 = getBodyCellContent ( grid , 2 , 1 ) ;
0 commit comments