Skip to content

Commit

Permalink
test: 修复单测
Browse files Browse the repository at this point in the history
  • Loading branch information
lijinke666 committed Feb 20, 2024
1 parent 37e6be5 commit eb5ac45
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -411,37 +411,37 @@ exports[`SpreadSheet Custom Cell Style Tests TableSheet Custom Cell Style Tests
Array [
Object {
"height": 30,
"id": "root[&]地区",
"id": "root[&]area",
"width": 180,
},
Object {
"height": 30,
"id": "root[&]地区[&]省份",
"id": "root[&]area[&]province",
"width": 100,
},
Object {
"height": 30,
"id": "root[&]地区[&]城市",
"id": "root[&]area[&]city",
"width": 80,
},
Object {
"height": 60,
"id": "root[&]类型",
"id": "root[&]type",
"width": 119.8,
},
Object {
"height": 30,
"id": "root[&]金额",
"id": "root[&]money",
"width": 210,
},
Object {
"height": 30,
"id": "root[&]金额[&]价格",
"id": "root[&]money[&]price",
"width": 90,
},
Object {
"height": 30,
"id": "root[&]金额[&]数量",
"id": "root[&]money[&]number",
"width": 120,
},
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('SpreadSheet Custom Cell Style Tests', () => {
});

afterEach(() => {
// s2.destroy();
s2.destroy();
});

test('should render default cell style', () => {
Expand Down
16 changes: 7 additions & 9 deletions packages/s2-core/__tests__/spreadsheet/custom-grid-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ describe('SpreadSheet Custom Grid Tests', () => {
expect(s2.interaction.getActiveCells()).toHaveLength(1);
// 高亮子节点
expectHighlightActiveNodes(s2, [
'root[&]自定义节点 a-1[&]自定义节点 a-1-1[&]指标1',
'root[&]自定义节点 a-1[&]自定义节点 a-1-1[&]指标2',
'root[&]自定义节点 a-1[&]自定义节点 a-1-2',
'root[&]a-1[&]a-1-1[&]measure-1',
'root[&]a-1[&]a-1-1[&]measure-2',
'root[&]a-1[&]a-1-2',
]);

// 取消选中 a - 1
Expand Down Expand Up @@ -319,9 +319,9 @@ describe('SpreadSheet Custom Grid Tests', () => {
expect(s2.interaction.getActiveCells()).toHaveLength(1);
// 高亮子节点
expectHighlightActiveNodes(s2, [
'root[&]自定义节点 a-1[&]自定义节点 a-1-1[&]指标1',
'root[&]自定义节点 a-1[&]自定义节点 a-1-1[&]指标2',
'root[&]自定义节点 a-1[&]自定义节点 a-1-2',
'root[&]a-1[&]a-1-1[&]measure-1',
'root[&]a-1[&]a-1-1[&]measure-2',
'root[&]a-1[&]a-1-2',
]);

// 取消选中 a - 1
Expand Down Expand Up @@ -374,9 +374,7 @@ describe('SpreadSheet Custom Grid Tests', () => {
});

test('should hide columns', async () => {
const hiddenColumns = [
'root[&]自定义节点 a-1[&]自定义节点 a-1-1[&]指标2',
];
const hiddenColumns = ['root[&]a-1[&]a-1-1[&]measure-2'];

await waitForRender(s2, () => {
s2.interaction.hideColumns(hiddenColumns);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ describe('TableSheet Custom Tests', () => {
expect(s2.interaction.getActiveCells()).toHaveLength(1);
// 高亮子节点
expectHighlightActiveNodes(s2, [
'root[&]地区[&]省份',
'root[&]地区[&]城市',
'root[&]area[&]province',
'root[&]area[&]city',
]);

// 取消选中 a - 1
Expand All @@ -138,7 +138,7 @@ describe('TableSheet Custom Tests', () => {
});

test('should hide columns', async () => {
const hiddenColumns = ['root[&]金额[&]价格'];
const hiddenColumns = ['root[&]money[&]price'];

await waitForRender(s2, () => {
s2.interaction.hideColumns(hiddenColumns);
Expand Down
8 changes: 2 additions & 6 deletions packages/s2-core/__tests__/spreadsheet/hidden-columns-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,7 @@ describe('SpreadSheet Hidden Columns Tests', () => {
});

test('should hide columns for multiple columns', async () => {
const hiddenColumns = [
'root[&]自定义节点 a-1[&]自定义节点 a-1-1[&]指标1',
];
const hiddenColumns = ['root[&]a-1[&]a-1-1[&]province'];

tableSheet.setDataCfg({
...mockTableDataConfig,
Expand Down Expand Up @@ -528,9 +526,7 @@ describe('SpreadSheet Hidden Columns Tests', () => {
});

test('should hide columns for multiple columns', async () => {
const hiddenColumns = [
'root[&]自定义节点 a-1[&]自定义节点 a-1-1[&]指标1',
];
const hiddenColumns = ['root[&]a-1[&]a-1-1[&]measure-1'];

pivotSheet.setDataCfg({
...mockPivotDataConfig,
Expand Down
3 changes: 3 additions & 0 deletions packages/s2-core/__tests__/unit/facet/pivot-facet-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ jest.mock('@/sheet-type', () => {
[FrozenGroupType.FROZEN_TRAILING_COL]: {},
},
cornerBBox: {},
getHeaderNodes: jest.fn().mockReturnValue([]),
},
getCanvasElement: () =>
container.getContextService().getDomElement() as HTMLCanvasElement,
Expand Down Expand Up @@ -153,6 +154,8 @@ describe('Pivot Mode Facet Test', () => {
});
const facet = new PivotFacet(s2);

s2.facet = facet;

beforeEach(async () => {
await s2.container.ready;
});
Expand Down
1 change: 1 addition & 0 deletions packages/s2-core/__tests__/unit/facet/table-facet-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ jest.mock('@/sheet-type', () => {
getColNodes: jest.fn().mockReturnValue([]),
getHiddenColumnsInfo: jest.fn(),
getColNodeHeight: jest.fn(),
getHeaderNodes: jest.fn().mockReturnValue([]),
},
dataSet: {
isEmpty: jest.fn(),
Expand Down
8 changes: 5 additions & 3 deletions packages/s2-core/src/data-set/base-data-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,11 @@ export abstract class BaseDataSet {
public getFieldName(field: CustomHeaderField, defaultValue?: string): string {
const realField = this.getField(field);
// 兼容自定义行列头场景
const headerNode = this.spreadsheet.facet?.getHeaderNodes().find((node) => {
return node.field === realField && node?.extra?.isCustomNode;
});
const headerNode = this.spreadsheet?.facet
?.getHeaderNodes()
.find((node) => {
return node.field === realField && node?.extra?.isCustomNode;
});
const realDefaultValue =
headerNode?.value ||
(isString(field) ? field : field?.title) ||
Expand Down

0 comments on commit eb5ac45

Please sign in to comment.