Skip to content

Commit

Permalink
test: 单测断言重构为 toMatchInlineSnapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
wjgogogo committed Nov 28, 2023
1 parent 49567c5 commit 34d1fc2
Show file tree
Hide file tree
Showing 2 changed files with 185 additions and 53 deletions.
45 changes: 39 additions & 6 deletions packages/s2-core/__tests__/spreadsheet/total-group-spec.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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: '家具',
Expand Down Expand Up @@ -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: '杭州市',
Expand Down
193 changes: 146 additions & 47 deletions packages/s2-core/__tests__/unit/utils/dataset/pivot-data-set-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
"四川省",
"绵阳市",
"办公用品",
"纸张",
],
]
`);
});
});

0 comments on commit 34d1fc2

Please sign in to comment.