Skip to content

Commit

Permalink
fix: 修复趋势分析表自定义列头 tooltip 后错误的使用行头的 tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
lijinke666 committed Nov 2, 2023
1 parent 82a6737 commit 5c20748
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
SheetComponent,
SheetComponentOptions,
} from '../../../../../src/components';
import { getContainer } from '../../../../util/helpers';
import { getContainer, sleep } from '../../../../util/helpers';
import {
StrategyOptions,
StrategySheetDataConfig,
Expand All @@ -36,6 +36,7 @@ describe('<StrategySheet/> Tests', () => {
ReactDOM.unmountComponentAtNode(container);
container.remove();
});

const renderStrategySheet = (
options: SheetComponentOptions | null,
dataCfg?: S2DataConfig,
Expand Down Expand Up @@ -74,7 +75,7 @@ describe('<StrategySheet/> 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', () => {
Expand Down Expand Up @@ -114,23 +115,29 @@ describe('<StrategySheet/> 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`;
const cell = {
[CellTypes.ROW_CELL]: 'row',
[CellTypes.COL_CELL]: 'col',
[CellTypes.DATA_CELL]: 'data',
[CellTypes.CORNER_CELL]: 'corner',
}[cellType];

renderStrategySheet({
Expand All @@ -150,6 +157,28 @@ describe('<StrategySheet/> Tests', () => {
},
);

test('should get current cell custom tooltip content', () => {
renderStrategySheet({
tooltip: {
showTooltip: true,
row: {
content: () => <div>{CellTypes.ROW_CELL}</div>,
},
data: {
content: () => <div>{CellTypes.DATA_CELL}</div>,
},
},
});

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(
{
Expand Down Expand Up @@ -209,7 +238,7 @@ describe('<StrategySheet/> Tests', () => {

expect(textList).toEqual([cornerExtraFieldText, '日期']);

expect(cornerNode.label).toEqual(cornerExtraFieldText);
expect(cornerNode!.label).toEqual(cornerExtraFieldText);
});

test('should format corner date field', () => {
Expand Down
13 changes: 6 additions & 7 deletions packages/s2-react/src/components/sheets/strategy-sheet/index.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -114,7 +113,7 @@ export const StrategySheet: React.FC<SheetComponentsProps> = React.memo(
},
col: {
content: (cell, tooltipOptions) =>
getContent('row')(cell, tooltipOptions) ?? (
getContent('col')(cell, tooltipOptions) ?? (
<StrategySheetColTooltip cell={cell} />
),
},
Expand Down

0 comments on commit 5c20748

Please sign in to comment.