Skip to content

Commit

Permalink
Merge branch 'master' into docs-custom
Browse files Browse the repository at this point in the history
  • Loading branch information
lijinke666 authored Oct 27, 2023
2 parents c40595a + 2edd99c commit 819a761
Show file tree
Hide file tree
Showing 9 changed files with 424 additions and 16 deletions.
57 changes: 57 additions & 0 deletions packages/s2-core/__tests__/bugs/issue-2385-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* @description spec for issue #2385
* https://github.com/antvis/S2/issues/2385
*/
import { createPivotSheet, getContainer } from '../util/helpers';

Check warning on line 5 in packages/s2-core/__tests__/bugs/issue-2385-spec.ts

View workflow job for this annotation

GitHub Actions / lint (18)

'createPivotSheet' is defined but never used
import * as mockDataConfig from '../data/data-issue-2385.json';
import type { S2Options } from '../../src';
import { PivotSheet, TableSheet } from '@/sheet-type';

const s2Options: S2Options = {
width: 800,
height: 600,
style: {
cellCfg: {
width: 200,
},
layoutWidthType: 'compact',
},
};

describe('Compare Layout Tests', () => {
test('should get max col width for pivot sheet', () => {
const s2 = new PivotSheet(getContainer(), mockDataConfig, s2Options);
s2.setTheme({
dataCell: {
text: {
fontSize: 20,
},
},
});
s2.render();

const colLeafNodes = s2.facet.layoutResult.colLeafNodes;
expect(Math.floor(colLeafNodes[0].width)).toBeCloseTo(179);
expect(Math.floor(colLeafNodes[1].width)).toEqual(98);
});

test('should get max col width for table sheet', () => {
const s2 = new TableSheet(getContainer(), mockDataConfig, s2Options);
s2.setDataCfg({
fields: {
columns: ['price'],
},
});
s2.setTheme({
dataCell: {
text: {
fontSize: 20,
},
},
});
s2.render();

const colLeafNodes = s2.facet.layoutResult.colLeafNodes;
expect(Math.floor(colLeafNodes[0].width)).toBeCloseTo(165);
});
});
272 changes: 272 additions & 0 deletions packages/s2-core/__tests__/data/data-issue-2385.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,272 @@
{
"data": [
{
"province": "浙江",
"city": "杭州",
"type": "",
"price": "11111111"
},
{
"province": "浙江",
"city": "杭州",
"type": "纸张",
"price": "2"
},
{
"province": "浙江",
"city": "舟山",
"type": "",
"price": "2"
},
{
"province": "浙江",
"city": "舟山",
"type": "纸张",
"price": "133.333"
},
{
"province": "吉林",
"city": "长春",
"type": "",
"price": "3"
},
{
"province": "吉林",
"city": "长春",
"type": "纸张",
"price": "2"
},
{
"province": "吉林",
"city": "白山",
"type": "",
"price": "4"
},
{
"province": "吉林",
"city": "白山",
"type": "纸张",
"price": "1"
},
{
"province": "浙江",
"city": "杭州",
"type": "",
"price": "11111111111111111"
},
{
"province": "浙江",
"city": "杭州",
"type": "纸张",
"price": "2"
},
{
"province": "浙江",
"city": "舟山",
"type": "",
"price": "2"
},
{
"province": "浙江",
"city": "舟山",
"type": "纸张",
"price": "666.333"
},
{
"province": "吉林",
"city": "长春",
"type": "",
"price": "3"
},
{
"province": "吉林",
"city": "长春",
"type": "纸张",
"price": "2"
},
{
"province": "吉林",
"city": "白山",
"type": "",
"price": "4"
},
{
"province": "吉林",
"city": "白山",
"type": "纸张",
"price": "1"
},
{
"province": "浙江",
"city": "杭州",
"type": "",
"cost": "33.333"
},
{
"province": "浙江",
"city": "杭州",
"type": "纸张",
"cost": "1.5"
},
{
"province": "浙江",
"city": "舟山",
"type": "",
"cost": "1.5"
},
{
"province": "浙江",
"city": "舟山",
"type": "纸张",
"cost": "0.2"
},
{
"province": "吉林",
"city": "长春",
"type": "",
"cost": "2"
},
{
"province": "吉林",
"city": "长春",
"type": "纸张",
"cost": "1"
},
{
"province": "吉林",
"city": "白山",
"type": "",
"cost": "3"
},
{
"province": "吉林",
"city": "白山",
"type": "纸张",
"cost": "33.333"
},
{
"price": "15.5"
},
{
"province": "浙江",
"price": "5.5"
},
{
"province": "浙江",
"city": "杭州",
"price": "3"
},
{
"province": "浙江",
"city": "舟山",
"price": "2.5"
},
{
"province": "吉林",
"price": "10"
},
{
"province": "吉林",
"city": "长春",
"price": "5"
},
{
"province": "吉林",
"city": "白山",
"price": "5"
},
{
"type": "",
"price": "10"
},
{
"type": "",
"province": "浙江",
"price": "3"
},
{
"type": "",
"province": "吉林",
"price": "7"
},
{
"type": "纸张",
"price": "5.5"
},
{
"type": "纸张",
"province": "浙江",
"price": "2.5"
},
{
"type": "纸张",
"province": "吉林",
"price": "3"
},
{
"cost": "10.2"
},
{
"province": "浙江",
"cost": "3.7"
},
{
"province": "浙江",
"city": "杭州",
"cost": "2"
},
{
"province": "浙江",
"city": "舟山",
"cost": "1.7"
},
{
"province": "吉林",
"cost": "6.5"
},
{
"province": "吉林",
"city": "长春",
"cost": "3"
},
{
"province": "吉林",
"city": "白山",
"cost": "3.5"
},
{
"type": "",
"cost": "7"
},
{
"type": "",
"province": "浙江",
"cost": "2"
},
{
"type": "",
"province": "吉林",
"cost": "5"
},
{
"type": "纸张",
"cost": "3.2"
},
{
"type": "纸张",
"province": "浙江",
"cost": "1.7"
},
{
"type": "纸张",
"province": "吉林",
"cost": "1.5"
}
],
"fields": {
"rows": ["province", "city"],
"columns": ["type"],
"values": ["price"],
"valueInCols": true
}
}
50 changes: 49 additions & 1 deletion packages/s2-core/__tests__/spreadsheet/scroll-spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable jest/no-conditional-expect */
import * as mockDataConfig from 'tests/data/simple-data.json';
import { createMockCellInfo, getContainer, sleep } from 'tests/util/helpers';
import { ScrollType } from '../../src/ui/scrollbar';
import { ScrollBar, ScrollType } from '../../src/ui/scrollbar';
import type { CellScrollPosition } from './../../src/common/interface/scroll';
import { PivotSheet, SpreadSheet } from '@/sheet-type';
import type {
Expand Down Expand Up @@ -880,4 +880,52 @@ describe('Scroll Tests', () => {

expect(errorSpy).toBeCalledTimes(1);
});

// https://github.com/antvis/S2/issues/2376
test.each(['hScrollBar', 'hRowScrollBar'])(
'should not reset interaction state after %s scrollbar thumb or track clicked',
(scrollbarName) => {
const containsMock = jest
.spyOn(HTMLElement.prototype, 'contains')
.mockImplementation(() => true);

const reset = jest.fn();

const scrollbar = s2.facet[scrollbarName] as ScrollBar;
const colCell = s2.getColumnLeafNodes()[0].belongsCell;

s2.on(S2Event.GLOBAL_RESET, reset);
s2.interaction.selectHeaderCell({
cell: colCell,
});

expect(s2.interaction.isSelectedState()).toBeTruthy();

const { maxX, maxY } = s2.facet?.panelBBox || {};
const { x, y } = canvas.getBoundingClientRect() || {};

// 滚动条
window.dispatchEvent(
new MouseEvent('click', {
clientX: x + scrollbar.position.x,
// 在滚动条内点击
clientY: y + scrollbar.position.y + scrollbar.theme.size - 2,
} as MouseEventInit),
);

// 滑动轨道
window.dispatchEvent(
new MouseEvent('click', {
// 右下角滑道点击
clientX: x + maxX - 2,
clientY: y + maxY + 2,
} as MouseEventInit),
);

expect(s2.interaction.isSelectedState()).toBeTruthy();
expect(reset).not.toHaveBeenCalled();

containsMock.mockReset();
},
);
});
Loading

0 comments on commit 819a761

Please sign in to comment.