From dcd048780a93b72f5eb64811f3464cb5c839734d Mon Sep 17 00:00:00 2001 From: "wuding.why" Date: Fri, 17 Nov 2023 12:12:48 +0800 Subject: [PATCH] fix: optimize test case --- .../spreadsheet/hidden-columns-spec.ts | 51 +++++++------------ 1 file changed, 19 insertions(+), 32 deletions(-) diff --git a/packages/s2-core/__tests__/spreadsheet/hidden-columns-spec.ts b/packages/s2-core/__tests__/spreadsheet/hidden-columns-spec.ts index d4fae5a0dd..8774ead68e 100644 --- a/packages/s2-core/__tests__/spreadsheet/hidden-columns-spec.ts +++ b/packages/s2-core/__tests__/spreadsheet/hidden-columns-spec.ts @@ -555,38 +555,25 @@ describe('SpreadSheet Hidden Columns Tests', () => { expect(leafNodes).toHaveLength(5); }); - test('hiding the column totals should not hide the row totals', () => { - sheet.render(); - const nodeId = 'root[&]总计'; - const preRowNodes = sheet.facet.layoutResult.rowNodes; - const preColumnNodes = sheet.facet.layoutResult.colNodes; - sheet.interaction.hideColumns([nodeId]); - - expect(sheet.facet.layoutResult.rowNodes[0].id).toBe(nodeId); - expect(sheet.facet.layoutResult.rowNodes.length).toBe( - preRowNodes.length, - ); - expect(sheet.facet.layoutResult.colNodes.length).toBe( - preColumnNodes.length - 1, - ); - }); - - test('hiding the column totals should not hide the row totals tree', () => { - sheet.setOptions({ hierarchyType: 'tree' }); - sheet.render(); - const nodeId = 'root[&]总计'; - const preRowNodes = sheet.facet.layoutResult.rowNodes; - const preColumnNodes = sheet.facet.layoutResult.colNodes; - sheet.interaction.hideColumns([nodeId]); - - expect(sheet.facet.layoutResult.rowNodes[0].id).toBe(nodeId); - expect(sheet.facet.layoutResult.rowNodes.length).toBe( - preRowNodes.length, - ); - expect(sheet.facet.layoutResult.colNodes.length).toBe( - preColumnNodes.length - 1, - ); - }); + test.each(['grid', 'tree'])( + 'hiding the column totals should not hide the row totals for %s mode', + (hierarchyType: 'grid' | 'tree') => { + sheet.setOptions({ hierarchyType }); + sheet.render(); + const nodeId = 'root[&]总计'; + const preRowNodes = sheet.facet.layoutResult.rowNodes; + const preColumnNodes = sheet.facet.layoutResult.colNodes; + sheet.interaction.hideColumns([nodeId]); + + expect(sheet.facet.layoutResult.rowNodes[0].id).toBe(nodeId); + expect(sheet.facet.layoutResult.rowNodes.length).toBe( + preRowNodes.length, + ); + expect(sheet.facet.layoutResult.colNodes.length).toBe( + preColumnNodes.length - 1, + ); + }, + ); }); }); });