Skip to content

Commit

Permalink
test: 修复单测
Browse files Browse the repository at this point in the history
  • Loading branch information
lijinke666 committed Nov 10, 2023
1 parent 29ac885 commit 10fa34a
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Array [
"value": "类型",
},
Object {
"height": 30,
"height": 100,
"value": "金额",
},
Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('TableSheet Custom Tests', () => {
});

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

test('should render custom layout column nodes', () => {
Expand Down
8 changes: 2 additions & 6 deletions packages/s2-core/__tests__/spreadsheet/layout-hooks-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,6 @@ const s2Options: S2Options = {
collapseAll: false,
width: 120,
},
colCell: {
widthByField: {},
heightByField: {},
},
dataCell: {
height: 32,
},
Expand All @@ -164,7 +160,7 @@ describe('layout hooks spec', () => {

test('layout arrange hook', () => {
const rowLeafNodes = s2.facet.getRowLeafNodes();
let arrangeValues;
let arrangeValues: string[];

if (s2.isHierarchyTreeType()) {
arrangeValues = rowLeafNodes.slice(2, 5).map((v) => v.value);
Expand All @@ -177,7 +173,7 @@ describe('layout hooks spec', () => {

test('layout hierarchy hook', () => {
const rowLeafNodes = s2.facet.getRowLeafNodes();
let addValues;
let addValues: string[];

if (s2.isHierarchyTreeType()) {
addValues = rowLeafNodes.slice(5, 8).map((v) => v.value);
Expand Down
5 changes: 4 additions & 1 deletion packages/s2-core/__tests__/unit/facet/table-facet-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,22 @@ jest.mock('@/sheet-type', () => {
isTableMode: jest.fn().mockReturnValue(true),
isPivotMode: jest.fn(),
getTotalsConfig: jest.fn(),
getLayoutWidthType: jest.fn().mockRejectedValue('adaptive'),
getLayoutWidthType: jest.fn().mockReturnValue('adaptive'),
emit: jest.fn(),
facet: {
getColLeafNodes: jest.fn().mockReturnValue([]),
getColNodes: jest.fn().mockReturnValue([]),
getHiddenColumnsInfo: jest.fn(),
getColNodeHeight: jest.fn(),
},
isHierarchyTreeType: jest.fn(),
getCanvasElement: () =>
container.getContextService().getDomElement() as HTMLCanvasElement,
hideTooltip: jest.fn(),
interaction: {
clearHoverTimer: jest.fn(),
getState: jest.fn(),
getCells: jest.fn(() => []),
},
enableFrozenHeaders() {
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { omit } from 'lodash';
import { createFakeSpreadSheet, sleep } from 'tests/util/helpers';
import {
createFakeSpreadSheet,
createFederatedMouseEvent,
sleep,
} from 'tests/util/helpers';
import type { GEvent } from '@/index';
import type { CellEventTarget, S2Options, ViewMeta } from '@/common/interface';
import { HoverEvent } from '@/interaction/base-interaction/hover';
Expand Down Expand Up @@ -47,7 +51,7 @@ describe('Interaction Hover Tests', () => {

return mockCell;
},
isTextOverflowing: jest.fn(),
isTextOverflowing: jest.fn(() => true),
getActualText: () => ELLIPSIS_SYMBOL,
getFieldValue: () => '',
cellType: 'dataCell',
Expand Down Expand Up @@ -167,12 +171,9 @@ describe('Interaction Hover Tests', () => {
// click date cell before will trigger hover focus
await sleep(HOVER_FOCUS_DURATION - 200);

const mockEvent = {
preventDefault: () => {},
originalEvent: {},
};
const event = createFederatedMouseEvent(s2, OriginEventType.MOUSE_DOWN);

s2.container.emit(OriginEventType.MOUSE_DOWN, mockEvent);
s2.container.dispatchEvent(event);

await sleep(200);

Expand Down Expand Up @@ -305,9 +306,9 @@ describe('Interaction Hover Tests', () => {

return mockCell;
},
getActualText: () => 'test',
getActualText: () => `test`,
getFieldValue: () => 'test',
isTextOverflowing: jest.fn(),
isTextOverflowing: jest.fn(() => false),
cellType: 'dataCell',
}) as any;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ describe('Interaction Event Controller Tests', () => {
);
spreadsheet.interaction.reset = jest.fn();
spreadsheet.interaction.removeIntercepts = jest.fn();
spreadsheet.interaction.hasIntercepts = jest.fn();
spreadsheet.interaction.intercepts.clear();
spreadsheet.getCell = () => ({}) as any;
spreadsheet.options = s2Options;
Expand Down Expand Up @@ -483,6 +484,7 @@ describe('Interaction Event Controller Tests', () => {
spreadsheet.interaction.addIntercepts([
InterceptType.DATA_CELL_BRUSH_SELECTION,
]);
spreadsheet.interaction.hasIntercepts = jest.fn(() => true);
const reset = jest.fn();

spreadsheet.on(S2Event.GLOBAL_RESET, reset);
Expand All @@ -491,6 +493,7 @@ describe('Interaction Event Controller Tests', () => {

expect(spreadsheet.interaction.removeIntercepts).toHaveBeenCalled();
expect(reset).not.toHaveBeenCalled();
spreadsheet.interaction.hasIntercepts = jest.fn();
});

test('should not reset if current mouse on the canvas container', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ describe('Interaction Row Column Resize Tests', () => {
height: 0,
isResizeArea: true,
effect: ResizeAreaEffect.Cell,
resizedWidth: 40,
resizedWidth: 42,
resizedHeight: 0,
size: 3,
meta: {
Expand Down Expand Up @@ -304,9 +304,9 @@ describe('Interaction Row Column Resize Tests', () => {
info: resizeInfo,
style: {
colCell: {
width: 40,
width: resizeInfo.resizedWidth!,
widthByField: {
[resizeInfo.meta.field!]: 40,
[resizeInfo.meta.field!]: resizeInfo.resizedWidth!,
},
},
},
Expand All @@ -317,11 +317,11 @@ describe('Interaction Row Column Resize Tests', () => {

// update style options
expect(s2.options.style!.colCell).toEqual({
width: 40,
width: resizeInfo.resizedWidth!,
height: 30,
heightByField: null,
widthByField: {
[resizeInfo.meta.field!]: 40,
[resizeInfo.meta.field!]: resizeInfo.resizedWidth!,
},
});

Expand Down Expand Up @@ -768,7 +768,7 @@ describe('Interaction Row Column Resize Tests', () => {
expect(disable).toHaveBeenCalledWith({
...resizeInfo,
resizedWidth: 0,
resizedHeight: 16,
resizedHeight: 40,
});

emitResizeEvent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ describe('PivotSheet Tests', () => {
.mockImplementation((_, __, options) => {
return {
forceRender: options?.forceRender,
};
} as unknown as void;
});

const nodeMeta = new Node({ id: '1', field: '1', value: 'testValue' });
Expand Down
2 changes: 1 addition & 1 deletion packages/s2-core/src/facet/pivot-facet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ export class PivotFacet extends BaseFacet {
}

private getRowNodeHeight(rowNode: Node): number {
const rowCell = new RowCell(rowNode, rowNode.spreadsheet, {});
const rowCell = new RowCell(rowNode, this.spreadsheet, {});
const defaultHeight = this.getRowCellHeight(rowNode);

return this.getCellAdaptiveHeight(rowCell, defaultHeight);
Expand Down
6 changes: 3 additions & 3 deletions packages/s2-core/src/interaction/event-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,13 @@ export class EventController {
const { interaction } = this.spreadsheet;

if (
interaction.hasIntercepts([
interaction?.hasIntercepts?.([
InterceptType.DATA_CELL_BRUSH_SELECTION,
InterceptType.COL_CELL_BRUSH_SELECTION,
InterceptType.ROW_CELL_BRUSH_SELECTION,
])
) {
interaction.removeIntercepts([
interaction?.removeIntercepts?.([
InterceptType.DATA_CELL_BRUSH_SELECTION,
InterceptType.ROW_CELL_BRUSH_SELECTION,
InterceptType.COL_CELL_BRUSH_SELECTION,
Expand All @@ -176,7 +176,7 @@ export class EventController {
}

this.spreadsheet.emit(S2Event.GLOBAL_RESET, event);
interaction.reset();
interaction?.reset();
}

private isMouseEvent(event: Event): event is MouseEvent {
Expand Down
4 changes: 2 additions & 2 deletions packages/s2-core/src/sheet-type/spread-sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ export abstract class SpreadSheet extends EE {
event: CanvasEvent | MouseEvent,
cellInfos: TooltipData[],
options?: TooltipOptions,
) {
): Promise<void> | void {
const { enable: showTooltip, content } = getTooltipOptions(this, event)!;

if (!showTooltip) {
Expand All @@ -307,7 +307,7 @@ export abstract class SpreadSheet extends EE {
},
});

this.showTooltip({
return this.showTooltip({
data: tooltipData,
position: {
x: event.clientX,
Expand Down

0 comments on commit 10fa34a

Please sign in to comment.