Skip to content

Commit

Permalink
test: 修复单测
Browse files Browse the repository at this point in the history
  • Loading branch information
lijinke666 committed Feb 28, 2024
1 parent a1477ae commit 57c0012
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 18 deletions.
9 changes: 5 additions & 4 deletions packages/s2-core/__tests__/bugs/issue-2340-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ describe('Header Brush Selection Tests', () => {
await s2.render();

const isRow = cellType === CellType.ROW_CELL;
const stateName = isRow
? InteractionStateName.ROW_CELL_BRUSH_SELECTED
: InteractionStateName.COL_CELL_BRUSH_SELECTED;
const targetCells = isRow
? s2.facet.getRowCells()
: s2.facet.getColCells();
Expand All @@ -45,7 +48,7 @@ describe('Header Brush Selection Tests', () => {

s2.interaction.changeState({
cells: cells.map(getCellMeta),
stateName: InteractionStateName.BRUSH_SELECTED,
stateName,
});

await sleep(500);
Expand All @@ -65,9 +68,7 @@ describe('Header Brush Selection Tests', () => {
});

expect(s2.interaction.getActiveCells()).toHaveLength(1);
expect(s2.interaction.getCurrentStateName()).toEqual(
InteractionStateName.BRUSH_SELECTED,
);
expect(s2.interaction.getCurrentStateName()).toEqual(stateName);

// 交互过的不应该有 dataCell (未触发过列头多选)
s2.interaction.getInteractedCells().forEach((cell) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/s2-core/src/cell/data-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export class DataCell extends BaseCell<ViewMeta> {

switch (stateName) {
case InteractionStateName.SELECTED:
case InteractionStateName.BRUSH_SELECTED:
case InteractionStateName.DATA_CELL_BRUSH_SELECTED:
this.handleSelect(cells);
break;
case InteractionStateName.HOVER_FOCUS:
Expand Down
3 changes: 2 additions & 1 deletion packages/s2-core/src/cell/header-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,8 @@ export abstract class HeaderCell<

switch (stateInfo?.stateName) {
case InteractionStateName.SELECTED:
case InteractionStateName.BRUSH_SELECTED:
case InteractionStateName.ROW_CELL_BRUSH_SELECTED:
case InteractionStateName.COL_CELL_BRUSH_SELECTED:
this.handleSelect(cells, stateInfo?.nodes);
break;
case InteractionStateName.HOVER_FOCUS:
Expand Down
4 changes: 3 additions & 1 deletion packages/s2-core/src/common/constant/interaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ export enum InteractionName {
export enum InteractionStateName {
ALL_SELECTED = 'allSelected',
SELECTED = 'selected',
BRUSH_SELECTED = 'brushSelected',
ROW_CELL_BRUSH_SELECTED = 'rowCellBrushSelected',
COL_CELL_BRUSH_SELECTED = 'colCellBrushSelected',
DATA_CELL_BRUSH_SELECTED = 'dataCellBrushSelected',
UNSELECTED = 'unselected',
HOVER = 'hover',
HOVER_FOCUS = 'hoverFocus',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class ColCellBrushSelection extends BaseBrushSelection {
onUpdateCells: (root) => {
root.updateCells(facet.getColCells());
},
stateName: InteractionStateName.BRUSH_SELECTED,
stateName: InteractionStateName.COL_CELL_BRUSH_SELECTED,
});

this.spreadsheet.emit(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class DataCellBrushSelection extends BaseBrushSelection {

this.spreadsheet.interaction.changeState({
cells: selectedCellMetas,
stateName: InteractionStateName.BRUSH_SELECTED,
stateName: InteractionStateName.DATA_CELL_BRUSH_SELECTED,
onUpdateCells: afterSelectDataCells,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class RowCellBrushSelection extends BaseBrushSelection {

this.spreadsheet.interaction.changeState({
cells: selectedCellMetas,
stateName: InteractionStateName.BRUSH_SELECTED,
stateName: InteractionStateName.ROW_CELL_BRUSH_SELECTED,
onUpdateCells: this.onUpdateCells,
});

Expand Down
12 changes: 8 additions & 4 deletions packages/s2-core/src/interaction/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,14 @@ export class RootInteraction {
}

public isSelectedState() {
return (
this.isStateOf(InteractionStateName.SELECTED) ||
this.isStateOf(InteractionStateName.BRUSH_SELECTED)
);
return [
InteractionStateName.SELECTED,
InteractionStateName.ROW_CELL_BRUSH_SELECTED,
InteractionStateName.COL_CELL_BRUSH_SELECTED,
InteractionStateName.DATA_CELL_BRUSH_SELECTED,
].some((stateName) => {
return this.isStateOf(stateName);
});
}

public isAllSelectedState() {
Expand Down
23 changes: 22 additions & 1 deletion s2-site/docs/api/basic-class/interaction.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,11 @@ type S2CellType<T extends SimpleBBox = ViewMeta> =
| ColCell
| CornerCell
| RowCell
| MergedCell
| SeriesNumberCell
| MergedCell
| TableDataCell
| TableCornerCell
| TableSeriesNumberCell
| BaseCell<T>;
```

Expand All @@ -121,6 +124,24 @@ interface MergedCellInfo {
}
```

### InteractionStateName

```ts
enum InteractionStateName {
ALL_SELECTED = 'allSelected',
SELECTED = 'selected',
ROW_CELL_BRUSH_SELECTED = 'rowCellBrushSelected',
COL_CELL_BRUSH_SELECTED = 'colCellBrushSelected',
DATA_CELL_BRUSH_SELECTED = 'dataCellBrushSelected',
UNSELECTED = 'unselected',
HOVER = 'hover',
HOVER_FOCUS = 'hoverFocus',
HIGHLIGHT = 'highlight',
SEARCH_RESULT = 'searchResult',
PREPARE_SELECT = 'prepareSelect',
}
```

### InteractionStateInfo

```ts
Expand Down
15 changes: 12 additions & 3 deletions s2-site/docs/manual/migration-v2.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -598,15 +598,24 @@ const s2Options = {

具体请查看 [获取单元格数据](/manual/advanced/get-cell-data) 相关文档。

#### 数值单元格刷选选中状态变更
#### 单元格刷选选中状态变更

`1.x` 中,数值单元格的刷选选中状态为 `selected`, `2.x` 中行头,列头,数值单元格的刷选状态统一为 `brushSelected`.
`1.x` 中,行列头刷选选中状态为 `brushSelected`, 数值单元格的刷选选中状态为 `selected`, `2.x` 中做了进一步统一和区分:

```diff
s2.interaction.getState()

// 行头
- stateName: "brushSelected"
+ stateName: "rowCellBrushSelected"

// 列头
- stateName: "brushSelected"
+ stateName: "colCellBrushSelected"

// 数值
- stateName: "selected"
+ stateName: "brushSelected"
+ stateName: "dataCellBrushSelected"
```

### 组件层 <Badge>@antv/s2-react</Badge>
Expand Down

0 comments on commit 57c0012

Please sign in to comment.