Skip to content

Commit

Permalink
Merge pull request #535 from mathuo/534-setvisible-is-missing-from-sp…
Browse files Browse the repository at this point in the history
…litviewpanelapiimpl

feat: cleanup setVisible api
  • Loading branch information
mathuo authored Mar 2, 2024
2 parents 2ee9b46 + d3b22d8 commit f00b3d8
Show file tree
Hide file tree
Showing 17 changed files with 348 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { DockviewPanelApiImpl } from '../../api/dockviewPanelApi';
import { DockviewComponent } from '../../dockview/dockviewComponent';
import { DockviewPanel, IDockviewPanel } from '../../dockview/dockviewPanel';
import { DockviewGroupPanel } from '../../dockview/dockviewGroupPanel';
import { fromPartial } from '@total-typescript/shoehorn';

describe('groupPanelApi', () => {
test('title', () => {
Expand All @@ -17,12 +18,15 @@ describe('groupPanelApi', () => {
setTitle: jest.fn(),
} as any;
});
const groupMock = jest.fn<DockviewGroupPanel, []>(() => {
return {} as any;
});

const panel = new panelMock();
const group = new groupMock();
const group = fromPartial<DockviewGroupPanel>({
api: {
onDidVisibilityChange: jest.fn(),
onDidLocationChange: jest.fn(),
onDidActiveChange: jest.fn(),
},
});

const cut = new DockviewPanelApiImpl(
panel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
TabDragEvent,
} from '../../dockview/components/titlebar/tabsContainer';
import { fromPartial } from '@total-typescript/shoehorn';
import { DockviewApi } from '../../api/component.api';

class PanelContentPartTest implements IContentRenderer {
element: HTMLElement = document.createElement('div');
Expand Down Expand Up @@ -4596,4 +4597,113 @@ describe('dockviewComponent', () => {
expect(panel2.group.api.isActive).toBeFalsy();
});
});

test('that setVisible toggles visiblity', () => {
const container = document.createElement('div');

const dockview = new DockviewComponent({
parentElement: container,
components: {
default: PanelContentPartTest,
},
tabComponents: {
test_tab_id: PanelTabPartTest,
},
orientation: Orientation.HORIZONTAL,
});
const api = new DockviewApi(dockview);

dockview.layout(1000, 1000);

const panel1 = api.addPanel({
id: 'panel1',
component: 'default',
});
const panel2 = api.addPanel({
id: 'panel2',
component: 'default',
position: { referencePanel: panel1, direction: 'within' },
});

const panel3 = api.addPanel({
id: 'panel3',
component: 'default',
position: { referencePanel: panel1, direction: 'right' },
});

const panel4 = api.addPanel({
id: 'panel4',
component: 'default',
position: { referencePanel: panel3, direction: 'within' },
});

expect(api.groups.length).toBe(2);
expect(panel1.group).toBe(panel2.group);
expect(panel3.group).toBe(panel4.group);

expect(panel1.group.api.isVisible).toBeTruthy();
expect(panel2.group.api.isVisible).toBeTruthy();
expect(panel3.group.api.isVisible).toBeTruthy();
expect(panel4.group.api.isVisible).toBeTruthy();

expect(panel1.api.isVisible).toBeFalsy();
expect(panel2.api.isVisible).toBeTruthy();
expect(panel3.api.isVisible).toBeFalsy();
expect(panel4.api.isVisible).toBeTruthy();

// case #1
panel1.group.api.setVisible(false);

expect(panel1.group.api.isVisible).toBeFalsy();
expect(panel2.group.api.isVisible).toBeFalsy();
expect(panel3.group.api.isVisible).toBeTruthy();
expect(panel4.group.api.isVisible).toBeTruthy();

expect(panel1.api.isVisible).toBeFalsy();
expect(panel2.api.isVisible).toBeFalsy();
expect(panel3.api.isVisible).toBeFalsy();
expect(panel4.api.isVisible).toBeTruthy();

// case #2

panel3.group.api.setVisible(false);

expect(panel1.group.api.isVisible).toBeFalsy();
expect(panel2.group.api.isVisible).toBeFalsy();
expect(panel3.group.api.isVisible).toBeFalsy();
expect(panel4.group.api.isVisible).toBeFalsy();

expect(panel1.api.isVisible).toBeFalsy();
expect(panel2.api.isVisible).toBeFalsy();
expect(panel3.api.isVisible).toBeFalsy();
expect(panel4.api.isVisible).toBeFalsy();

// case #2

panel3.group.api.setVisible(true);

expect(panel1.group.api.isVisible).toBeFalsy();
expect(panel2.group.api.isVisible).toBeFalsy();
expect(panel3.group.api.isVisible).toBeTruthy();
expect(panel4.group.api.isVisible).toBeTruthy();

expect(panel1.api.isVisible).toBeFalsy();
expect(panel2.api.isVisible).toBeFalsy();
expect(panel3.api.isVisible).toBeFalsy();
expect(panel4.api.isVisible).toBeTruthy();

// case #2

panel1.group.api.setVisible(true);

expect(panel1.group.api.isVisible).toBeTruthy();
expect(panel2.group.api.isVisible).toBeTruthy();
expect(panel3.group.api.isVisible).toBeTruthy();
expect(panel4.group.api.isVisible).toBeTruthy();

expect(panel1.api.isVisible).toBeFalsy();
expect(panel2.api.isVisible).toBeTruthy();
expect(panel3.api.isVisible).toBeFalsy();
expect(panel4.api.isVisible).toBeTruthy();
});
});
79 changes: 51 additions & 28 deletions packages/dockview-core/src/__tests__/dockview/dockviewPanel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DockviewApi } from '../../api/component.api';
import { DockviewPanel } from '../../dockview/dockviewPanel';
import { IDockviewPanelModel } from '../../dockview/dockviewPanelModel';
import { DockviewGroupPanel } from '../../dockview/dockviewGroupPanel';
import { fromPartial } from '@total-typescript/shoehorn';

