-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
48b7073
commit 39ae16b
Showing
4 changed files
with
197 additions
and
30 deletions.
There are no files selected for viewing
126 changes: 126 additions & 0 deletions
126
packages/s2-core/__tests__/spreadsheet/interaction-corner-click-spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
import { | ||
createMockCellInfo, | ||
createPivotSheet, | ||
getContainer, | ||
} from 'tests/util/helpers'; | ||
import { customRowGridSimpleFields } from '../data/custom-grid-simple-fields'; | ||
import { CustomGridData } from '../data/data-custom-grid'; | ||
import { S2Event } from '@/common/constant'; | ||
import { CornerNodeType, type S2Options } from '@/common/interface'; | ||
import type { GEvent, HierarchyType, S2DataConfig } from '@/index'; | ||
import { PivotSheet, SpreadSheet } from '@/sheet-type'; | ||
|
||
const s2Options: S2Options = { | ||
width: 600, | ||
height: 400, | ||
}; | ||
|
||
describe('Interaction Corner Cell Click Tests', () => { | ||
let s2: SpreadSheet; | ||
|
||
afterEach(() => { | ||
s2.destroy(); | ||
}); | ||
|
||
test.each(['grid', 'tree'] as HierarchyType[])( | ||
'should not selected row cell when col corner cell clicked for %s mode', | ||
async (hierarchyType) => { | ||
jest.spyOn(SpreadSheet.prototype, 'getCell').mockImplementationOnce( | ||
() => | ||
createMockCellInfo('testId', { | ||
cornerType: CornerNodeType.Col, | ||
}).mockCell, | ||
); | ||
|
||
s2 = createPivotSheet({ | ||
...s2Options, | ||
hierarchyType, | ||
}); | ||
await s2.render(); | ||
|
||
const reset = jest | ||
.spyOn(s2.interaction, 'reset') | ||
.mockImplementationOnce(() => {}); | ||
|
||
s2.emit(S2Event.CORNER_CELL_CLICK, {} as unknown as GEvent); | ||
|
||
expect(reset).toHaveBeenCalledTimes(1); | ||
expect(s2.interaction.isSelectedState()).toBeFalsy(); | ||
}, | ||
); | ||
|
||
test.each(['grid', 'tree'] as HierarchyType[])( | ||
'should selected row cell when row corner cell clicked for %s mode', | ||
async (hierarchyType) => { | ||
jest.spyOn(SpreadSheet.prototype, 'getCell').mockImplementationOnce( | ||
() => | ||
createMockCellInfo('city', { | ||
cornerType: CornerNodeType.Row, | ||
}).mockCell, | ||
); | ||
|
||
s2 = createPivotSheet({ | ||
...s2Options, | ||
hierarchyType, | ||
}); | ||
await s2.render(); | ||
|
||
const reset = jest | ||
.spyOn(s2.interaction, 'reset') | ||
.mockImplementationOnce(() => {}); | ||
|
||
s2.emit(S2Event.CORNER_CELL_CLICK, {} as unknown as GEvent); | ||
|
||
expect(reset).not.toHaveBeenCalled(); | ||
expect(s2.interaction.getActiveCells()).toHaveLength( | ||
s2.isHierarchyTreeType() ? 3 : 2, | ||
); | ||
expect(s2.interaction.isSelectedState()).toBeTruthy(); | ||
}, | ||
); | ||
|
||
test.each(['grid', 'tree'] as HierarchyType[])( | ||
'should selected custom row cell when row corner cell clicked for %s mode', | ||
async (hierarchyType) => { | ||
jest.spyOn(SpreadSheet.prototype, 'getCell').mockImplementationOnce( | ||
() => | ||
createMockCellInfo('a-1-1', { | ||
cornerType: CornerNodeType.Row, | ||
}).mockCell, | ||
); | ||
|
||
const customRowDataCfg: S2DataConfig = { | ||
data: CustomGridData, | ||
fields: customRowGridSimpleFields, | ||
}; | ||
|
||
s2 = new PivotSheet(getContainer(), customRowDataCfg, { | ||
...s2Options, | ||
hierarchyType, | ||
}); | ||
await s2.render(); | ||
|
||
const reset = jest | ||
.spyOn(s2.interaction, 'reset') | ||
.mockImplementationOnce(() => {}); | ||
|
||
s2.emit(S2Event.CORNER_CELL_CLICK, {} as unknown as GEvent); | ||
|
||
const gridFields = ['a-1-1', 'a-1-2']; | ||
const treeFields = [ | ||
'a-1', | ||
'a-1-1', | ||
'measure-1', | ||
'measure-2', | ||
'a-1-2', | ||
'a-2', | ||
]; | ||
|
||
expect(reset).not.toHaveBeenCalled(); | ||
expect( | ||
s2.interaction.getActiveCells().map((cell) => cell.getMeta().field), | ||
).toEqual(s2.isHierarchyTreeType() ? treeFields : gridFields); | ||
expect(s2.interaction.isSelectedState()).toBeTruthy(); | ||
}, | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters