feat: fix deserialization active panel issue + tests

This commit is contained in:
mathuo 2022-05-16 17:57:29 +01:00
parent 0693c49098
commit b7085493a7
No known key found for this signature in database
GPG Key ID: C6EEDEFD6CA07281
5 changed files with 85 additions and 9 deletions

View File

@ -19,12 +19,16 @@ import {
GroupOptions, GroupOptions,
Groupview, Groupview,
} from '../../groupview/groupview'; } from '../../groupview/groupview';
import { DockviewPanelApi } from '../../api/groupPanelApi'; import {
DockviewPanelApi,
DockviewPanelApiImpl,
} from '../../api/groupPanelApi';
import { import {
DefaultGroupPanelView, DefaultGroupPanelView,
IGroupPanelView, IGroupPanelView,
} from '../../dockview/defaultGroupPanelView'; } from '../../dockview/defaultGroupPanelView';
import { GroupPanel } from '../../groupview/groupviewPanel'; import { GroupPanel } from '../../groupview/groupviewPanel';
import { DockviewApi } from '../../api/component.api';
class Watermark implements IWatermarkRenderer { class Watermark implements IWatermarkRenderer {
public readonly element = document.createElement('div'); public readonly element = document.createElement('div');
@ -522,4 +526,49 @@ describe('groupview', () => {
hideHeader: true, hideHeader: true,
}); });
}); });
test("that openPanel with skipSetActive doesn't set panel to active", () => {
const dockviewComponent: IDockviewComponent = new DockviewComponent(
document.createElement('div'),
{
components: {
component: TestContentPart,
},
}
);
const groupviewContainer = document.createElement('div');
const cut = new Groupview(
groupviewContainer,
dockviewComponent,
'id',
{},
null
);
const contentContainer = groupviewContainer
.getElementsByClassName('content-container')
.item(0).childNodes;
const panel1 = new TestPanel('id_1', null);
cut.openPanel(panel1);
expect(contentContainer.length).toBe(1);
expect(contentContainer.item(0)).toBe(panel1.view.content.element);
const panel2 = new TestPanel('id_2', null);
cut.openPanel(panel2);
expect(contentContainer.length).toBe(1);
expect(contentContainer.item(0)).toBe(panel2.view.content.element);
const panel3 = new TestPanel('id_2', null);
cut.openPanel(panel3, { skipSetActive: true });
expect(contentContainer.length).toBe(1);
expect(contentContainer.item(0)).toBe(panel2.view.content.element);
cut.openPanel(panel3);
expect(contentContainer.length).toBe(1);
expect(contentContainer.item(0)).toBe(panel3.view.content.element);
});
}); });

View File

@ -0,0 +1,25 @@
import { Tab } from '../../groupview/tab';
describe('tab', () => {
test('that empty tab has inactive-tab class', () => {
const accessorMock = jest.fn();
const groupMock = jest.fn();
const cut = new Tab('panelId', new accessorMock(), new groupMock());
expect(cut.element.className).toBe('tab inactive-tab');
});
test('that active tab has active-tab class', () => {
const accessorMock = jest.fn();
const groupMock = jest.fn();
const cut = new Tab('panelId', new accessorMock(), new groupMock());
cut.setActive(true);
expect(cut.element.className).toBe('tab active-tab');
cut.setActive(false);
expect(cut.element.className).toBe('tab inactive-tab');
});
});

View File

@ -420,7 +420,7 @@ export class Groupview extends CompositeDisposable implements IGroupview {
return; return;
} }
this.doAddPanel(panel, options.index); this.doAddPanel(panel, options.index, skipSetActive);
if (!skipSetActive) { if (!skipSetActive) {
this.doSetActivePanel(panel); this.doSetActivePanel(panel);
@ -561,14 +561,17 @@ export class Groupview extends CompositeDisposable implements IGroupview {
private doAddPanel( private doAddPanel(
panel: IDockviewPanel, panel: IDockviewPanel,
index: number = this.panels.length index: number = this.panels.length,
skipSetActive = false
) { ) {
const existingPanel = this._panels.indexOf(panel); const existingPanel = this._panels.indexOf(panel);
const hasExistingPanel = existingPanel > -1; const hasExistingPanel = existingPanel > -1;
this.tabsContainer.openPanel(panel, index); this.tabsContainer.openPanel(panel, index);
this.contentContainer.openPanel(panel); if (!skipSetActive) {
this.contentContainer.openPanel(panel);
}
this.tabsContainer.show(); this.tabsContainer.show();
this.contentContainer.show(); this.contentContainer.show();

View File

@ -64,6 +64,8 @@ export class Tab extends CompositeDisposable implements ITab {
this._element.tabIndex = 0; this._element.tabIndex = 0;
this._element.draggable = true; this._element.draggable = true;
toggleClass(this.element, 'inactive-tab', true);
this.addDisposables( this.addDisposables(
new (class Handler extends DragHandler { new (class Handler extends DragHandler {
private readonly panelTransfer = private readonly panelTransfer =

View File

@ -51,8 +51,6 @@ export class TabsContainer
private tabs: IValueDisposable<ITab>[] = []; private tabs: IValueDisposable<ITab>[] = [];
private selectedIndex = -1; private selectedIndex = -1;
private active = false;
private activePanel: IDockviewPanel | undefined;
private actions: HTMLElement | undefined; private actions: HTMLElement | undefined;
private _height: number | undefined; private _height: number | undefined;
@ -205,8 +203,8 @@ export class TabsContainer
); );
} }
public setActive(isGroupActive: boolean) { public setActive(_isGroupActive: boolean) {
this.active = isGroupActive; // noop
} }
private addTab( private addTab(
@ -291,7 +289,6 @@ export class TabsContainer
const value: IValueDisposable<ITab> = { value: tabToAdd, disposable }; const value: IValueDisposable<ITab> = { value: tabToAdd, disposable };
this.addTab(value, index); this.addTab(value, index);
this.activePanel = panel;
} }
public closePanel(panel: IDockviewPanel) { public closePanel(panel: IDockviewPanel) {