From 5c20748b16b1622598069387a845219bc87a3350 Mon Sep 17 00:00:00 2001 From: lijinke666 Date: Thu, 2 Nov 2023 17:52:42 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=B6=8B=E5=8A=BF?= =?UTF-8?q?=E5=88=86=E6=9E=90=E8=A1=A8=E8=87=AA=E5=AE=9A=E4=B9=89=E5=88=97?= =?UTF-8?q?=E5=A4=B4=20tooltip=20=E5=90=8E=E9=94=99=E8=AF=AF=E7=9A=84?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E8=A1=8C=E5=A4=B4=E7=9A=84=20tooltip?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sheets/strategy-sheet/index-spec.tsx | 41 ++++++++++++++++--- .../sheets/strategy-sheet/index.tsx | 13 +++--- 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/packages/s2-react/__tests__/unit/components/sheets/strategy-sheet/index-spec.tsx b/packages/s2-react/__tests__/unit/components/sheets/strategy-sheet/index-spec.tsx index 46facbf366..66cbf1a2ef 100644 --- a/packages/s2-react/__tests__/unit/components/sheets/strategy-sheet/index-spec.tsx +++ b/packages/s2-react/__tests__/unit/components/sheets/strategy-sheet/index-spec.tsx @@ -18,7 +18,7 @@ import { SheetComponent, SheetComponentOptions, } from '../../../../../src/components'; -import { getContainer } from '../../../../util/helpers'; +import { getContainer, sleep } from '../../../../util/helpers'; import { StrategyOptions, StrategySheetDataConfig, @@ -36,6 +36,7 @@ describe(' Tests', () => { ReactDOM.unmountComponentAtNode(container); container.remove(); }); + const renderStrategySheet = ( options: SheetComponentOptions | null, dataCfg?: S2DataConfig, @@ -74,7 +75,7 @@ describe(' Tests', () => { renderStrategySheet(s2Options); - expect(s2.options.tooltip.data.content).toEqual(content); + expect(s2.options.tooltip!.data!.content).toEqual(content); }); test('should replace hierarchyType with "customTree" when rows is empty and contains custom tree items', () => { @@ -114,16 +115,21 @@ describe(' Tests', () => { renderStrategySheet(s2Options, s2DataConfig); - expect(s2.options.style.colCfg.hideMeasureColumn).toBeTruthy(); + expect(s2.options.style!.colCfg!.hideMeasureColumn).toBeTruthy(); }); test('should enable hidden columns operation', () => { renderStrategySheet(null); - expect(s2.options.tooltip.operation.hiddenColumns).toBeTruthy(); + expect(s2.options.tooltip!.operation!.hiddenColumns).toBeTruthy(); }); - test.each([CellTypes.ROW_CELL, CellTypes.COL_CELL, CellTypes.DATA_CELL])( + test.each([ + CellTypes.ROW_CELL, + CellTypes.COL_CELL, + CellTypes.DATA_CELL, + CellTypes.CORNER_CELL, + ])( 'should overwrite strategy sheet default custom tooltip and render custom %s tooltip', (cellType) => { const content = `${cellType} test content`; @@ -131,6 +137,7 @@ describe(' Tests', () => { [CellTypes.ROW_CELL]: 'row', [CellTypes.COL_CELL]: 'col', [CellTypes.DATA_CELL]: 'data', + [CellTypes.CORNER_CELL]: 'corner', }[cellType]; renderStrategySheet({ @@ -150,6 +157,28 @@ describe(' Tests', () => { }, ); + test('should get current cell custom tooltip content', () => { + renderStrategySheet({ + tooltip: { + showTooltip: true, + row: { + content: () =>
{CellTypes.ROW_CELL}
, + }, + data: { + content: () =>
{CellTypes.DATA_CELL}
, + }, + }, + }); + + jest.spyOn(s2, 'getCellType').mockReturnValueOnce(CellTypes.COL_CELL); + + s2.showTooltipWithInfo({} as GEvent, []); + + [CellTypes.ROW_CELL, CellTypes.DATA_CELL].forEach((content) => { + expect(s2.tooltip.container.innerText).not.toEqual(content); + }); + }); + test('should render correctly KPI bullet column measure text', () => { renderStrategySheet( { @@ -209,7 +238,7 @@ describe(' Tests', () => { expect(textList).toEqual([cornerExtraFieldText, '日期']); - expect(cornerNode.label).toEqual(cornerExtraFieldText); + expect(cornerNode!.label).toEqual(cornerExtraFieldText); }); test('should format corner date field', () => { diff --git a/packages/s2-react/src/components/sheets/strategy-sheet/index.tsx b/packages/s2-react/src/components/sheets/strategy-sheet/index.tsx index fcced7995d..f7252e29e0 100644 --- a/packages/s2-react/src/components/sheets/strategy-sheet/index.tsx +++ b/packages/s2-react/src/components/sheets/strategy-sheet/index.tsx @@ -1,14 +1,13 @@ -import type { S2CellType } from '@antv/s2'; +import type { S2CellType, S2DataConfig } from '@antv/s2'; import { - type ColHeaderConfig, - customMerge, Node, - type S2DataConfig, - type S2Options, SpreadSheet, - type ViewMeta, + customMerge, + type ColHeaderConfig, type MultiData, + type S2Options, type TooltipShowOptions, + type ViewMeta, } from '@antv/s2'; import { isArray, isEmpty, isFunction, isNil, size } from 'lodash'; import React from 'react'; @@ -114,7 +113,7 @@ export const StrategySheet: React.FC = React.memo( }, col: { content: (cell, tooltipOptions) => - getContent('row')(cell, tooltipOptions) ?? ( + getContent('col')(cell, tooltipOptions) ?? ( ), },