mirror of
https://github.com/mathuo/dockview
synced 2025-05-04 18:48:26 +00:00
Merge pull request #30 from mathuo/23-increase-test-coverage
tests: add tests
This commit is contained in:
commit
ce46422347
@ -22,6 +22,10 @@ describe('component.api', () => {
|
|||||||
'onDidLayoutChange',
|
'onDidLayoutChange',
|
||||||
'onDidAddView',
|
'onDidAddView',
|
||||||
'onDidRemoveView',
|
'onDidRemoveView',
|
||||||
|
'getPanels',
|
||||||
|
'focus',
|
||||||
|
'resizeToFit',
|
||||||
|
'toJSON',
|
||||||
];
|
];
|
||||||
|
|
||||||
for (const _ of list) {
|
for (const _ of list) {
|
||||||
@ -33,7 +37,7 @@ describe('component.api', () => {
|
|||||||
|
|
||||||
const cut = new SplitviewApi(<SplitviewComponent>component);
|
const cut = new SplitviewApi(<SplitviewComponent>component);
|
||||||
|
|
||||||
expect((cut as any)[_]).toBeFalsy();
|
(cut as any)[_];
|
||||||
|
|
||||||
expect(f).toBeCalledTimes(1);
|
expect(f).toBeCalledTimes(1);
|
||||||
}
|
}
|
||||||
@ -50,6 +54,10 @@ describe('component.api', () => {
|
|||||||
'onDidLayoutChange',
|
'onDidLayoutChange',
|
||||||
'onDidAddView',
|
'onDidAddView',
|
||||||
'onDidRemoveView',
|
'onDidRemoveView',
|
||||||
|
'getPanels',
|
||||||
|
'focus',
|
||||||
|
'resizeToFit',
|
||||||
|
'toJSON',
|
||||||
];
|
];
|
||||||
|
|
||||||
for (const _ of list) {
|
for (const _ of list) {
|
||||||
@ -61,7 +69,7 @@ describe('component.api', () => {
|
|||||||
|
|
||||||
const cut = new PaneviewApi(<PaneviewComponent>component);
|
const cut = new PaneviewApi(<PaneviewComponent>component);
|
||||||
|
|
||||||
expect((cut as any)[_]).toBeFalsy();
|
(cut as any)[_];
|
||||||
|
|
||||||
expect(f).toBeCalledTimes(1);
|
expect(f).toBeCalledTimes(1);
|
||||||
}
|
}
|
||||||
@ -80,6 +88,9 @@ describe('component.api', () => {
|
|||||||
'onGridEvent',
|
'onGridEvent',
|
||||||
'onDidLayoutChange',
|
'onDidLayoutChange',
|
||||||
'orientation',
|
'orientation',
|
||||||
|
'focus',
|
||||||
|
'resizeToFit',
|
||||||
|
'toJSON',
|
||||||
];
|
];
|
||||||
|
|
||||||
for (const _ of list) {
|
for (const _ of list) {
|
||||||
@ -91,7 +102,7 @@ describe('component.api', () => {
|
|||||||
|
|
||||||
const cut = new GridviewApi(<GridviewComponent>component);
|
const cut = new GridviewApi(<GridviewComponent>component);
|
||||||
|
|
||||||
expect((cut as any)[_]).toBeFalsy();
|
(cut as any)[_];
|
||||||
|
|
||||||
expect(f).toBeCalledTimes(1);
|
expect(f).toBeCalledTimes(1);
|
||||||
}
|
}
|
||||||
@ -115,6 +126,10 @@ describe('component.api', () => {
|
|||||||
'groups',
|
'groups',
|
||||||
'activeGroup',
|
'activeGroup',
|
||||||
'activePanel',
|
'activePanel',
|
||||||
|
'focus',
|
||||||
|
'closeAllGroups',
|
||||||
|
'resizeToFit',
|
||||||
|
'toJSON',
|
||||||
];
|
];
|
||||||
|
|
||||||
for (const _ of list) {
|
for (const _ of list) {
|
||||||
@ -126,7 +141,7 @@ describe('component.api', () => {
|
|||||||
|
|
||||||
const cut = new DockviewApi(<DockviewComponent>component);
|
const cut = new DockviewApi(<DockviewComponent>component);
|
||||||
|
|
||||||
expect((cut as any)[_]).toBeFalsy();
|
(cut as any)[_];
|
||||||
|
|
||||||
expect(f).toBeCalledTimes(1);
|
expect(f).toBeCalledTimes(1);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
import { IDockviewComponent } from '../../dockview/dockviewComponent';
|
import {
|
||||||
|
IDockviewComponent,
|
||||||
|
DockviewComponent,
|
||||||
|
} from '../../dockview/dockviewComponent';
|
||||||
import {
|
import {
|
||||||
GroupviewPanelState,
|
GroupviewPanelState,
|
||||||
IGroupPanel,
|
IGroupPanel,
|
||||||
@ -198,13 +201,21 @@ describe('groupview', () => {
|
|||||||
let dockview: IDockviewComponent;
|
let dockview: IDockviewComponent;
|
||||||
let options: GroupOptions;
|
let options: GroupOptions;
|
||||||
|
|
||||||
|
let removePanelMock: jest.Mock;
|
||||||
|
let removeGroupMock: jest.Mock;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
dockview = <IDockviewComponent>(<any>{
|
removePanelMock = jest.fn();
|
||||||
|
removeGroupMock = jest.fn();
|
||||||
|
|
||||||
|
dockview = (<Partial<DockviewComponent>>{
|
||||||
options: {},
|
options: {},
|
||||||
createWatermarkComponent: () => new Watermark(),
|
createWatermarkComponent: () => new Watermark(),
|
||||||
doSetGroupActive: jest.fn(),
|
doSetGroupActive: jest.fn(),
|
||||||
id: 'dockview-1',
|
id: 'dockview-1',
|
||||||
});
|
removePanel: removePanelMock,
|
||||||
|
removeGroup: removeGroupMock,
|
||||||
|
}) as DockviewComponent;
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
tabHeight: 30,
|
tabHeight: 30,
|
||||||
@ -412,4 +423,25 @@ describe('groupview', () => {
|
|||||||
);
|
);
|
||||||
expect(viewQuery).toBeTruthy();
|
expect(viewQuery).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('closeAllPanels with panels', () => {
|
||||||
|
const panel1 = new TestPanel('panel1', jest.fn() as any);
|
||||||
|
const panel2 = new TestPanel('panel2', jest.fn() as any);
|
||||||
|
const panel3 = new TestPanel('panel3', jest.fn() as any);
|
||||||
|
|
||||||
|
groupview.model.openPanel(panel1);
|
||||||
|
groupview.model.openPanel(panel2);
|
||||||
|
groupview.model.openPanel(panel3);
|
||||||
|
|
||||||
|
groupview.model.closeAllPanels();
|
||||||
|
|
||||||
|
expect(removePanelMock).toBeCalledWith(panel1);
|
||||||
|
expect(removePanelMock).toBeCalledWith(panel2);
|
||||||
|
expect(removePanelMock).toBeCalledWith(panel3);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('closeAllPanels with no panels', () => {
|
||||||
|
groupview.model.closeAllPanels();
|
||||||
|
expect(removeGroupMock).toBeCalledWith(groupview);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,71 +0,0 @@
|
|||||||
import { IDisposable } from '../../lifecycle';
|
|
||||||
import { IGroupPanel } from '../groupPanel';
|
|
||||||
import { IRenderable } from '../types';
|
|
||||||
|
|
||||||
export interface HostedPanelOptions {
|
|
||||||
id: string;
|
|
||||||
parent?: HTMLElement;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class HostedPanel implements IRenderable, IDisposable {
|
|
||||||
private readonly _element: HTMLElement;
|
|
||||||
|
|
||||||
get element() {
|
|
||||||
return this._element;
|
|
||||||
}
|
|
||||||
|
|
||||||
get id() {
|
|
||||||
return this.panel.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
private readonly panel: IGroupPanel,
|
|
||||||
private readonly options: HostedPanelOptions
|
|
||||||
) {
|
|
||||||
if (!options.parent) {
|
|
||||||
options.parent = document.getElementById('app') as HTMLElement;
|
|
||||||
options.parent.style.position = 'relative';
|
|
||||||
}
|
|
||||||
|
|
||||||
this._element = document.createElement('div');
|
|
||||||
this._element.style.visibility = 'hidden';
|
|
||||||
this._element.style.overflow = 'hidden';
|
|
||||||
// this._element.style.pointerEvents = 'none';
|
|
||||||
this._element.id = `webivew-${options.id}`;
|
|
||||||
|
|
||||||
options.parent.appendChild(this._element);
|
|
||||||
}
|
|
||||||
|
|
||||||
hide() {
|
|
||||||
this._element.style.visibility = 'hidden';
|
|
||||||
}
|
|
||||||
|
|
||||||
show() {
|
|
||||||
this._element.style.visibility = 'visible';
|
|
||||||
}
|
|
||||||
|
|
||||||
layout(
|
|
||||||
element: HTMLElement,
|
|
||||||
dimension?: { width: number; height: number }
|
|
||||||
) {
|
|
||||||
if (!this.element || !this.element.parentElement) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const frameRect = element.getBoundingClientRect();
|
|
||||||
const containerRect =
|
|
||||||
this.element.parentElement.getBoundingClientRect();
|
|
||||||
this.element.style.position = 'absolute';
|
|
||||||
this.element.style.top = `${frameRect.top - containerRect.top}px`;
|
|
||||||
this.element.style.left = `${frameRect.left - containerRect.left}px`;
|
|
||||||
this.element.style.width = `${
|
|
||||||
dimension ? dimension.width : frameRect.width
|
|
||||||
}px`;
|
|
||||||
this.element.style.height = `${
|
|
||||||
dimension ? dimension.height : frameRect.height
|
|
||||||
}px`;
|
|
||||||
}
|
|
||||||
|
|
||||||
dispose() {
|
|
||||||
this._element.remove();
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user