diff --git a/packages/s2-core/__tests__/unit/facet/header/frozen-row-spec.ts b/packages/s2-core/__tests__/unit/facet/header/frozen-row-spec.ts index b38225aad5..1acb772798 100644 --- a/packages/s2-core/__tests__/unit/facet/header/frozen-row-spec.ts +++ b/packages/s2-core/__tests__/unit/facet/header/frozen-row-spec.ts @@ -32,140 +32,73 @@ const s2 = createPivotSheet({ height: 50, }, }); -describe('Frozen Row Header Tests Grid Mode', () => { +describe('Frozen Row Header Test', () => { let facet; - beforeEach(() => { - s2.setOptions({ hierarchyType: 'grid' }); - s2.render(); - facet = s2.facet as PivotFacet; - }); - test('get header after render', () => { - expect(facet.rowHeader instanceof FrozenRowHeader).toBeTrue(); - expect(facet.rowHeader.frozenHeadGroup).toBeTruthy(); - expect(facet.rowHeader.scrollGroup).toBeTruthy(); - - expect(facet.rowHeader.frozenHeadGroup.getChildren()).toHaveLength(1); - const frozenRowCell = facet.rowHeader.frozenHeadGroup.getChildren()[0]; - - expect(frozenRowCell instanceof RowCell).toBeTrue(); - expect(frozenRowCell.meta.height).toEqual(30); - - expect(facet.rowHeader.scrollGroup.getChildren()).toHaveLength(3); - const scrollCell = facet.rowHeader.scrollGroup.getChildren()[0]; - - expect(scrollCell instanceof FrozenRowCell).toBeTrue(); - expect(frozenRowCell.meta.height).toEqual(30); - }); - - test('frozen header api is it correct?', () => { - const rowHeader = facet.rowHeader; - expect(rowHeader.getFrozenRowHeight()).toBe(30); - - expect( - rowHeader.isFrozenRow({ - rowIndex: 0, - }), - ).toBe(true); - expect( - rowHeader.isFrozenRow({ - rowIndex: -1, - }), - ).toBe(false); - - expect(rowHeader.getFrozenRowCount()).toBe(1); - }); -}); -describe('Frozen Row Header Tests Tree Mode', () => { - let facet; - beforeEach(() => { - s2.setOptions({ hierarchyType: 'tree' }); - s2.render(); - facet = s2.facet as PivotFacet; - }); - test('get header after render', () => { - expect(facet.rowHeader instanceof FrozenRowHeader).toBeTrue(); - expect(facet.rowHeader.frozenHeadGroup).toBeTruthy(); - expect(facet.rowHeader.scrollGroup).toBeTruthy(); - - expect(facet.rowHeader.frozenHeadGroup.getChildren()).toHaveLength(1); - const frozenRowCell = facet.rowHeader.frozenHeadGroup.getChildren()[0]; - - expect(frozenRowCell instanceof RowCell).toBeTrue(); - expect(frozenRowCell.meta.height).toEqual(30); - - expect(facet.rowHeader.scrollGroup.getChildren()).toHaveLength(3); - const scrollCell = facet.rowHeader.scrollGroup.getChildren()[0]; - - expect(scrollCell instanceof FrozenRowCell).toBeTrue(); - expect(frozenRowCell.meta.height).toEqual(30); - }); - - test('frozen header api is it correct?', () => { - const rowHeader = facet.rowHeader; - expect(rowHeader.getFrozenRowHeight()).toBe(30); - - expect( - rowHeader.isFrozenRow({ - rowIndex: 0, - }), - ).toBe(true); - expect( - rowHeader.isFrozenRow({ - rowIndex: -1, - }), - ).toBe(false); - - expect(rowHeader.getFrozenRowCount()).toBe(1); - }); -}); + test.each(['grid', 'tree'])( + 'frozen row header group api', + (hierarchyType: 'grid' | 'tree') => { + s2.setOptions({ hierarchyType }); + s2.render(); + facet = s2.facet as PivotFacet; -describe('Frozen Series Number Tests Tree Mode', () => { - let facet; - beforeEach(() => { - s2.setOptions({ hierarchyType: 'tree' }); - s2.render(); - facet = s2.facet as PivotFacet; - }); + expect(facet.rowHeader instanceof FrozenRowHeader).toBeTrue(); + expect(facet.rowHeader.frozenHeadGroup).toBeTruthy(); + expect(facet.rowHeader.scrollGroup).toBeTruthy(); - test('FrozenSeriesNumber Header Tests', () => { - expect(facet.rowIndexHeader instanceof FrozenSeriesNumber).toBe(true); + expect(facet.rowHeader.frozenHeadGroup.getChildren()).toHaveLength(1); + const frozenRowCell = facet.rowHeader.frozenHeadGroup.getChildren()[0]; - const seriesNumberCell = facet.rowIndexHeader.frozenHeadGroup.getChildren(); - expect(seriesNumberCell).toHaveLength(1); + expect(frozenRowCell instanceof RowCell).toBeTrue(); + expect(frozenRowCell.meta.height).toEqual(30); - expect( - facet.rowIndexHeader.scrollGroup.getChildren()[0] instanceof - SeriesNumberCell, - ).toBe(true); + expect(facet.rowHeader.scrollGroup.getChildren()).toHaveLength(3); + const scrollCell = facet.rowHeader.scrollGroup.getChildren()[0]; - expect(seriesNumberCell[0] instanceof SeriesNumberCell).toBe(true); + expect(scrollCell instanceof FrozenRowCell).toBeTrue(); + expect(frozenRowCell.meta.height).toEqual(30); - expect(seriesNumberCell[0].meta.height).toBe(30); - }); -}); - -describe('Frozen Series Number Tests Grid Mode', () => { - let facet; - beforeEach(() => { - s2.setOptions({ hierarchyType: 'grid' }); - s2.render(); - facet = s2.facet as PivotFacet; - }); + const rowHeader = facet.rowHeader; + expect(rowHeader.getFrozenRowHeight()).toBe(30); - test('FrozenSeriesNumber Header Tests', () => { - expect(facet.rowIndexHeader instanceof FrozenSeriesNumber).toBe(true); + expect( + rowHeader.isFrozenRow({ + rowIndex: 0, + }), + ).toBe(true); + expect( + rowHeader.isFrozenRow({ + rowIndex: -1, + }), + ).toBe(false); - const seriesNumberCell = facet.rowIndexHeader.frozenHeadGroup.getChildren(); - expect(seriesNumberCell).toHaveLength(1); - - expect( - facet.rowIndexHeader.scrollGroup.getChildren()[0] instanceof - SeriesNumberCell, - ).toBe(true); - - expect(seriesNumberCell[0] instanceof SeriesNumberCell).toBe(true); + expect(rowHeader.getFrozenRowCount()).toBe(1); + }, + ); +}); - expect(seriesNumberCell[0].meta.height).toBe(30); - }); +describe('Frozen Series Number Test', () => { + let facet; + test.each(['grid', 'tree'])( + 'series number test', + (hierarchyType: 'grid' | 'tree') => { + s2.setOptions({ hierarchyType }); + s2.render(); + facet = s2.facet as PivotFacet; + expect(facet.rowIndexHeader instanceof FrozenSeriesNumber).toBe(true); + + const seriesNumberCell = + facet.rowIndexHeader.frozenHeadGroup.getChildren(); + expect(seriesNumberCell).toHaveLength(1); + + expect( + facet.rowIndexHeader.scrollGroup.getChildren()[0] instanceof + SeriesNumberCell, + ).toBe(true); + + expect(seriesNumberCell[0] instanceof SeriesNumberCell).toBe(true); + + expect(seriesNumberCell[0].meta.height).toBe(30); + }, + ); }); diff --git a/packages/s2-core/__tests__/unit/facet/pivot-facet-spec.ts b/packages/s2-core/__tests__/unit/facet/pivot-facet-spec.ts index 9e5b36582e..f5608a15e0 100644 --- a/packages/s2-core/__tests__/unit/facet/pivot-facet-spec.ts +++ b/packages/s2-core/__tests__/unit/facet/pivot-facet-spec.ts @@ -485,205 +485,107 @@ describe('Pivot Mode Facet Test', () => { }); }); -describe('Pivot Mode Facet frozen entire row', () => { - const s2: SpreadSheet = new MockSpreadSheet(); - const dataSet: PivotDataSet = new MockPivotDataSet(s2); - s2.dataSet = dataSet; - s2.interaction = new RootInteraction(s2); - const facet: PivotFacet = new PivotFacet({ - spreadsheet: s2, - dataSet, - dataCell: (fct) => new DataCell(fct, s2), - ...assembleDataCfg().fields, - valueInCols: true, - ...assembleOptions({ - frozenEntireHeadRowPivot: true, - totals: { - row: { - showGrandTotals: true, - reverseLayout: true, - }, - }, - frozenColCount: 2, - frozenRowCount: 2, - frozenTrailingColCount: 2, - frozenTrailingRowCount: 2, - }), - ...DEFAULT_STYLE, - }); - - test('should get correct frozenOptions', () => { - expect(getFrozenOptionsPivot(facet.cfg)).toStrictEqual({ - frozenRowCount: 1, - frozenColCount: 0, - frozenTrailingColCount: 0, - frozenTrailingRowCount: 0, - }); - - expect( - getFrozenOptionsPivot({ - ...{ - ...facet.cfg, - showSeriesNumber: true, +describe.each(['grid', 'tree'])( + 'Pivot Mode Facet frozen entire row', + (hierarchyType: 'grid' | 'tree') => { + const s2: SpreadSheet = new MockSpreadSheet(); + const dataSet: PivotDataSet = new MockPivotDataSet(s2); + s2.dataSet = dataSet; + s2.interaction = new RootInteraction(s2); + const facet: PivotFacet = new PivotFacet({ + spreadsheet: s2, + dataSet, + dataCell: (fct) => new DataCell(fct, s2), + ...assembleDataCfg().fields, + valueInCols: true, + ...assembleOptions({ + frozenEntireHeadRowPivot: true, + totals: { + row: { + showGrandTotals: true, + reverseLayout: true, + }, }, + frozenColCount: 2, + frozenRowCount: 2, + frozenTrailingColCount: 2, + frozenTrailingRowCount: 2, }), - ).toStrictEqual({ - frozenRowCount: 1, - frozenColCount: 0, - frozenTrailingColCount: 0, - frozenTrailingRowCount: 0, + ...DEFAULT_STYLE, + hierarchyType, }); - }); - test('should get correct frozenInfo', () => { - facet.calculateFrozenGroupInfo(); - expect(facet.frozenGroupInfo).toStrictEqual({ - [FrozenGroup.FROZEN_COL]: { - width: 0, - }, - [FrozenGroup.FROZEN_ROW]: { - height: 30, - range: [0, 0], - }, - [FrozenGroup.FROZEN_TRAILING_COL]: { - width: 0, - }, - [FrozenGroup.FROZEN_TRAILING_ROW]: { - height: 0, - }, - }); - }); + test('should get correct frozenOptions', () => { + expect(getFrozenOptionsPivot(facet.cfg)).toStrictEqual({ + frozenRowCount: 1, + frozenColCount: 0, + frozenTrailingColCount: 0, + frozenTrailingRowCount: 0, + }); - test('should get correct xy indexes with frozen', () => { - expect(facet.calculateXYIndexes(0, 0)).toStrictEqual({ - center: [0, 3, 1, 7], - frozenCol: [0, -1, 1, 7], - frozenRow: [0, 3, 0, 0], - frozenTrailingCol: [4, 3, 1, 7], - frozenTrailingRow: [0, 3, 8, 7], - }); - expect(facet.calculateXYIndexes(110, 30)).toStrictEqual({ - center: [1, 3, 2, 7], - frozenCol: [0, -1, 2, 7], - frozenRow: [1, 3, 0, 0], - frozenTrailingCol: [4, 3, 2, 7], - frozenTrailingRow: [1, 3, 8, 7], + expect( + getFrozenOptionsPivot({ + ...{ + ...facet.cfg, + showSeriesNumber: true, + }, + }), + ).toStrictEqual({ + frozenRowCount: 1, + frozenColCount: 0, + frozenTrailingColCount: 0, + frozenTrailingRowCount: 0, + }); }); - }); - test('should get correct indexes with row height gt canvas height', () => { - const originHeight = facet.panelBBox.viewportHeight; - facet.panelBBox.viewportHeight = 10; - expect(facet.calculateXYIndexes(0, 0)).toStrictEqual({ - center: [0, 3, 1, 0], - frozenCol: [0, -1, 1, 0], - frozenRow: [0, 3, 0, 0], - frozenTrailingCol: [4, 3, 1, 0], - frozenTrailingRow: [0, 3, 8, 7], - }); - // reset - facet.panelBBox.viewportHeight = originHeight; - }); -}); - -describe('Pivot Mode Facet frozen entire row tree mode', () => { - const s2: SpreadSheet = new MockSpreadSheet(); - const dataSet: PivotDataSet = new MockPivotDataSet(s2); - s2.dataSet = dataSet; - s2.interaction = new RootInteraction(s2); - const facet: PivotFacet = new PivotFacet({ - spreadsheet: s2, - dataSet, - dataCell: (fct) => new DataCell(fct, s2), - ...assembleDataCfg().fields, - valueInCols: true, - ...assembleOptions({ - frozenEntireHeadRowPivot: true, - totals: { - row: { - showGrandTotals: true, - reverseLayout: true, + test('should get correct frozenInfo', () => { + facet.calculateFrozenGroupInfo(); + expect(facet.frozenGroupInfo).toStrictEqual({ + [FrozenGroup.FROZEN_COL]: { + width: 0, }, - }, - frozenColCount: 2, - frozenRowCount: 2, - frozenTrailingColCount: 2, - frozenTrailingRowCount: 2, - }), - ...DEFAULT_STYLE, - hierarchyType: 'tree', - }); - - test('should get correct frozenOptions', () => { - expect(getFrozenOptionsPivot(facet.cfg)).toStrictEqual({ - frozenRowCount: 1, - frozenColCount: 0, - frozenTrailingColCount: 0, - frozenTrailingRowCount: 0, - }); - - expect( - getFrozenOptionsPivot({ - ...{ - ...facet.cfg, - showSeriesNumber: true, + [FrozenGroup.FROZEN_ROW]: { + height: 30, + range: [0, 0], }, - }), - ).toStrictEqual({ - frozenRowCount: 1, - frozenColCount: 0, - frozenTrailingColCount: 0, - frozenTrailingRowCount: 0, - }); - }); - - test('should get correct frozenInfo', () => { - facet.calculateFrozenGroupInfo(); - expect(facet.frozenGroupInfo).toStrictEqual({ - [FrozenGroup.FROZEN_COL]: { - width: 0, - }, - [FrozenGroup.FROZEN_ROW]: { - height: 30, - range: [0, 0], - }, - [FrozenGroup.FROZEN_TRAILING_COL]: { - width: 0, - }, - [FrozenGroup.FROZEN_TRAILING_ROW]: { - height: 0, - }, + [FrozenGroup.FROZEN_TRAILING_COL]: { + width: 0, + }, + [FrozenGroup.FROZEN_TRAILING_ROW]: { + height: 0, + }, + }); }); - }); - test('should get correct xy indexes with frozen', () => { - expect(facet.calculateXYIndexes(0, 0)).toStrictEqual({ - center: [0, 3, 1, 7], - frozenCol: [0, -1, 1, 7], - frozenRow: [0, 3, 0, 0], - frozenTrailingCol: [4, 3, 1, 7], - frozenTrailingRow: [0, 3, 8, 7], - }); - expect(facet.calculateXYIndexes(110, 30)).toStrictEqual({ - center: [1, 3, 2, 7], - frozenCol: [0, -1, 2, 7], - frozenRow: [1, 3, 0, 0], - frozenTrailingCol: [4, 3, 2, 7], - frozenTrailingRow: [1, 3, 8, 7], + test('should get correct xy indexes with frozen', () => { + expect(facet.calculateXYIndexes(0, 0)).toStrictEqual({ + center: [0, 3, 1, 7], + frozenCol: [0, -1, 1, 7], + frozenRow: [0, 3, 0, 0], + frozenTrailingCol: [4, 3, 1, 7], + frozenTrailingRow: [0, 3, 8, 7], + }); + expect(facet.calculateXYIndexes(110, 30)).toStrictEqual({ + center: [1, 3, 2, 7], + frozenCol: [0, -1, 2, 7], + frozenRow: [1, 3, 0, 0], + frozenTrailingCol: [4, 3, 2, 7], + frozenTrailingRow: [1, 3, 8, 7], + }); }); - }); - test('should get correct indexes with row height gt canvas height', () => { - const originHeight = facet.panelBBox.viewportHeight; - facet.panelBBox.viewportHeight = 10; - expect(facet.calculateXYIndexes(0, 0)).toStrictEqual({ - center: [0, 3, 1, 0], - frozenCol: [0, -1, 1, 0], - frozenRow: [0, 3, 0, 0], - frozenTrailingCol: [4, 3, 1, 0], - frozenTrailingRow: [0, 3, 8, 7], + test('should get correct indexes with row height gt canvas height', () => { + const originHeight = facet.panelBBox.viewportHeight; + facet.panelBBox.viewportHeight = 10; + expect(facet.calculateXYIndexes(0, 0)).toStrictEqual({ + center: [0, 3, 1, 0], + frozenCol: [0, -1, 1, 0], + frozenRow: [0, 3, 0, 0], + frozenTrailingCol: [4, 3, 1, 0], + frozenTrailingRow: [0, 3, 8, 7], + }); + // reset + facet.panelBBox.viewportHeight = originHeight; }); - // reset - facet.panelBBox.viewportHeight = originHeight; - }); -}); + }, +);