From 06d8f647463eda666fb845b59031bbb751bac169 Mon Sep 17 00:00:00 2001 From: lijinke666 Date: Mon, 29 Apr 2024 15:24:23 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=9D=9E=E6=BB=9A?= =?UTF-8?q?=E5=8A=A8=E5=BC=95=E8=B5=B7=E7=9A=84=E6=B8=B2=E6=9F=93=E4=B9=9F?= =?UTF-8?q?=E4=BC=9A=E8=A7=A6=E5=8F=91=E6=BB=9A=E5=8A=A8=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../__tests__/spreadsheet/scroll-spec.ts | 34 +++++++++++++++++-- packages/s2-core/src/facet/base-facet.ts | 14 ++++---- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/packages/s2-core/__tests__/spreadsheet/scroll-spec.ts b/packages/s2-core/__tests__/spreadsheet/scroll-spec.ts index b634849f5a..d61472b23e 100644 --- a/packages/s2-core/__tests__/spreadsheet/scroll-spec.ts +++ b/packages/s2-core/__tests__/spreadsheet/scroll-spec.ts @@ -1,6 +1,8 @@ +/* eslint-disable jest/expect-expect */ /* eslint-disable jest/no-conditional-expect */ import * as mockDataConfig from 'tests/data/simple-data.json'; import { createMockCellInfo, getContainer, sleep } from 'tests/util/helpers'; +import { cloneDeep } from 'lodash'; import { ScrollBar, ScrollType } from '../../src/ui/scrollbar'; import type { CellScrollPosition } from './../../src/common/interface/scroll'; import { PivotSheet, SpreadSheet } from '@/sheet-type'; @@ -66,8 +68,8 @@ describe('Scroll Tests', () => { }); afterEach(() => { - s2.destroy(); - canvas.remove(); + // s2.destroy(); + // canvas.remove(); }); test('should hide tooltip when start scroll', () => { @@ -909,7 +911,7 @@ describe('Scroll Tests', () => { new MouseEvent('click', { clientX: x + scrollbar.position.x, // 在滚动条内点击 - clientY: y + scrollbar.position.y + scrollbar.theme.size - 2, + clientY: y + scrollbar.position.y + scrollbar.theme.size! - 2, } as MouseEventInit), ); @@ -928,4 +930,30 @@ describe('Scroll Tests', () => { containsMock.mockReset(); }, ); + + test('should not trigger scroll event when first rendered', () => { + const expectScroll = getScrollExpect(); + + expectScroll(); + }); + + test('should not trigger scroll event when options changed', () => { + const expectScroll = getScrollExpect(); + + s2.setOptions({ + hierarchyType: 'tree', + }); + s2.render(); + + expectScroll(); + }); + + test('should not trigger scroll event when data config changed', () => { + const expectScroll = getScrollExpect(); + + s2.setDataCfg(cloneDeep(mockDataConfig)); + s2.render(); + + expectScroll(); + }); }); diff --git a/packages/s2-core/src/facet/base-facet.ts b/packages/s2-core/src/facet/base-facet.ts index fd14be4e2f..618a5f013d 100644 --- a/packages/s2-core/src/facet/base-facet.ts +++ b/packages/s2-core/src/facet/base-facet.ts @@ -265,7 +265,7 @@ export abstract class BaseFacet { this.renderHeaders(); this.renderScrollBars(); this.renderBackground(); - this.dynamicRenderCell(); + this.dynamicRenderCell(true); } /** @@ -641,24 +641,24 @@ export abstract class BaseFacet { this.hRowScrollBar.on(ScrollType.ScrollChange, ({ offset }) => { const newOffset = this.getValidScrollBarOffset(offset, maxOffset); - const rowHeaderScrollX = Math.floor(newOffset); - this.setScrollOffset({ rowHeaderScrollX }); + const newRowHeaderScrollX = Math.floor(newOffset); + this.setScrollOffset({ rowHeaderScrollX: newRowHeaderScrollX }); this.rowHeader?.onRowScrollX( - rowHeaderScrollX, + newRowHeaderScrollX, KEY_GROUP_ROW_RESIZE_AREA, ); this.rowIndexHeader?.onRowScrollX( - rowHeaderScrollX, + newRowHeaderScrollX, KEY_GROUP_ROW_INDEX_RESIZE_AREA, ); this.cornerHeader.onRowScrollX( - rowHeaderScrollX, + newRowHeaderScrollX, KEY_GROUP_CORNER_RESIZE_AREA, ); const scrollBarOffsetX = this.getScrollBarOffset( - rowHeaderScrollX, + newRowHeaderScrollX, this.hRowScrollBar, ); From ea6201847b23e738bafbaaab212f274520ab75f6 Mon Sep 17 00:00:00 2001 From: lijinke666 Date: Mon, 29 Apr 2024 15:26:28 +0800 Subject: [PATCH 2/2] =?UTF-8?q?chore:=20=E8=BF=98=E5=8E=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/s2-core/__tests__/spreadsheet/scroll-spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/s2-core/__tests__/spreadsheet/scroll-spec.ts b/packages/s2-core/__tests__/spreadsheet/scroll-spec.ts index d61472b23e..2752f4b171 100644 --- a/packages/s2-core/__tests__/spreadsheet/scroll-spec.ts +++ b/packages/s2-core/__tests__/spreadsheet/scroll-spec.ts @@ -68,8 +68,8 @@ describe('Scroll Tests', () => { }); afterEach(() => { - // s2.destroy(); - // canvas.remove(); + s2.destroy(); + canvas.remove(); }); test('should hide tooltip when start scroll', () => {