diff --git a/packages/s2-core/__tests__/unit/utils/__snapshots__/tooltip-spec.ts.snap b/packages/s2-core/__tests__/unit/utils/__snapshots__/tooltip-spec.ts.snap index c3cd030d43..bcfd73a2c8 100644 --- a/packages/s2-core/__tests__/unit/utils/__snapshots__/tooltip-spec.ts.snap +++ b/packages/s2-core/__tests__/unit/utils/__snapshots__/tooltip-spec.ts.snap @@ -87,6 +87,32 @@ Object { } `; +exports[`Tooltip Utils Tests Tooltip Get Data Tests should get correctly data cell details 1`] = ` +Object { + "description": undefined, + "details": Array [ + Object { + "name": "number", + "value": 7789, + }, + ], + "headInfo": Object { + "cols": Array [], + "rows": Array [ + Object { + "name": undefined, + "value": "-", + }, + ], + }, + "infos": undefined, + "interpretation": undefined, + "name": null, + "summaries": Array [], + "tips": undefined, +} +`; + exports[`Tooltip Utils Tests Tooltip Get Data Tests should get custom tree row cell summary data 1`] = ` Object { "description": "指标1描述", diff --git a/packages/s2-core/__tests__/unit/utils/tooltip-spec.ts b/packages/s2-core/__tests__/unit/utils/tooltip-spec.ts index 2503d8ebc6..b830e2c50f 100644 --- a/packages/s2-core/__tests__/unit/utils/tooltip-spec.ts +++ b/packages/s2-core/__tests__/unit/utils/tooltip-spec.ts @@ -636,6 +636,30 @@ describe('Tooltip Utils Tests', () => { expect(tooltipData).toEqual(defaultTooltipData); }); + test('should get correctly data cell details', () => { + s2 = createPivotSheet(); + + const cell = createMockCellInfo('test-a'); + const tooltipData = getTooltipData({ + cellInfos: [ + getCellData(7789, false, { + sub_type: '桌子', + type: '家具', + }), + ], + options: { + enableFormat: true, + isTotals: false, + hideSummary: true, + onlyShowCellText: false, + }, + targetCell: cell.mockCell, + spreadsheet: s2, + }); + + expect(tooltipData).toMatchSnapshot(); + }); + test.each([ { count: 1, isTotalCell: true, name: '单选' }, { count: 4, isTotalCell: false, name: '多选' }, diff --git a/packages/s2-core/src/utils/tooltip.ts b/packages/s2-core/src/utils/tooltip.ts index 3232d595fa..87822b2c6f 100644 --- a/packages/s2-core/src/utils/tooltip.ts +++ b/packages/s2-core/src/utils/tooltip.ts @@ -191,9 +191,11 @@ export const getListItem = ( targetCell?: S2CellType; }, ): TooltipDetailListItem => { - const name = - spreadsheet?.dataSet.getCustomRowFieldName(targetCell!) || - spreadsheet?.dataSet?.getFieldName(field); + const defaultFieldName = spreadsheet?.dataSet?.getFieldName(field); + const name = spreadsheet.isCustomRowFields() + ? spreadsheet?.dataSet.getCustomRowFieldName(targetCell!) || + defaultFieldName + : defaultFieldName; const formatter = spreadsheet?.dataSet?.getFieldFormatter(field);