@eclipse-emfcloud/model-service-theia
Version:
Model service Theia
67 lines • 3.29 kB
JavaScript
;
// *****************************************************************************
// Copyright (C) 2023-2024 STMicroelectronics.
//
// 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: MIT License which is
// available at https://opensource.org/licenses/MIT.
//
// SPDX-License-Identifier: EPL-2.0 OR MIT
// *****************************************************************************
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const inversify_1 = require("@theia/core/shared/inversify");
const chai_1 = require("chai");
const sinon_1 = __importDefault(require("sinon"));
const frontend_model_accessor_bus_subscriber_1 = require("../frontend-model-accessor-bus-subscriber");
const frontend_model_hub_1 = require("../frontend-model-hub");
const fake_model_accessor_bus_protocol_1 = require("./fake-model-accessor-bus-protocol");
const test_module_1 = require("./test-module");
function createTestContainer() {
const container = new inversify_1.Container();
container.load(test_module_1.testModule);
return container;
}
describe('FrontendModelAccessorBus', () => {
const appContext = 'test-app';
let sandbox;
let frontendModelAccessorBus;
let fake;
beforeEach(async () => {
sandbox = sinon_1.default.createSandbox();
const container = createTestContainer();
const modelHub = await container.get(frontend_model_hub_1.FrontendModelHubProvider)(appContext);
frontendModelAccessorBus = modelHub.getModelAccessorBus();
const subscriber = container.get(frontend_model_accessor_bus_subscriber_1.FrontendModelAccessorBusSubscriber);
fake = container.get(fake_model_accessor_bus_protocol_1.FakeModelAccessorBusProtocol);
(0, fake_model_accessor_bus_protocol_1.connectClient)(fake, subscriber);
});
afterEach(() => {
sandbox.restore();
});
describe('Call ModelAccessorBusProtocol', () => {
it('get: expects the first parameter given (or undefined if none given)', async () => {
(0, chai_1.expect)(await frontendModelAccessorBus.get('test'), 'Get should be undefined').to.be.undefined;
(0, chai_1.expect)(await frontendModelAccessorBus.get('test', ''), 'Get should be an empty string').to.be.equal('');
});
});
describe('Delegators to FrontendModelAccessorBusSubscriber', () => {
it('subscribe', async () => {
(0, chai_1.expect)(await frontendModelAccessorBus.subscribe('test', () => console.info('test'))).to.be.eql({
id: 1,
accessorId: 'test',
});
});
it('unsubscribe', async () => {
(0, chai_1.expect)(() => frontendModelAccessorBus.unsubscribe(1)).not.to.throw();
});
});
});
//# sourceMappingURL=frontend-model-accessor-bus.spec.js.map