tests: add tests

This commit is contained in:
mathuo 2022-03-12 21:32:43 +00:00
parent 0d9abc4937
commit 9608ec957d
No known key found for this signature in database
GPG Key ID: C6EEDEFD6CA07281
2 changed files with 54 additions and 7 deletions

View File

@ -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);
} }

View File

@ -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);
});
}); });