@theia/core
Version:
Theia is a cloud & desktop IDE framework implemented in TypeScript.
90 lines • 3.72 kB
JavaScript
// *****************************************************************************
// Copyright (C) 2026 Vinay Kaushal and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0.
//
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
// with the GNU Classpath Exception which is available at
// https://www.gnu.org/software/classpath/license.html.
//
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
// *****************************************************************************
import { enableJSDOM } from './test/jsdom.js';
let disableJSDOM = enableJSDOM();
import { expect } from 'chai';
import { Widget } from './widgets/index.js';
import { WidgetStatusBarService } from './widget-status-bar-service.js';
disableJSDOM();
class HandledWidget extends Widget {
}
class TestWidgetStatusBarContribution {
canHandle(widget) {
return widget instanceof HandledWidget;
}
activate(statusBar, widget) {
this.active = widget;
}
deactivate(statusBar) {
this.active = undefined;
}
}
class TestWidgetStatusBarService extends WidgetStatusBarService {
show(widget) {
super.show(widget);
}
}
describe('WidgetStatusBarService', () => {
let contribution;
let service;
before(() => disableJSDOM = enableJSDOM());
after(() => disableJSDOM());
beforeEach(() => {
contribution = new TestWidgetStatusBarContribution();
service = new TestWidgetStatusBarService();
const contributionProvider = {
getContributions: () => [contribution]
};
Object.assign(service, { contributionProvider, statusBar: {} });
});
it('activates the contributions that handle the current widget', () => {
const widget = new HandledWidget();
service.show(widget);
expect(contribution.active).to.equal(widget);
});
it('keeps the status bar as is for a widget no contribution handles', () => {
const widget = new HandledWidget();
service.show(widget);
service.show(new Widget());
expect(contribution.active).to.equal(widget);
});
it('deactivates the contributions when the shown widget is disposed', () => {
const widget = new HandledWidget();
service.show(widget);
service.show(new Widget());
widget.dispose();
expect(contribution.active).to.be.undefined;
});
it('ignores the disposal of a widget that is no longer shown', () => {
const first = new HandledWidget();
const second = new HandledWidget();
service.show(first);
service.show(second);
first.dispose();
expect(contribution.active).to.equal(second);
});
it('keeps the items of the next widget when the shown widget is closed and the next one becomes current', () => {
const first = new HandledWidget();
const second = new HandledWidget();
// Like the shell's focus tracker, which handles `disposed` before the service and makes the next widget current:
// `show(second)` disconnects the service's `disposed` listener of `first` during the emit, so it must not run.
first.disposed.connect(() => service.show(second));
service.show(first);
first.dispose();
expect(contribution.active).to.equal(second);
});
});
//# sourceMappingURL=widget-status-bar-service.spec.js.map