Skip to content

Commit

Permalink
test: 单测修复
Browse files Browse the repository at this point in the history
  • Loading branch information
wjgogogo committed Nov 24, 2023
1 parent dea9605 commit 8f4a8b5
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 27 deletions.
7 changes: 1 addition & 6 deletions packages/s2-core/__tests__/data/data-issue-292.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@
"province": "浙江",
"city": "义乌",
"type": "",
"cost": "2"
},
{
"province": "浙江",
"city": "义乌",
"type": "",
"cost": "2",
"price": "8"
},
{
Expand Down
10 changes: 5 additions & 5 deletions packages/s2-core/__tests__/unit/data-process/pivot-spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,35 +48,35 @@ describe('Pivot Table Core Data Process', () => {
data.length,
);

expect(get(indexesData, [prefix, 1, 1, 1, 1])).toEqual({
expect(get(indexesData, [prefix, 1, 1, 1, 1, 1])).toEqual({
province: '浙江省',
city: '杭州市',
type: '家具',
sub_type: '桌子',
number: 7789,
}); // 左上角
expect(get(indexesData, [prefix, 1, 1, 2, 2])).toEqual({
expect(get(indexesData, [prefix, 1, 1, 2, 2, 1])).toEqual({
province: '浙江省',
city: '杭州市',
type: '办公用品',
sub_type: '纸张',
number: 1343,
}); // 右上角
expect(get(indexesData, [prefix, 2, 4, 1, 1])).toEqual({
expect(get(indexesData, [prefix, 2, 4, 1, 1, 1])).toEqual({
province: '四川省',
city: '乐山市',
type: '家具',
sub_type: '桌子',
number: 2330,
}); // 左下角
expect(get(indexesData, [prefix, 2, 4, 2, 2])).toEqual({
expect(get(indexesData, [prefix, 2, 4, 2, 2, 1])).toEqual({
province: '四川省',
city: '乐山市',
type: '办公用品',
sub_type: '纸张',
number: 352,
}); // 右下角
expect(get(indexesData, [prefix, 1, 4, 2, 1])).toEqual({
expect(get(indexesData, [prefix, 1, 4, 2, 1, 1])).toEqual({
province: '浙江省',
city: '舟山市',
type: '办公用品',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('Custom Tree Dataset Test', () => {

test('should get empty row pivot meta', () => {
const rowPivotMeta = dataSet.rowPivotMeta;
expect([...rowPivotMeta.keys()]).toEqual([]);
expect([...rowPivotMeta.keys()]).toEqual(values);
});

test('should get correct col pivot meta', () => {
Expand All @@ -68,7 +68,7 @@ describe('Custom Tree Dataset Test', () => {
test('should get correct indexesData', () => {
const prefix = 'type[&]sub_type';
const indexesData = dataSet.indexesData;
expect(get(indexesData, [prefix, 1, 1])).toEqual({
expect(get(indexesData, [prefix, 1, 1, 1])).toEqual({
type: '家具',
sub_type: '桌子',
'measure-a': 1,
Expand All @@ -78,7 +78,7 @@ describe('Custom Tree Dataset Test', () => {
'measure-e': 5,
'measure-f': 6,
});
expect(get(indexesData, [prefix, 1, 2])).toEqual({
expect(get(indexesData, [prefix, 1, 1, 2])).toEqual({
type: '家具',
sub_type: '椅子',
'measure-a': 11,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,21 @@ describe('Pivot Mode Test When Value In Row', () => {
test('should get correct indexesData', () => {
const prefix = 'province[&]city[&]type[&]sub_type';
const indexesData = dataSet.indexesData;
expect(get(indexesData, [prefix, 1, 1, 1, 1])).toEqual({
expect(get(indexesData, [prefix, 1, 1, 1, 1, 1])).toEqual({
province: '浙江省',
city: '杭州市',
type: '家具',
sub_type: '桌子',
number: 7789,
});
expect(get(indexesData, [prefix, 1, 2, 1, 2])).toEqual({
expect(get(indexesData, [prefix, 1, 2, 1, 1, 2])).toEqual({
province: '浙江省',
city: '绍兴市',
type: '家具',
sub_type: '沙发',
number: 632,
});
expect(get(indexesData, [prefix, 2, 1, 1, 2])).toEqual({
expect(get(indexesData, [prefix, 2, 1, 1, 1, 2])).toEqual({
province: '四川省',
city: '成都市',
type: '家具',
Expand All @@ -121,6 +121,7 @@ describe('Pivot Mode Test When Value In Row', () => {
expect([...keys(sortedDimensionValues)]).toEqual([
'province',
'city',
EXTRA_FIELD,
'type',
'sub_type',
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,21 @@ describe('Pivot Dataset Test', () => {
test('should get correct indexesData', () => {
const indexesData = dataSet.indexesData;
const prefix = 'province[&]city[&]type[&]sub_type';
expect(get(indexesData, [prefix, 1, 1, 1, 1])).toEqual({
expect(get(indexesData, [prefix, 1, 1, 1, 1, 1])).toEqual({
province: '浙江省',
city: '杭州市',
type: '家具',
sub_type: '桌子',
number: 7789,
});
expect(get(indexesData, [prefix, 1, 2, 2, 1])).toEqual({
expect(get(indexesData, [prefix, 1, 2, 2, 1, 1])).toEqual({
province: '浙江省',
city: '绍兴市',
type: '办公用品',
sub_type: '笔',
number: 1304,
});
expect(get(indexesData, [prefix, 2, 1, 1, 2])).toEqual({
expect(get(indexesData, [prefix, 2, 1, 1, 2, 1])).toEqual({
province: '四川省',
city: '成都市',
type: '家具',
Expand All @@ -127,6 +127,7 @@ describe('Pivot Dataset Test', () => {
'city',
'type',
'sub_type',
EXTRA_FIELD,
]);
expect(
getDimensionsWithoutPathPre(sortedDimensionValues.province),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,30 +84,30 @@ describe('Pivot Dataset Total Test', () => {
test('should get correct indexesData', () => {
const indexesData = dataSet.indexesData;
expect(
get(indexesData, ['province[&]city[&]type[&]sub_type', 1, 1, 0, 0]),
get(indexesData, ['province[&]city[&]type[&]sub_type', 1, 1, 0, 0, 1]),
).toEqual({
province: '浙江省',
city: '杭州市',
number: 15420,
});

expect(
get(indexesData, ['province[&]city[&]type[&]sub_type', 1, 1, 2, 0]),
get(indexesData, ['province[&]city[&]type[&]sub_type', 1, 1, 2, 0, 1]),
).toEqual({
province: '浙江省',
city: '杭州市',
type: '办公用品',
number: 2288,
});
expect(
get(indexesData, ['province[&]city[&]type[&]sub_type', 2, 0, 2, 0]),
get(indexesData, ['province[&]city[&]type[&]sub_type', 2, 0, 2, 0, 1]),
).toEqual({
province: '四川省',
type: '办公用品',
number: 18479,
});
expect(
get(indexesData, ['province[&]city[&]type[&]sub_type', 0, 0, 0, 0]),
get(indexesData, ['province[&]city[&]type[&]sub_type', 0, 0, 0, 0, 1]),
).toEqual({
number: 78868,
});
Expand All @@ -120,6 +120,7 @@ describe('Pivot Dataset Total Test', () => {
'city',
'type',
'sub_type',
EXTRA_FIELD,
]);
expect(
getDimensionsWithoutPathPre(sortedDimensionValues.province),
Expand Down Expand Up @@ -153,6 +154,17 @@ describe('Pivot Dataset Total Test', () => {
TOTAL_VALUE,
TOTAL_VALUE,
]);
expect(
getDimensionsWithoutPathPre(sortedDimensionValues[EXTRA_FIELD]),
).toEqual([
'number',
'number',
'number',
'number',
'number',
'number',
'number',
]);
});
});

Expand Down
1 change: 1 addition & 0 deletions packages/s2-core/__tests__/unit/facet/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ export function getMockPivotMeta() {
sortedDimensionValues,
rowPivotMeta: rawRowPivotMeta,
colPivotMeta: rawColPivotMeta,
valueInCols: true,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ describe('PivotDataSet util test', () => {
sortedDimensionValues,
rowPivotMeta,
colPivotMeta,
valueInCols: true,
});
expect(result.paths).toHaveLength(32);
expect(get(result.indexesData, result.paths[0])).toEqual({
Expand Down Expand Up @@ -107,6 +108,7 @@ describe('PivotDataSet util test', () => {
isFirstCreate: true,
rowFields: rows,
colFields: columns,
prefix,
});
expect(result).toEqual([prefix, 1, 1, 1, 1]);
});
Expand Down
7 changes: 4 additions & 3 deletions packages/s2-core/src/data-set/pivot-data-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -584,9 +584,10 @@ export class PivotDataSet extends BaseDataSet {

const extraFields = this.getQueryExtraFields(query);

return flatMap(all.filter(Boolean), (item) =>
DataHandler.createProxyDataList(item, extraFields),
);
// 多个 extra field 有时对应的同一个对象,需要进行去重
return flatMap(uniq(all), (item) => {
return item ? DataHandler.createProxyDataList(item, extraFields) : [];
});
}

public getFieldFormatter(field: string, cellMeta?: ViewMeta): Formatter {
Expand Down

0 comments on commit 8f4a8b5

Please sign in to comment.