UNPKG

@eclipse-emfcloud/model-service-theia

Version:
72 lines 3.53 kB
"use strict"; // ***************************************************************************** // 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 __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; 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 common_1 = require("../../common"); const backend_module_1 = __importDefault(require("../backend-module")); describe('Model Hub Contextual Injection', () => { const appContext1 = { context: 'a' }; const appContext2 = { context: 'b' }; const appContext3 = { context: 'c' }; const createContextContainer = (context) => { const child = container.createChild(); child.bind(common_1.ModelHubContext).toConstantValue(context); return child; }; let container; beforeEach(() => { container = new inversify_1.Container(); container.load(backend_module_1.default); container.bind(HasModelHub).toSelf(); }); it('one context, one hub', () => { const contextContainer = createContextContainer(appContext1); const hasModelHub = contextContainer.get(HasModelHub); (0, chai_1.expect)(hasModelHub.hub).to.exist; (0, chai_1.expect)(hasModelHub.hub).to.have.ownProperty('context', appContext1); }); it('multiple contexts, multiple hubs', function () { for (const context of [appContext1, appContext2, appContext3]) { const contextContainer = createContextContainer(context); const hasModelHub = contextContainer.get(HasModelHub); (0, chai_1.expect)(hasModelHub.hub).to.exist; (0, chai_1.expect)(hasModelHub.hub).to.have.ownProperty('context', context); } }); }); let HasModelHub = class HasModelHub { }; __decorate([ (0, inversify_1.inject)(common_1.ModelHub), __metadata("design:type", Object) ], HasModelHub.prototype, "hub", void 0); HasModelHub = __decorate([ (0, inversify_1.injectable)() ], HasModelHub); //# sourceMappingURL=model-hub-injection.spec.js.map