Merge pull request #29 from mathuo/23-increase-test-coverage

tests: add tests
This commit is contained in:
mathuo 2022-03-11 22:42:23 +00:00 committed by GitHub
commit 0d9abc4937
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 155 additions and 20 deletions

View File

@ -0,0 +1,135 @@
import { DockviewComponent } from '../..';
import {
SplitviewApi,
PaneviewApi,
GridviewApi,
DockviewApi,
} from '../../api/component.api';
import { GridviewComponent } from '../../gridview/gridviewComponent';
import { PaneviewComponent } from '../../paneview/paneviewComponent';
import { SplitviewComponent } from '../../splitview/splitviewComponent';
describe('component.api', () => {
describe('splitview', () => {
test('splitviewapi', () => {
const list: (keyof SplitviewComponent)[] = [
'minimumSize',
'maximumSize',
'height',
'width',
'length',
'orientation',
'onDidLayoutChange',
'onDidAddView',
'onDidRemoveView',
];
for (const _ of list) {
const f = jest.fn();
const component: Partial<SplitviewComponent> = {
[_]: f(),
};
const cut = new SplitviewApi(<SplitviewComponent>component);
expect((cut as any)[_]).toBeFalsy();
expect(f).toBeCalledTimes(1);
}
});
});
describe('paneview', () => {
test('panviewapi', () => {
const list: (keyof PaneviewComponent)[] = [
'minimumSize',
'maximumSize',
'height',
'width',
'onDidLayoutChange',
'onDidAddView',
'onDidRemoveView',
];
for (const _ of list) {
const f = jest.fn();
const component: Partial<PaneviewComponent> = {
[_]: f(),
};
const cut = new PaneviewApi(<PaneviewComponent>component);
expect((cut as any)[_]).toBeFalsy();
expect(f).toBeCalledTimes(1);
}
});
});
describe('gridview', () => {
test('gridviewapi', () => {
const list: (keyof GridviewComponent)[] = [
'minimumHeight',
'maximumHeight',
'minimumWidth',
'maximumWidth',
'width',
'height',
'onGridEvent',
'onDidLayoutChange',
'orientation',
];
for (const _ of list) {
const f = jest.fn();
const component: Partial<GridviewComponent> = {
[_]: f(),
};
const cut = new GridviewApi(<GridviewComponent>component);
expect((cut as any)[_]).toBeFalsy();
expect(f).toBeCalledTimes(1);
}
});
});
describe('dockview', () => {
test('dockviewapi', () => {
const list: (keyof DockviewComponent)[] = [
'minimumHeight',
'maximumHeight',
'minimumWidth',
'maximumWidth',
'width',
'height',
'size',
'totalPanels',
'onGridEvent',
'onDidLayoutChange',
'panels',
'groups',
'activeGroup',
'activePanel',
];
for (const _ of list) {
const f = jest.fn();
const component: Partial<DockviewComponent> = {
[_]: f(),
};
const cut = new DockviewApi(<DockviewComponent>component);
expect((cut as any)[_]).toBeFalsy();
expect(f).toBeCalledTimes(1);
}
});
});
});

View File

@ -64,6 +64,10 @@ export class SplitviewApi implements CommonApi {
return this.component.length;
}
get orientation(): Orientation {
return this.component.orientation;
}
get onDidLayoutChange(): Event<void> {
return this.component.onDidLayoutChange;
}
@ -76,10 +80,6 @@ export class SplitviewApi implements CommonApi {
return this.component.onDidRemoveView;
}
get orientation(): Orientation {
return this.component.orientation;
}
constructor(private readonly component: ISplitviewComponent) {}
updateOptions(options: SplitviewComponentUpdateOptions): void {
@ -136,14 +136,6 @@ export class SplitviewApi implements CommonApi {
}
export class PaneviewApi implements CommonApi {
get width(): number {
return this.component.width;
}
get height(): number {
return this.component.height;
}
get minimumSize(): number {
return this.component.minimumSize;
}
@ -152,6 +144,14 @@ export class PaneviewApi implements CommonApi {
return this.component.maximumSize;
}
get height(): number {
return this.component.height;
}
get width(): number {
return this.component.width;
}
get onDidLayoutChange(): Event<void> {
return this.component.onDidLayoutChange;
}
@ -223,14 +223,6 @@ export class PaneviewApi implements CommonApi {
}
export class GridviewApi implements CommonApi {
get width(): number {
return this.component.width;
}
get height(): number {
return this.component.height;
}
get minimumHeight(): number {
return this.component.minimumHeight;
}
@ -247,6 +239,14 @@ export class GridviewApi implements CommonApi {
return this.component.maximumWidth;
}
get width(): number {
return this.component.width;
}
get height(): number {
return this.component.height;
}
get onGridEvent(): Event<GroupChangeEvent> {
return this.component.onGridEvent;
}