|
| 1 | +/* |
| 2 | + * GNU AGPL-3.0 License |
| 3 | + * |
| 4 | + * Modified Work Copyright (c) 2021 - present core.ai . All rights reserved. |
| 5 | + * Original work Copyright (c) 2013 - 2021 Adobe Systems Incorporated. All rights reserved. |
| 6 | + * |
| 7 | + * This program is free software: you can redistribute it and/or modify it |
| 8 | + * under the terms of the GNU Affero General Public License as published by |
| 9 | + * the Free Software Foundation, either version 3 of the License, or |
| 10 | + * (at your option) any later version. |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, but WITHOUT |
| 13 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License |
| 15 | + * for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU Affero General Public License |
| 18 | + * along with this program. If not, see https://opensource.org/licenses/AGPL-3.0. |
| 19 | + * |
| 20 | + */ |
| 21 | + |
| 22 | +/*global describe, it, expect, beforeFirst, afterLast, beforeEach, afterEach, waitsFor, runs, waitsForDone */ |
| 23 | + |
| 24 | +define(function (require, exports, module) { |
| 25 | + const ExtensionInterface = require("utils/ExtensionInterface"), |
| 26 | + INTERFACE_OBJ = { |
| 27 | + "hello": "world" |
| 28 | + }; |
| 29 | + |
| 30 | + describe("Extension Interface tests", function () { |
| 31 | + it("should return a registered interface", function () { |
| 32 | + const INTERFACE_1 = "int1"; |
| 33 | + ExtensionInterface.registerExtensionInterface(INTERFACE_1, INTERFACE_OBJ); |
| 34 | + expect(ExtensionInterface.isExistsExtensionInterface(INTERFACE_1)).toEqual(true); |
| 35 | + }); |
| 36 | + |
| 37 | + it("should raise event on extension registration", function () { |
| 38 | + const INTERFACE_1 = "int1"; |
| 39 | + let notified = false, interfaceObjNotified = null; |
| 40 | + ExtensionInterface.on(ExtensionInterface.EVENT_EXTENSION_INTERFACE_REGISTERED, (event, name, intrfaceObj)=>{ |
| 41 | + notified = name; |
| 42 | + interfaceObjNotified = intrfaceObj; |
| 43 | + }); |
| 44 | + ExtensionInterface.registerExtensionInterface(INTERFACE_1, INTERFACE_OBJ); |
| 45 | + expect(ExtensionInterface.isExistsExtensionInterface(INTERFACE_1)).toEqual(true); |
| 46 | + waitsFor(function () { |
| 47 | + return notified === INTERFACE_1 && interfaceObjNotified === INTERFACE_OBJ; |
| 48 | + }, 100, "extension interface registration notification"); |
| 49 | + }); |
| 50 | + |
| 51 | + it("should await and get the extension interface", function () { |
| 52 | + const INTERFACE_2 = "int2"; |
| 53 | + let extensionInterface = null; |
| 54 | + ExtensionInterface.awaitGetExtensionInterface(INTERFACE_2).then((interfaceObj)=>{ |
| 55 | + extensionInterface = interfaceObj; |
| 56 | + }); |
| 57 | + |
| 58 | + ExtensionInterface.registerExtensionInterface(INTERFACE_2, INTERFACE_OBJ); |
| 59 | + waitsFor(function () { |
| 60 | + return extensionInterface === INTERFACE_OBJ; |
| 61 | + }, 100, "awaiting extension interface"); |
| 62 | + }); |
| 63 | + }); |
| 64 | +}); |
0 commit comments