Skip to content

Commit

Permalink
fix(core): only do compatibility of shit + scroll on Windows
Browse files Browse the repository at this point in the history
- add test case
  • Loading branch information
d2FuZ3h1ZG9uZw committed May 12, 2023
1 parent d9fda2f commit 96f9169
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions packages/s2-core/__tests__/spreadsheet/scroll-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ describe('Scroll Tests', () => {
).toBeFalsy();
});

test('should scroll horizontally when shift key is held', async () => {
test('should scroll horizontally when shift key is held on Windows', async () => {
s2.setOptions({
frozenRowHeader: true,
style: {
Expand Down Expand Up @@ -671,13 +671,41 @@ describe('Scroll Tests', () => {
shiftKey: true,
});

canvas.dispatchEvent(wheelEvent);
Object.defineProperty(window.navigator, 'userAgent', {
value: 'Windows',
configurable: true,
writable: true,
});

canvas.dispatchEvent(wheelEvent);
await sleep(200);

expect(onScroll).toHaveBeenCalled();
});

test('should not scroll horizontally when shift key is held on macOS', async () => {
const onScroll = jest.fn((...args) => {
expect(args[0].rowHeaderScrollX).toBeGreaterThan(0);
expect(args[0].scrollX).toBe(0);
expect(args[0].scrollY).toBe(0);
});

const wheelEvent = new WheelEvent('wheel', {
deltaX: 0,
deltaY: 20,
shiftKey: true,
});

Object.defineProperty(window.navigator, 'userAgent', {
value: 'Mac OS',
configurable: true,
writable: true,
});

canvas.dispatchEvent(wheelEvent);
await sleep(200);
expect(onScroll).not.toHaveBeenCalled();
});

it('should not change init body overscrollBehavior style when render and destroyed', () => {
document.body.style.overscrollBehavior = 'none';

Expand Down

0 comments on commit 96f9169

Please sign in to comment.