Skip to content

Commit

Permalink
fix: test case optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
wuding.why committed Nov 17, 2023
1 parent c8d7391 commit 1b32ad3
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 313 deletions.
183 changes: 58 additions & 125 deletions packages/s2-core/__tests__/unit/facet/header/frozen-row-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,140 +32,73 @@ const s2 = createPivotSheet({
height: 50,
},
});
describe('Frozen Row Header Tests Grid Mode', () => {
describe('Frozen Row Header Test', () => {
let facet;
beforeEach(() => {
s2.setOptions({ hierarchyType: 'grid' });
s2.render();
facet = s2.facet as PivotFacet;
});
test('get header after render', () => {
expect(facet.rowHeader instanceof FrozenRowHeader).toBeTrue();
expect(facet.rowHeader.frozenHeadGroup).toBeTruthy();
expect(facet.rowHeader.scrollGroup).toBeTruthy();

expect(facet.rowHeader.frozenHeadGroup.getChildren()).toHaveLength(1);
const frozenRowCell = facet.rowHeader.frozenHeadGroup.getChildren()[0];

expect(frozenRowCell instanceof RowCell).toBeTrue();
expect(frozenRowCell.meta.height).toEqual(30);

expect(facet.rowHeader.scrollGroup.getChildren()).toHaveLength(3);
const scrollCell = facet.rowHeader.scrollGroup.getChildren()[0];

expect(scrollCell instanceof FrozenRowCell).toBeTrue();
expect(frozenRowCell.meta.height).toEqual(30);
});

test('frozen header api is it correct?', () => {
const rowHeader = facet.rowHeader;
expect(rowHeader.getFrozenRowHeight()).toBe(30);

expect(
rowHeader.isFrozenRow({
rowIndex: 0,
}),
).toBe(true);
expect(
rowHeader.isFrozenRow({
rowIndex: -1,
}),
).toBe(false);

expect(rowHeader.getFrozenRowCount()).toBe(1);
});
});

describe('Frozen Row Header Tests Tree Mode', () => {
let facet;
beforeEach(() => {
s2.setOptions({ hierarchyType: 'tree' });
s2.render();
facet = s2.facet as PivotFacet;
});
test('get header after render', () => {
expect(facet.rowHeader instanceof FrozenRowHeader).toBeTrue();
expect(facet.rowHeader.frozenHeadGroup).toBeTruthy();
expect(facet.rowHeader.scrollGroup).toBeTruthy();

expect(facet.rowHeader.frozenHeadGroup.getChildren()).toHaveLength(1);
const frozenRowCell = facet.rowHeader.frozenHeadGroup.getChildren()[0];

expect(frozenRowCell instanceof RowCell).toBeTrue();
expect(frozenRowCell.meta.height).toEqual(30);

expect(facet.rowHeader.scrollGroup.getChildren()).toHaveLength(3);
const scrollCell = facet.rowHeader.scrollGroup.getChildren()[0];

expect(scrollCell instanceof FrozenRowCell).toBeTrue();
expect(frozenRowCell.meta.height).toEqual(30);
});

test('frozen header api is it correct?', () => {
const rowHeader = facet.rowHeader;
expect(rowHeader.getFrozenRowHeight()).toBe(30);

expect(
rowHeader.isFrozenRow({
rowIndex: 0,
}),
).toBe(true);
expect(
rowHeader.isFrozenRow({
rowIndex: -1,
}),
).toBe(false);

expect(rowHeader.getFrozenRowCount()).toBe(1);
});
});
test.each(['grid', 'tree'])(
'frozen row header group api',
(hierarchyType: 'grid' | 'tree') => {
s2.setOptions({ hierarchyType });
s2.render();
facet = s2.facet as PivotFacet;

describe('Frozen Series Number Tests Tree Mode', () => {
let facet;
beforeEach(() => {
s2.setOptions({ hierarchyType: 'tree' });
s2.render();
facet = s2.facet as PivotFacet;
});
expect(facet.rowHeader instanceof FrozenRowHeader).toBeTrue();
expect(facet.rowHeader.frozenHeadGroup).toBeTruthy();
expect(facet.rowHeader.scrollGroup).toBeTruthy();

test('FrozenSeriesNumber Header Tests', () => {
expect(facet.rowIndexHeader instanceof FrozenSeriesNumber).toBe(true);
expect(facet.rowHeader.frozenHeadGroup.getChildren()).toHaveLength(1);
const frozenRowCell = facet.rowHeader.frozenHeadGroup.getChildren()[0];

const seriesNumberCell = facet.rowIndexHeader.frozenHeadGroup.getChildren();
expect(seriesNumberCell).toHaveLength(1);
expect(frozenRowCell instanceof RowCell).toBeTrue();
expect(frozenRowCell.meta.height).toEqual(30);

expect(
facet.rowIndexHeader.scrollGroup.getChildren()[0] instanceof
SeriesNumberCell,
).toBe(true);
expect(facet.rowHeader.scrollGroup.getChildren()).toHaveLength(3);
const scrollCell = facet.rowHeader.scrollGroup.getChildren()[0];

expect(seriesNumberCell[0] instanceof SeriesNumberCell).toBe(true);
expect(scrollCell instanceof FrozenRowCell).toBeTrue();
expect(frozenRowCell.meta.height).toEqual(30);

expect(seriesNumberCell[0].meta.height).toBe(30);
});
});

describe('Frozen Series Number Tests Grid Mode', () => {
let facet;
beforeEach(() => {
s2.setOptions({ hierarchyType: 'grid' });
s2.render();
facet = s2.facet as PivotFacet;
});
const rowHeader = facet.rowHeader;
expect(rowHeader.getFrozenRowHeight()).toBe(30);

test('FrozenSeriesNumber Header Tests', () => {
expect(facet.rowIndexHeader instanceof FrozenSeriesNumber).toBe(true);
expect(
rowHeader.isFrozenRow({
rowIndex: 0,
}),
).toBe(true);
expect(
rowHeader.isFrozenRow({
rowIndex: -1,
}),
).toBe(false);

const seriesNumberCell = facet.rowIndexHeader.frozenHeadGroup.getChildren();
expect(seriesNumberCell).toHaveLength(1);

expect(
facet.rowIndexHeader.scrollGroup.getChildren()[0] instanceof
SeriesNumberCell,
).toBe(true);

expect(seriesNumberCell[0] instanceof SeriesNumberCell).toBe(true);
expect(rowHeader.getFrozenRowCount()).toBe(1);
},
);
});

expect(seriesNumberCell[0].meta.height).toBe(30);
});
describe('Frozen Series Number Test', () => {
let facet;
test.each(['grid', 'tree'])(
'series number test',
(hierarchyType: 'grid' | 'tree') => {
s2.setOptions({ hierarchyType });
s2.render();
facet = s2.facet as PivotFacet;
expect(facet.rowIndexHeader instanceof FrozenSeriesNumber).toBe(true);

const seriesNumberCell =
facet.rowIndexHeader.frozenHeadGroup.getChildren();
expect(seriesNumberCell).toHaveLength(1);

expect(
facet.rowIndexHeader.scrollGroup.getChildren()[0] instanceof
SeriesNumberCell,
).toBe(true);

expect(seriesNumberCell[0] instanceof SeriesNumberCell).toBe(true);

expect(seriesNumberCell[0].meta.height).toBe(30);
},
);
});
Loading

0 comments on commit 1b32ad3

Please sign in to comment.