-
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
821e2ac
commit 58faf9f
Showing
7 changed files
with
263 additions
and
4 deletions.
There are no files selected for viewing
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
12 changes: 12 additions & 0 deletions
12
packages/s2-shared/__tests__/unit/utils/classnames-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,12 @@ | ||
import { getStrategySheetTooltipClsName } from '../../../src/utils/classnames'; | ||
|
||
describe('classnames test', () => { | ||
test('#getStrategySheetTooltipClsName()', () => { | ||
expect(getStrategySheetTooltipClsName()).toEqual( | ||
's2-strategy-sheet-tooltip', | ||
); | ||
expect(getStrategySheetTooltipClsName('test')).toEqual( | ||
's2-strategy-sheet-tooltip-test', | ||
); | ||
}); | ||
}); |
178 changes: 178 additions & 0 deletions
178
packages/s2-shared/__tests__/unit/utils/drill-down-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,178 @@ | ||
import { | ||
Store, | ||
type Node, | ||
type SpreadSheet, | ||
GEvent, | ||
S2Event, | ||
PivotDataSet, | ||
} from '@antv/s2'; | ||
import type { PartDrillDown } from '../../../src/interface'; | ||
import { | ||
buildDrillDownOptions, | ||
defaultPartDrillDownDisplayCondition, | ||
getDrillDownCache, | ||
handleActionIconClick, | ||
handleDrillDown, | ||
} from '../../../src/utils/drill-down'; | ||
import { sleep } from '../../util/helpers'; | ||
|
||
describe('drill-down test', () => { | ||
let s2: SpreadSheet; | ||
|
||
beforeEach(() => { | ||
s2 = { | ||
store: new Store(), | ||
dataCfg: { | ||
fields: { | ||
rows: [], | ||
}, | ||
}, | ||
interaction: {}, | ||
} as unknown as SpreadSheet; | ||
}); | ||
|
||
test('#getDrillDownCache()', () => { | ||
const node = { | ||
id: 'test', | ||
} as Node; | ||
|
||
expect(getDrillDownCache(s2, node)).toMatchInlineSnapshot(` | ||
Object { | ||
"drillDownCurrentCache": undefined, | ||
"drillDownDataCache": Array [], | ||
} | ||
`); | ||
|
||
s2.store.set('drillDownDataCache', [{ rowId: node.id }]); | ||
|
||
expect(getDrillDownCache(s2, node)).toMatchInlineSnapshot(` | ||
Object { | ||
"drillDownCurrentCache": Object { | ||
"rowId": "test", | ||
}, | ||
"drillDownDataCache": Array [ | ||
Object { | ||
"rowId": "test", | ||
}, | ||
], | ||
} | ||
`); | ||
}); | ||
|
||
test('#handleActionIconClick()', () => { | ||
const callback = jest.fn(); | ||
const emit = jest.fn(); | ||
s2.emit = emit; | ||
const node = { | ||
id: 'test', | ||
spreadsheet: s2, | ||
} as Node; | ||
const event = {} as GEvent; | ||
|
||
handleActionIconClick({ | ||
meta: node, | ||
event, | ||
callback, | ||
}); | ||
|
||
expect(s2.store.get('drillDownNode')).toEqual(node); | ||
expect(callback).toHaveBeenCalledWith({ | ||
cacheDrillFields: [], | ||
disabledFields: [], | ||
event, | ||
sheetInstance: s2, | ||
}); | ||
expect(emit).toHaveBeenCalledWith(S2Event.GLOBAL_ACTION_ICON_CLICK, event); | ||
}); | ||
|
||
test('#defaultPartDrillDownDisplayCondition()', () => { | ||
const node = { | ||
id: 'test', | ||
spreadsheet: s2, | ||
} as Node; | ||
|
||
expect(defaultPartDrillDownDisplayCondition(node)).toEqual(false); | ||
}); | ||
|
||
test('#buildDrillDownOptions()', () => { | ||
const partDrillDown: PartDrillDown = { | ||
fetchData: jest.fn(), | ||
drillItemsNum: 1, | ||
drillConfig: { | ||
dataSet: [], | ||
}, | ||
}; | ||
|
||
const callback = jest.fn(); | ||
|
||
expect( | ||
buildDrillDownOptions( | ||
{ | ||
headerActionIcons: [], | ||
}, | ||
null, | ||
callback, | ||
), | ||
).toMatchInlineSnapshot(` | ||
Object { | ||
"headerActionIcons": Array [], | ||
} | ||
`); | ||
|
||
expect( | ||
buildDrillDownOptions( | ||
{ | ||
headerActionIcons: [], | ||
}, | ||
partDrillDown, | ||
callback, | ||
), | ||
).toMatchInlineSnapshot(` | ||
Object { | ||
"headerActionIcons": Array [ | ||
Object { | ||
"action": [Function], | ||
"belongsCell": "rowCell", | ||
"defaultHide": true, | ||
"displayCondition": [Function], | ||
"iconNames": Array [ | ||
"DrillDownIcon", | ||
], | ||
}, | ||
], | ||
} | ||
`); | ||
}); | ||
|
||
test('#handleDrillDown()', async () => { | ||
const render = jest.fn(); | ||
const reset = jest.fn(); | ||
|
||
s2.dataSet = { | ||
transformDrillDownData: jest.fn(), | ||
} as unknown as PivotDataSet; | ||
s2.interaction.reset = reset; | ||
s2.render = render; | ||
|
||
const fetchData = () => | ||
Promise.resolve({ | ||
drillField: 'area', | ||
drillData: [], | ||
}); | ||
|
||
handleDrillDown({ | ||
fetchData, | ||
spreadsheet: s2, | ||
drillFields: [], | ||
rows: [], | ||
}); | ||
|
||
await sleep(200); | ||
|
||
expect( | ||
(s2.dataSet as PivotDataSet).transformDrillDownData, | ||
).toHaveBeenCalledTimes(1); | ||
expect(reset).toHaveBeenCalledTimes(1); | ||
expect(render).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
2 changes: 1 addition & 1 deletion
2
...s2-shared/__tests__/utils/options-spec.ts → ...ared/__tests__/unit/utils/options-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
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,60 @@ | ||
import { PivotSheet } from '@antv/s2'; | ||
import { | ||
analyzeAdaptive, | ||
createResizeObserver, | ||
} from '../../../src/utils/resize'; | ||
|
||
describe('resize test', () => { | ||
test('#analyzeAdaptive()', () => { | ||
const container = document.createElement('div'); | ||
|
||
expect(analyzeAdaptive(container)).toEqual({ | ||
container, | ||
adaptiveWidth: true, | ||
adaptiveHeight: true, | ||
}); | ||
|
||
expect(analyzeAdaptive(container, true)).toEqual({ | ||
container, | ||
adaptiveWidth: true, | ||
adaptiveHeight: false, | ||
}); | ||
|
||
expect(analyzeAdaptive(container, false)).toEqual({ | ||
container, | ||
adaptiveWidth: true, | ||
adaptiveHeight: false, | ||
}); | ||
}); | ||
|
||
test('#createResizeObserver()', () => { | ||
const container = document.createElement('div'); | ||
const wrapper = document.createElement('div'); | ||
const s2 = new PivotSheet( | ||
container, | ||
{ data: [], fields: { rows: [], columns: [], values: [] } }, | ||
{ | ||
width: 200, | ||
height: 200, | ||
}, | ||
); | ||
|
||
expect( | ||
createResizeObserver({ | ||
s2, | ||
container: null, | ||
wrapper: null, | ||
adaptive: true, | ||
}), | ||
).toBeUndefined(); | ||
|
||
expect( | ||
createResizeObserver({ | ||
s2, | ||
container, | ||
wrapper, | ||
adaptive: true, | ||
}), | ||
).toBeFunction(); | ||
}); | ||
}); |
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,3 @@ | ||
export const sleep = async (timeout = 0) => { | ||
await new Promise((resolve) => setTimeout(resolve, timeout)); | ||
}; |
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