describe('dockviewPanel', () => {
test('update title', () => {
Expand All @@ -14,9 +15,7 @@ describe('dockviewPanel', () => {
const accessorMock = jest.fn<DockviewComponent, []>(() => {
return {} as any;
});
const groupMock = jest.fn<DockviewGroupPanel, []>(() => {
return {} as any;
});

const panelModelMock = jest.fn<Partial<IDockviewPanelModel>, []>(() => {
return {
update: jest.fn(),
Expand All @@ -26,7 +25,13 @@ describe('dockviewPanel', () => {

const api = new dockviewApiMock();
const accessor = new accessorMock();
const group = new groupMock();
const group = fromPartial<DockviewGroupPanel>({
api: {
onDidVisibilityChange: jest.fn(),
onDidLocationChange: jest.fn(),
onDidActiveChange: jest.fn(),
},
});
const model = <IDockviewPanelModel>new panelModelMock();

const cut = new DockviewPanel('fake-id', accessor, api, group, model, {
Expand Down Expand Up @@ -61,9 +66,6 @@ describe('dockviewPanel', () => {
const accessorMock = jest.fn<DockviewComponent, []>(() => {
return {} as any;
});
const groupMock = jest.fn<DockviewGroupPanel, []>(() => {
return {} as any;
});
const panelModelMock = jest.fn<Partial<IDockviewPanelModel>, []>(() => {
return {
update: jest.fn(),
Expand All @@ -73,7 +75,13 @@ describe('dockviewPanel', () => {

const api = new dockviewApiMock();
const accessor = new accessorMock();
const group = new groupMock();
const group = fromPartial<DockviewGroupPanel>({
api: {
onDidVisibilityChange: jest.fn(),
onDidLocationChange: jest.fn(),
onDidActiveChange: jest.fn(),
},
});
const model = <IDockviewPanelModel>new panelModelMock();

const cut = new DockviewPanel('fake-id', accessor, api, group, model, {
Expand All @@ -97,9 +105,6 @@ describe('dockviewPanel', () => {
const accessorMock = jest.fn<DockviewComponent, []>(() => {
return {} as any;
});
const groupMock = jest.fn<DockviewGroupPanel, []>(() => {
return {} as any;
});
const panelModelMock = jest.fn<Partial<IDockviewPanelModel>, []>(() => {
return {
update: jest.fn(),
Expand All @@ -110,7 +115,19 @@ describe('dockviewPanel', () => {

const api = new dockviewApiMock();
const accessor = new accessorMock();
const group = new groupMock();
const group = fromPartial<DockviewGroupPanel>({
api: {
onDidVisibilityChange: jest
.fn()
.mockReturnValue({ dispose: jest.fn() }),
onDidLocationChange: jest
.fn()
.mockReturnValue({ dispose: jest.fn() }),
onDidActiveChange: jest
.fn()
.mockReturnValue({ dispose: jest.fn() }),
},
});
const model = <IDockviewPanelModel>new panelModelMock();

const cut = new DockviewPanel('fake-id', accessor, api, group, model, {
Expand All @@ -131,9 +148,6 @@ describe('dockviewPanel', () => {
const accessorMock = jest.fn<DockviewComponent, []>(() => {
return {} as any;
});
const groupMock = jest.fn<DockviewGroupPanel, []>(() => {
return {} as any;
});
const panelModelMock = jest.fn<Partial<IDockviewPanelModel>, []>(() => {
return {
update: jest.fn(),
Expand All @@ -144,7 +158,13 @@ describe('dockviewPanel', () => {

const api = new dockviewApiMock();
const accessor = new accessorMock();
const group = new groupMock();
const group = fromPartial<DockviewGroupPanel>({
api: {
onDidVisibilityChange: jest.fn(),
onDidLocationChange: jest.fn(),
onDidActiveChange: jest.fn(),
},
});
const model = <IDockviewPanelModel>new panelModelMock();

const cut = new DockviewPanel('fake-id', accessor, api, group, model, {
Expand All @@ -165,13 +185,6 @@ describe('dockviewPanel', () => {
const accessorMock = jest.fn<DockviewComponent, []>(() => {
return {} as any;
});
const groupMock = jest.fn<DockviewGroupPanel, []>(() => {
return {
api: {
setSize: jest.fn(),
},
} as any;
});
const panelModelMock = jest.fn<Partial<IDockviewPanelModel>, []>(() => {
return {
update: jest.fn(),
Expand All @@ -182,7 +195,14 @@ describe('dockviewPanel', () => {

const api = new dockviewApiMock();
const accessor = new accessorMock();
const group = new groupMock();
const group = fromPartial<DockviewGroupPanel>({
api: {
onDidVisibilityChange: jest.fn(),
onDidLocationChange: jest.fn(),
onDidActiveChange: jest.fn(),
setSize: jest.fn(),
},
});
const model = <IDockviewPanelModel>new panelModelMock();

const cut = new DockviewPanel('fake-id', accessor, api, group, model, {
Expand All @@ -202,9 +222,6 @@ describe('dockviewPanel', () => {
const accessorMock = jest.fn<DockviewComponent, []>(() => {
return {} as any;
});
const groupMock = jest.fn<DockviewGroupPanel, []>(() => {
return {} as any;
});
const panelModelMock = jest.fn<Partial<IDockviewPanelModel>, []>(() => {
return {
update: jest.fn(),
Expand All @@ -215,7 +232,13 @@ describe('dockviewPanel', () => {

const api = new dockviewApiMock();
const accessor = new accessorMock();
const group = new groupMock();
const group = fromPartial<DockviewGroupPanel>({
api: {
onDidVisibilityChange: jest.fn(),
onDidLocationChange: jest.fn(),
onDidActiveChange: jest.fn(),
},
});
const model = <IDockviewPanelModel>new panelModelMock();

const cut = new DockviewPanel('fake-id', accessor, api, group, model, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2700,4 +2700,35 @@ describe('gridview', () => {

expect(gridview.disableResizing).toBeTruthy();
});

test('that setVisible toggles visiblity', () => {
const gridview = new GridviewComponent({
parentElement: container,
proportionalLayout: true,
orientation: Orientation.HORIZONTAL,
components: { default: TestGridview },
disableAutoResizing: true,
});
gridview.layout(1000, 1000);

const panel1 = gridview.addPanel({
id: 'panel1',
component: 'default',
});
const panel2 = gridview.addPanel({
id: 'panel2',
component: 'default',
});

expect(panel1.api.isVisible).toBeTruthy();
expect(panel2.api.isVisible).toBeTruthy();

panel1.api.setVisible(false);
expect(panel1.api.isVisible).toBeFalsy();
expect(panel2.api.isVisible).toBeTruthy();

panel1.api.setVisible(true);
expect(panel1.api.isVisible).toBeTruthy();
expect(panel2.api.isVisible).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -514,4 +514,38 @@ describe('componentPaneview', () => {

expect(paneview.disableResizing).toBeTruthy();
});

test('that setVisible toggles visiblity', () => {
const paneview = new PaneviewComponent({
parentElement: container,
components: {
default: TestPanel,
},
disableAutoResizing: true,
});

paneview.layout(1000, 1000);

const panel1 = paneview.addPanel({
id: 'panel1',
component: 'default',
title: 'panel1',
});
const panel2 = paneview.addPanel({
id: 'panel2',
component: 'default',
title: 'panel2',
});

expect(panel1.api.isVisible).toBeTruthy();
expect(panel2.api.isVisible).toBeTruthy();

panel1.api.setVisible(false);
expect(panel1.api.isVisible).toBeFalsy();
expect(panel2.api.isVisible).toBeTruthy();

panel1.api.setVisible(true);
expect(panel1.api.isVisible).toBeTruthy();
expect(panel2.api.isVisible).toBeTruthy();
});
});
Loading

0 comments on commit f00b3d8

Please sign in to comment.