mirror of
https://github.com/mathuo/dockview
synced 2025-05-02 09:38: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',
|
||||
'onDidAddView',
|
||||
'onDidRemoveView',
|
||||
'getPanels',
|
||||
'focus',
|
||||
'resizeToFit',
|
||||
'toJSON',
|
||||
];
|
||||
|
||||
for (const _ of list) {
|
||||
@ -33,7 +37,7 @@ describe('component.api', () => {
|
||||
|
||||
const cut = new SplitviewApi(<SplitviewComponent>component);
|
||||
|
||||
expect((cut as any)[_]).toBeFalsy();
|
||||
(cut as any)[_];
|
||||
|
||||
expect(f).toBeCalledTimes(1);
|
||||
}
|
||||
@ -50,6 +54,10 @@ describe('component.api', () => {
|
||||
'onDidLayoutChange',
|
||||
'onDidAddView',
|
||||
'onDidRemoveView',
|
||||
'getPanels',
|
||||
'focus',
|
||||
'resizeToFit',
|
||||
'toJSON',
|
||||
];
|
||||
|
||||
for (const _ of list) {
|
||||
@ -61,7 +69,7 @@ describe('component.api', () => {
|
||||
|
||||
const cut = new PaneviewApi(<PaneviewComponent>component);
|
||||
|
||||
expect((cut as any)[_]).toBeFalsy();
|
||||
(cut as any)[_];
|
||||
|
||||
expect(f).toBeCalledTimes(1);
|
||||
}
|
||||
@ -80,6 +88,9 @@ describe('component.api', () => {
|
||||
'onGridEvent',
|
||||
'onDidLayoutChange',
|
||||
'orientation',
|
||||
'focus',
|
||||
'resizeToFit',
|
||||
'toJSON',
|
||||
];
|
||||
|
||||
for (const _ of list) {
|
||||
@ -91,7 +102,7 @@ describe('component.api', () => {
|
||||
|
||||
const cut = new GridviewApi(<GridviewComponent>component);
|
||||
|
||||
expect((cut as any)[_]).toBeFalsy();
|
||||
(cut as any)[_];
|
||||
|
||||
expect(f).toBeCalledTimes(1);
|
||||
}
|
||||
@ -115,6 +126,10 @@ describe('component.api', () => {
|
||||
'groups',
|
||||
'activeGroup',
|
||||
'activePanel',
|
||||
'focus',
|
||||
'closeAllGroups',
|
||||
'resizeToFit',
|
||||
'toJSON',
|
||||
];
|
||||
|
||||
for (const _ of list) {
|
||||
@ -126,7 +141,7 @@ describe('component.api', () => {
|
||||
|
||||
const cut = new DockviewApi(<DockviewComponent>component);
|
||||
|
||||
expect((cut as any)[_]).toBeFalsy();
|
||||
(cut as any)[_];
|
||||
|
||||
expect(f).toBeCalledTimes(1);
|
||||
}
|
||||
|
@ -1,4 +1,7 @@
|
||||
import { IDockviewComponent } from '../../dockview/dockviewComponent';
|
||||
import {
|
||||
IDockviewComponent,
|
||||
DockviewComponent,
|
||||
} from '../../dockview/dockviewComponent';
|
||||
import {
|
||||
GroupviewPanelState,
|
||||
IGroupPanel,
|
||||
@ -198,13 +201,21 @@ describe('groupview', () => {
|
||||
let dockview: IDockviewComponent;
|
||||
let options: GroupOptions;
|
||||
|
||||
let removePanelMock: jest.Mock;
|
||||
let removeGroupMock: jest.Mock;
|
||||
|
||||
beforeEach(() => {
|
||||
dockview = <IDockviewComponent>(<any>{
|
||||
removePanelMock = jest.fn();
|
||||
removeGroupMock = jest.fn();
|
||||
|
||||
dockview = (<Partial<DockviewComponent>>{
|
||||
options: {},
|
||||
createWatermarkComponent: () => new Watermark(),
|
||||
doSetGroupActive: jest.fn(),
|
||||
id: 'dockview-1',
|
||||
});
|
||||
removePanel: removePanelMock,
|
||||
removeGroup: removeGroupMock,
|
||||
}) as DockviewComponent;
|
||||
|
||||
options = {
|
||||
tabHeight: 30,
|
||||
@ -412,4 +423,25 @@ describe('groupview', () => {
|
||||
);
|
||||
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