diff --git a/packages/s2-core/__tests__/spreadsheet/total-group-spec.ts b/packages/s2-core/__tests__/spreadsheet/total-group-spec.ts index cc1adbd250..1b16ebdc09 100644 --- a/packages/s2-core/__tests__/spreadsheet/total-group-spec.ts +++ b/packages/s2-core/__tests__/spreadsheet/total-group-spec.ts @@ -1,4 +1,5 @@ import { getContainer } from 'tests/util/helpers'; +import { map } from 'lodash'; import { s2Options, dataCfg } from '../data/total-group-data'; import { PivotSheet } from '@/sheet-type'; import { EXTRA_FIELD, VALUE_FIELD, type S2Options } from '@/common'; @@ -20,8 +21,24 @@ describe('Total Group Dimension Test', () => { s2.render(); const { rowLeafNodes, getCellMeta } = s2.facet.layoutResult; - expect(rowLeafNodes[0].id).toEqual('root[&]总计[&]家具'); - expect(rowLeafNodes[1].id).toEqual('root[&]总计[&]办公用品'); + expect(map(rowLeafNodes, 'id')).toMatchInlineSnapshot(` + Array [ + "root[&]总计[&]家具", + "root[&]总计[&]办公用品", + "root[&]浙江省[&]小计[&]家具", + "root[&]浙江省[&]小计[&]办公用品", + "root[&]浙江省[&]杭州市[&]家具", + "root[&]浙江省[&]杭州市[&]办公用品", + "root[&]浙江省[&]舟山市[&]家具", + "root[&]浙江省[&]舟山市[&]办公用品", + "root[&]四川省[&]小计[&]家具", + "root[&]四川省[&]小计[&]办公用品", + "root[&]四川省[&]成都市[&]家具", + "root[&]四川省[&]成都市[&]办公用品", + "root[&]四川省[&]绵阳市[&]家具", + "root[&]四川省[&]绵阳市[&]办公用品", + ] + `); expect(getCellMeta(0, 0).data).toEqual({ type: '家具', @@ -52,10 +69,26 @@ describe('Total Group Dimension Test', () => { s2.render(); const { rowLeafNodes, getCellMeta } = s2.facet.layoutResult; - expect(rowLeafNodes[0].id).toEqual('root[&]总计[&]杭州市'); - expect(rowLeafNodes[1].id).toEqual('root[&]总计[&]舟山市'); - expect(rowLeafNodes[2].id).toEqual('root[&]总计[&]成都市'); - expect(rowLeafNodes[3].id).toEqual('root[&]总计[&]绵阳市'); + expect(map(rowLeafNodes, 'id')).toMatchInlineSnapshot(` + Array [ + "root[&]总计[&]杭州市", + "root[&]总计[&]舟山市", + "root[&]总计[&]成都市", + "root[&]总计[&]绵阳市", + "root[&]浙江省[&]小计[&]家具", + "root[&]浙江省[&]小计[&]办公用品", + "root[&]浙江省[&]杭州市[&]家具", + "root[&]浙江省[&]杭州市[&]办公用品", + "root[&]浙江省[&]舟山市[&]家具", + "root[&]浙江省[&]舟山市[&]办公用品", + "root[&]四川省[&]小计[&]家具", + "root[&]四川省[&]小计[&]办公用品", + "root[&]四川省[&]成都市[&]家具", + "root[&]四川省[&]成都市[&]办公用品", + "root[&]四川省[&]绵阳市[&]家具", + "root[&]四川省[&]绵阳市[&]办公用品", + ] + `); expect(getCellMeta(0, 0).data).toEqual({ city: '杭州市', diff --git a/packages/s2-core/__tests__/unit/utils/dataset/pivot-data-set-spec.ts b/packages/s2-core/__tests__/unit/utils/dataset/pivot-data-set-spec.ts index 38136e889d..89384dca37 100644 --- a/packages/s2-core/__tests__/unit/utils/dataset/pivot-data-set-spec.ts +++ b/packages/s2-core/__tests__/unit/utils/dataset/pivot-data-set-spec.ts @@ -421,55 +421,154 @@ describe('pivot-data-set utils test', () => { }); test(`should return flatten dimension values if exist total group`, () => { - const result1 = flattenDimensionValues({ - fields, - pivotMeta, - sortedDimensionValues, - dimensionValues: [MULTI_VALUE, '成都市', MULTI_VALUE, MULTI_VALUE], - }); - expect(result1).toEqual([ - ['四川省', '成都市', '家具', '桌子'], - ['四川省', '成都市', '家具', '沙发'], - ['四川省', '成都市', '办公用品', '笔'], - ['四川省', '成都市', '办公用品', '纸张'], - ]); + expect( + flattenDimensionValues({ + fields, + pivotMeta, + sortedDimensionValues, + dimensionValues: [MULTI_VALUE, '成都市', MULTI_VALUE, '纸张'], + }), + ).toMatchInlineSnapshot(` + Array [ + Array [ + "四川省", + "成都市", + "办公用品", + "纸张", + ], + ] + `); - const result2 = flattenDimensionValues({ - fields, - pivotMeta, - sortedDimensionValues, - dimensionValues: [MULTI_VALUE, MULTI_VALUE, '办公用品', MULTI_VALUE], - }); - expect(result2).toEqual([ - ['四川省', '成都市', '办公用品', '笔'], - ['四川省', '成都市', '办公用品', '纸张'], - ['四川省', '绵阳市', '办公用品', '笔'], - ['四川省', '绵阳市', '办公用品', '纸张'], - ['浙江省', '杭州市', '办公用品', '笔'], - ['浙江省', '杭州市', '办公用品', '纸张'], - ['浙江省', '舟山市', '办公用品', '笔'], - ['浙江省', '舟山市', '办公用品', '纸张'], - ]); + expect( + flattenDimensionValues({ + fields, + pivotMeta, + sortedDimensionValues, + dimensionValues: [MULTI_VALUE, '成都市', MULTI_VALUE, MULTI_VALUE], + }), + ).toMatchInlineSnapshot(` + Array [ + Array [ + "四川省", + "成都市", + "家具", + "桌子", + ], + Array [ + "四川省", + "成都市", + "家具", + "沙发", + ], + Array [ + "四川省", + "成都市", + "办公用品", + "笔", + ], + Array [ + "四川省", + "成都市", + "办公用品", + "纸张", + ], + ] + `); - const result3 = flattenDimensionValues({ - fields, - pivotMeta, - sortedDimensionValues, - dimensionValues: ['四川省', MULTI_VALUE, '办公用品', MULTI_VALUE], - }); - expect(result3).toEqual([ - ['四川省', '成都市', '办公用品', '笔'], - ['四川省', '成都市', '办公用品', '纸张'], - ['四川省', '绵阳市', '办公用品', '笔'], - ['四川省', '绵阳市', '办公用品', '纸张'], - ]); + expect( + flattenDimensionValues({ + fields, + pivotMeta, + sortedDimensionValues, + dimensionValues: [MULTI_VALUE, MULTI_VALUE, '办公用品', MULTI_VALUE], + }), + ).toMatchInlineSnapshot(` + Array [ + Array [ + "四川省", + "成都市", + "办公用品", + "笔", + ], + Array [ + "四川省", + "成都市", + "办公用品", + "纸张", + ], + Array [ + "四川省", + "绵阳市", + "办公用品", + "笔", + ], + Array [ + "四川省", + "绵阳市", + "办公用品", + "纸张", + ], + Array [ + "浙江省", + "杭州市", + "办公用品", + "笔", + ], + Array [ + "浙江省", + "杭州市", + "办公用品", + "纸张", + ], + Array [ + "浙江省", + "舟山市", + "办公用品", + "笔", + ], + Array [ + "浙江省", + "舟山市", + "办公用品", + "纸张", + ], + ] + `); - const result4 = flattenDimensionValues({ - fields, - pivotMeta, - sortedDimensionValues, - dimensionValues: [MULTI_VALUE, '成都市', MULTI_VALUE, '纸张'], - }); - expect(result4).toEqual([['四川省', '成都市', '办公用品', '纸张']]); + expect( + flattenDimensionValues({ + fields, + pivotMeta, + sortedDimensionValues, + dimensionValues: ['四川省', MULTI_VALUE, '办公用品', MULTI_VALUE], + }), + ).toMatchInlineSnapshot(` + Array [ + Array [ + "四川省", + "成都市", + "办公用品", + "笔", + ], + Array [ + "四川省", + "成都市", + "办公用品", + "纸张", + ], + Array [ + "四川省", + "绵阳市", + "办公用品", + "笔", + ], + Array [ + "四川省", + "绵阳市", + "办公用品", + "纸张", + ], + ] + `); }); });