-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: 修复行头字段为空字符串时, getDimensionValues 获取数据错误的问题 (#2482)
- Loading branch information
Showing
2 changed files
with
121 additions
and
1 deletion.
There are no files selected for viewing
120 changes: 120 additions & 0 deletions
120
packages/s2-core/__tests__/spreadsheet/empty-string-values-spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import { getContainer } from 'tests/util/helpers'; | ||
import type { S2DataConfig, S2Options } from '@/common'; | ||
import { PivotSheet, SpreadSheet } from '@/sheet-type'; | ||
|
||
const s2Options: S2Options = { | ||
debug: true, | ||
width: 600, | ||
height: 400, | ||
hierarchyType: 'grid', | ||
style: { | ||
layoutWidthType: 'adaptive', | ||
cellCfg: { | ||
height: 30, | ||
}, | ||
}, | ||
}; | ||
|
||
const testDataCfg: S2DataConfig = { | ||
meta: [ | ||
{ | ||
field: 'first', | ||
name: '一级维度', | ||
}, | ||
{ | ||
field: 'second', | ||
name: '二级维度', | ||
}, | ||
{ | ||
field: 'number', | ||
name: '数值', | ||
}, | ||
], | ||
fields: { | ||
rows: ['first', 'second'], | ||
columns: [], | ||
values: ['number'], | ||
valueInCols: true, | ||
}, | ||
data: [ | ||
{ | ||
first: '', | ||
second: '维值1', | ||
number: 100, | ||
}, | ||
{ | ||
first: '', | ||
second: '维值2', | ||
number: 200, | ||
}, | ||
{ | ||
first: null, | ||
second: '维值3', | ||
number: 300, | ||
}, | ||
{ | ||
first: null, | ||
second: '维值4', | ||
number: 400, | ||
}, | ||
{ | ||
first: '非空维度', | ||
second: '维值5', | ||
number: 500, | ||
}, | ||
{ | ||
first: '非空维度', | ||
second: '维值6', | ||
number: 600, | ||
}, | ||
], | ||
}; | ||
|
||
describe('Empty String Values Tests', () => { | ||
let s2: SpreadSheet; | ||
|
||
beforeEach(() => { | ||
s2 = new PivotSheet(getContainer(), testDataCfg, s2Options); | ||
s2.render(); | ||
}); | ||
|
||
test('should get correctly first dimension values', () => { | ||
const values = s2.dataSet.getDimensionValues('first'); | ||
expect(values).toEqual(['', 'null', '非空维度']); | ||
}); | ||
|
||
test('should get correctly second dimension values', () => { | ||
const values = s2.dataSet.getDimensionValues('second'); | ||
expect(values).toEqual([ | ||
'维值1', | ||
'维值2', | ||
'维值3', | ||
'维值4', | ||
'维值5', | ||
'维值6', | ||
]); | ||
}); | ||
|
||
test('should get correctly second dimension values by specific query', () => { | ||
let values = s2.dataSet.getDimensionValues('second', { first: '' }); | ||
expect(values).toEqual(['维值1', '维值2']); | ||
|
||
values = s2.dataSet.getDimensionValues('second', { first: 'null' }); | ||
expect(values).toEqual(['维值3', '维值4']); | ||
|
||
values = s2.dataSet.getDimensionValues('second', { first: '非空维度' }); | ||
expect(values).toEqual(['维值5', '维值6']); | ||
}); | ||
|
||
test('should get correctly layout result', () => { | ||
const nodes = s2.facet.layoutResult.rowLeafNodes; | ||
expect(nodes.map((node) => node.id)).toEqual([ | ||
'root[&][&]维值1', | ||
'root[&][&]维值2', | ||
'root[&]null[&]维值3', | ||
'root[&]null[&]维值4', | ||
'root[&]非空维度[&]维值5', | ||
'root[&]非空维度[&]维值6', | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters