Skip to content

Commit

Permalink
Merge branch 'master' into alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
wjgogogo committed Dec 7, 2023
2 parents ea01b03 + 02f0b3b commit 89b9f3d
Show file tree
Hide file tree
Showing 61 changed files with 1,053 additions and 854 deletions.
5 changes: 1 addition & 4 deletions packages/s2-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ const s2DataConfig = {
```ts
const s2Options = {
width: 600,
height: 600,
height: 600
}
```

Expand Down Expand Up @@ -214,9 +214,6 @@ yarn site:start
<a>
<img width="300" height="auto" alt="DingTalk" src="https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*2VvTSZmI4vYAAAAAAAAAAAAADmJ7AQ/original">
</a>
<a>
<img width="300" height="auto" alt="qq" src="https://gw.alipayobjects.com/zos/antfincdn/v4TlwgORE/qq_qr_code.JPG">
</a>
</p>

## 👬 Contributors
Expand Down
64 changes: 64 additions & 0 deletions packages/s2-core/__tests__/spreadsheet/empty-dataset-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { getContainer } from 'tests/util/helpers';
import { PivotSheet, TableSheet } from '@/sheet-type';
import type { S2Options } from '@/common/interface/s2Options';

const s2Options: S2Options = {
width: 400,
height: 400,
hierarchyType: 'grid',
};

describe('Empty Dataset Structure Tests', () => {
test('should generate placeholder for pivot mode with single dimension', () => {
const container = getContainer();

const s2DataCfg = {
fields: {
rows: ['province', 'city'],
columns: ['type'],
values: ['price'],
valueInCols: true,
},
data: [],
};
const s2 = new PivotSheet(container, s2DataCfg, s2Options);
s2.render();

// @ts-ignore
expect(s2.facet.panelScrollGroupIndexes).toEqual([0, 0, 0, 0]);
});

test('should generate placeholder for pivot mode with two dimensions', () => {
const container = getContainer();

const s2DataCfg = {
fields: {
rows: ['province', 'city'],
columns: ['type'],
values: ['price', 'cost'],
valueInCols: true,
},
data: [],
};
const s2 = new PivotSheet(container, s2DataCfg, s2Options);
s2.render();
// @ts-ignore
expect(s2.facet.panelScrollGroupIndexes).toEqual([0, 1, 0, 0]);
});

test(`shouldn't generate placeholder for table mode`, () => {
const container = getContainer();

const s2DataCfg = {
fields: {
columns: ['province', 'city', 'type', 'price', 'cost'],
},
data: [],
};
const s2 = new TableSheet(container, s2DataCfg, s2Options);
s2.render();
// @ts-ignore
expect(s2.facet.panelScrollGroupIndexes).toEqual([]);
});
});
2 changes: 1 addition & 1 deletion packages/s2-core/__tests__/unit/cell/row-cell-spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { get } from 'lodash';
import { createPivotSheet } from 'tests/util/helpers';
import type { RowCell } from '@antv/s2';
import type { Group } from '@antv/g-canvas';
import type { RowCell } from '../../../src/cell';
import type { SpreadSheet } from '@/sheet-type';
import type { TextAlign } from '@/common';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { createPivotSheet } from 'tests/util/helpers';
import { get } from 'lodash';
import { RowCell } from '../../../../src/cell/row-cell';
import { DEFAULT_OPTIONS } from '@/common';
import { FrozenRowCell, SeriesNumberCell } from '@/cell';
import { SeriesNumberCell } from '@/cell';
import { PivotRowHeader } from '@/facet/header';
import { SeriesNumberHeader } from '@/facet/header/series-number';

const s2 = createPivotSheet(
{
...DEFAULT_OPTIONS,
frozenFirstRowPivot: true,
frozenRowHeader: true,
totals: { row: { showGrandTotals: true, reverseLayout: true } },
showSeriesNumber: true,
},
Expand All @@ -30,13 +31,13 @@ describe('Frozen Row Header Test', () => {
expect(rowHeader.frozenHeadGroup.getChildren()).toHaveLength(1);
const frozenRowCell = rowHeader.frozenHeadGroup.getChildren()[0];

expect(frozenRowCell instanceof FrozenRowCell).toBeTrue();
expect(frozenRowCell instanceof RowCell).toBeTrue();
expect(get(frozenRowCell, 'meta.height')).toEqual(30);

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

expect(scrollCell instanceof FrozenRowCell).toBeTrue();
expect(scrollCell instanceof RowCell).toBeTrue();
expect(get(frozenRowCell, 'meta.height')).toEqual(30);

expect(rowHeader.getFrozenFirstRowHeight()).toBe(30);
Expand Down
31 changes: 15 additions & 16 deletions packages/s2-core/__tests__/unit/facet/pivot-facet-frozen-spec.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
/**
* pivot mode pivot test.
*/
import { createPivotSheet } from 'tests/util/helpers';
import type { IGroup } from '@antv/g-canvas';
import { get } from 'lodash';

import type { PivotSheet, SpreadSheet } from '@antv/s2';
import { FrozenRowCell, SeriesNumberCell } from '@/cell';
import { getFrozenRowCfgPivot } from '@/facet/utils';
import { createPivotSheet } from 'tests/util/helpers';
import { type PivotSheet, RowCell, SeriesNumberCell } from '../../../src';
import {
FrozenGroup,
KEY_GROUP_ROW_HEADER_FROZEN,
KEY_GROUP_ROW_SCROLL,
type S2Options,
} from '@/common';
import type { FrozenFacet } from '@/facet/frozen-facet';
import { getFrozenRowCfgPivot } from '@/facet/utils';

const defaultOptions = {
frozenFirstRowPivot: true,
const defaultS2Options: S2Options = {
frozenFirstRow: true,
totals: {
row: {
showGrandTotals: true,
reverseLayout: true,
},
},
};

const enableFrozenFistRowOption = {
frozenRowCount: 1,
frozenColCount: 0,
Expand All @@ -32,6 +32,7 @@ const enableFrozenFistRowOption = {
enableFrozenFirstRow: true,
frozenRowHeight: 30,
};

const disableFrozenFistRowOption = {
...enableFrozenFistRowOption,
frozenRowCount: 0,
Expand All @@ -43,7 +44,7 @@ let s2: PivotSheet;

describe('test getFrozenRowCfgPivot', () => {
beforeEach(() => {
s2 = createPivotSheet(defaultOptions, { useSimpleData: false });
s2 = createPivotSheet(defaultS2Options, { useSimpleData: false });
});

afterEach(() => {
Expand Down Expand Up @@ -76,7 +77,7 @@ describe('test getFrozenRowCfgPivot in tree', () => {
beforeEach(() => {
s2 = createPivotSheet(
{
...defaultOptions,
...defaultS2Options,
hierarchyType: 'tree',
pagination: {
pageSize: 0,
Expand Down Expand Up @@ -106,7 +107,7 @@ describe('test getFrozenRowCfgPivot in tree', () => {
test('showSeriesNumber has totals', () => {
s2.setOptions({
showSeriesNumber: true,
...defaultOptions,
...defaultS2Options,
});
s2.render();

Expand All @@ -118,7 +119,7 @@ describe('test getFrozenRowCfgPivot in tree', () => {

describe('test cell XYIndexes frozen first row', () => {
beforeEach(() => {
s2 = createPivotSheet(defaultOptions, { useSimpleData: false });
s2 = createPivotSheet(defaultS2Options, { useSimpleData: false });
s2.render();
});

Expand Down Expand Up @@ -338,7 +339,7 @@ describe('test frozen group', () => {
beforeEach(() => {
s2 = createPivotSheet(
{
...defaultOptions,
...defaultS2Options,
showSeriesNumber: true,
},
{ useSimpleData: false },
Expand Down Expand Up @@ -369,12 +370,10 @@ describe('test frozen group', () => {
scrollHeaderGroup as IGroup
).getChildren();
expect(frozenRowGroupChildren).toHaveLength(1);
expect(frozenRowGroupChildren[0] instanceof FrozenRowCell).toBe(true);
expect(frozenRowGroupChildren[0] instanceof RowCell).toBeTruthy();
expect(get(frozenRowGroupChildren[0], 'meta.value')).toBe('总计');
expect(scrollRowHeaderGroupChildren).toHaveLength(10);
expect(scrollRowHeaderGroupChildren[0] instanceof FrozenRowCell).toBe(
true,
);
expect(scrollRowHeaderGroupChildren[0] instanceof RowCell).toBeTruthy();
expect(get(scrollRowHeaderGroupChildren[0], 'meta.value')).toBe('浙江省');

// serial number header
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import {
sleep,
} from 'tests/util/helpers';
import type { Event as GEvent } from '@antv/g-canvas';
import type { InteractionCellHighlight } from '@antv/s2';
import type { S2Options } from '@/common/interface';
import type { InteractionCellHighlight, S2Options } from '@/common/interface';
import type { SpreadSheet } from '@/sheet-type';
import {
HOVER_FOCUS_DURATION,
Expand Down Expand Up @@ -49,6 +48,7 @@ describe('Interaction Data Cell Click Tests', () => {
s2.emit(S2Event.DATA_CELL_CLICK, {
stopPropagation() {},
} as unknown as GEvent);

expect(s2.interaction.getState()).toEqual({
cells: [mockCellInfo.mockCellMeta],
stateName: InteractionStateName.SELECTED,
Expand Down Expand Up @@ -82,9 +82,29 @@ describe('Interaction Data Cell Click Tests', () => {
s2.emit(S2Event.DATA_CELL_CLICK, {
stopPropagation() {},
} as unknown as GEvent);

expect(selected).toHaveBeenCalledWith([mockCellInfo.mockCell]);
});

// https://github.com/antvis/S2/issues/2447
test('should emit cell selected event when cell unselected', () => {
jest
.spyOn(s2.interaction, 'isSelectedCell')
.mockImplementationOnce(() => true);

const selected = jest.fn();
s2.on(S2Event.GLOBAL_SELECTED, selected);

s2.emit(S2Event.DATA_CELL_CLICK, {
stopPropagation() {},
originalEvent: {
detail: 1,
},
} as unknown as GEvent);

expect(selected).toHaveBeenCalledWith([]);
});

test('should emit link field jump event when link field text click and not show tooltip', () => {
const linkFieldJump = jest.fn();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,11 @@ describe('Interaction Event Controller Tests', () => {
maxY: 100,
} as BBox,
} as BaseFacet;

const selected = jest.fn();
const reset = jest.fn();
spreadsheet.on(S2Event.GLOBAL_RESET, reset);
spreadsheet.on(S2Event.GLOBAL_SELECTED, selected);

window.dispatchEvent(
new MouseEvent('click', {
Expand All @@ -516,6 +519,7 @@ describe('Interaction Event Controller Tests', () => {
} as MouseEventInit),
);

expect(selected).toHaveBeenCalledWith([]);
expect(reset).toHaveBeenCalled();
expect(spreadsheet.interaction.reset).toHaveBeenCalled();
});
Expand All @@ -527,13 +531,17 @@ describe('Interaction Event Controller Tests', () => {
maxY: 100,
} as BBox,
} as BaseFacet;

const selected = jest.fn();
const reset = jest.fn();
spreadsheet.on(S2Event.GLOBAL_RESET, reset);
spreadsheet.on(S2Event.GLOBAL_SELECTED, selected);

window.dispatchEvent(
new KeyboardEvent('keydown', { key: InteractionKeyboardKey.ESC }),
);

expect(selected).toHaveBeenCalledWith([]);
expect(reset).toHaveBeenCalled();
expect(spreadsheet.interaction.reset).toHaveBeenCalled();
});
Expand Down
7 changes: 3 additions & 4 deletions packages/s2-core/__tests__/unit/interaction/root-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
DataCellBrushSelection,
ColBrushSelection,
RowBrushSelection,
S2Event,
} from '@/index';
import { RootInteraction } from '@/interaction/root';
import { mergeCell, unmergeCell } from '@/utils/interaction/merge-cell';
Expand Down Expand Up @@ -170,9 +171,9 @@ describe('RootInteraction Tests', () => {

// https://github.com/antvis/S2/issues/1243
test('should multi selected header cells', () => {
const isEqualStateNameSpy = jest
jest
.spyOn(rootInteraction, 'isEqualStateName')
.mockImplementation(() => false);
.mockImplementationOnce(() => false);

const mockCellA = createMockCellInfo('test-A').mockCell;
const mockCellB = createMockCellInfo('test-B').mockCell;
Expand Down Expand Up @@ -204,8 +205,6 @@ describe('RootInteraction Tests', () => {

// 取消选中
expect(rootInteraction.getState().cells).toEqual([getCellMeta(mockCellA)]);

isEqualStateNameSpy.mockRestore();
});

test('should call merge cells', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Node } from '@antv/s2';
import type { Node } from '../../../../src';
import { CellTypes, type HeaderActionIcon } from '@/common';
import { getActionIconConfig } from '@/utils/cell/header-cell';

Expand Down
3 changes: 1 addition & 2 deletions packages/s2-core/__tests__/unit/utils/export/copy-spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import type { S2DataConfig } from '@antv/s2';
import { assembleDataCfg, assembleOptions, TOTALS_OPTIONS } from 'tests/util';
import { getContainer } from 'tests/util/helpers';
import { data as originalData, totalData } from 'tests/data/mock-dataset.json';
import { map } from 'lodash';
import type { S2DataConfig } from '../../../../src/common';
import { TableSheet, PivotSheet } from '@/sheet-type';

import {
CellTypes,
InteractionStateName,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { RowCell } from '../../../../src/cell';
import { getCellMeta } from '@/utils/interaction/select-event';
import type { RowCell } from '@/cell/row-cell';
import { CellTypes, InteractionStateName } from '@/common/constant/interaction';
import type { S2Options } from '@/common/interface';
import { Store } from '@/common/store';
Expand Down
Loading

0 comments on commit 89b9f3d

Please sign in to comment.