Skip to content

Commit

Permalink
test: add unit test for right click behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
wusteven815 committed Feb 2, 2024
1 parent ac17b34 commit 5e97786
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions packages/grid/src/Grid.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,34 @@ function mouseClick(
mouseUp(column, row, component, extraMouseArgs, clientX, clientY);
}

function mouseRightClick(
column: VisibleIndex,
row: VisibleIndex,
component: Grid,
extraMouseArgs?: MouseEventInit,
clientX?: number,
clientY?: number
) {
mouseEvent(
column,
row,
component.handleContextMenu,
'mousedown',
extraMouseArgs,
clientX,
clientY
);
mouseEvent(
column,
row,
component.handleContextMenu,
'mouseup',
extraMouseArgs,
clientX,
clientY
);
}

function mouseDoubleClick(
column: VisibleIndex,
row: VisibleIndex,
Expand Down Expand Up @@ -334,6 +362,34 @@ it('ctrl clicking a selected cell should deselect it', () => {
expect(component.state.selectedRanges.length).toBe(0);
});

it('right click outside the range changes the selected ranges', () => {
const component = makeGridComponent();

mouseClick(3, 5, component);
mouseClick(3, 6, component, { ctrlKey: true });
expect(component.state.cursorColumn).toBe(3);
expect(component.state.cursorRow).toBe(6);
expect(component.state.selectedRanges[0]).toEqual(new GridRange(3, 5, 3, 6));

mouseRightClick(5, 7, component);
expect(component.state.cursorColumn).toBe(5);
expect(component.state.cursorRow).toBe(7);
expect(component.state.selectedRanges[0]).toEqual(new GridRange(5, 7, 5, 7));
});

it('right click inside the range keeps the selected ranges', () => {
const component = makeGridComponent();

mouseClick(3, 5, component);
mouseClick(3, 6, component, { ctrlKey: true });
expect(component.state.selectedRanges.length).toBe(1);
expect(component.state.selectedRanges[0]).toEqual(new GridRange(3, 5, 3, 6));

mouseRightClick(3, 5, component);
expect(component.state.selectedRanges.length).toBe(1);
expect(component.state.selectedRanges[0]).toEqual(new GridRange(3, 5, 3, 6));
});

it('handles mouse drag down to update selection', () => {
const component = makeGridComponent();
mouseDown(3, 5, component);
Expand Down

0 comments on commit 5e97786

Please sign in to comment.