diff --git a/platform/core/test/services/ThrottleSpec.js b/platform/core/test/services/ThrottleSpec.js index 173fad8006..bcaf2af363 100644 --- a/platform/core/test/services/ThrottleSpec.js +++ b/platform/core/test/services/ThrottleSpec.js @@ -1,3 +1,24 @@ +/***************************************************************************** + * Open MCT Web, Copyright (c) 2014-2015, United States Government + * as represented by the Administrator of the National Aeronautics and Space + * Administration. All rights reserved. + * + * Open MCT Web is licensed under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * Open MCT Web includes source code licensed under additional open source + * licenses. See the Open Source Licenses file (LICENSES.md) included with + * this source code distribution or the Licensing information page available + * at runtime from the About dialog for additional information. + *****************************************************************************/ /*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine*/ define( diff --git a/platform/core/test/services/TopicSpec.js b/platform/core/test/services/TopicSpec.js new file mode 100644 index 0000000000..b389b19579 --- /dev/null +++ b/platform/core/test/services/TopicSpec.js @@ -0,0 +1,70 @@ +/***************************************************************************** + * Open MCT Web, Copyright (c) 2014-2015, United States Government + * as represented by the Administrator of the National Aeronautics and Space + * Administration. All rights reserved. + * + * Open MCT Web is licensed under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * Open MCT Web includes source code licensed under additional open source + * licenses. See the Open Source Licenses file (LICENSES.md) included with + * this source code distribution or the Licensing information page available + * at runtime from the About dialog for additional information. + *****************************************************************************/ +/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine*/ + +define( + ["../../src/services/Topic"], + function (Topic) { + "use strict"; + + describe("The 'topic' service", function () { + var topic, + testMessage, + mockCallback; + + beforeEach(function () { + testMessage = { someKey: "some value"}; + mockCallback = jasmine.createSpy('callback'); + topic = new Topic(); + }); + + it("notifies listeners on a topic", function () { + topic("abc").listen(mockCallback); + topic("abc").notify(testMessage); + expect(mockCallback).toHaveBeenCalledWith(testMessage); + }); + + it("does not notify listeners across topics", function () { + topic("abc").listen(mockCallback); + topic("xyz").notify(testMessage); + expect(mockCallback).not.toHaveBeenCalledWith(testMessage); + }); + + it("does not notify listeners after unlistening", function () { + topic("abc").listen(mockCallback)(); // Unlisten immediately + topic("abc").notify(testMessage); + expect(mockCallback).not.toHaveBeenCalledWith(testMessage); + }); + + it("provides anonymous private topics", function () { + var t1 = topic(), t2 = topic(); + + t1.listen(mockCallback); + t2.notify(testMessage); + expect(mockCallback).not.toHaveBeenCalledWith(testMessage); + t1.notify(testMessage); + expect(mockCallback).toHaveBeenCalledWith(testMessage); + }); + + }); + } +); diff --git a/platform/core/test/suite.json b/platform/core/test/suite.json index 9c939acf5e..acc7391d02 100644 --- a/platform/core/test/suite.json +++ b/platform/core/test/suite.json @@ -25,6 +25,7 @@ "services/Now", "services/Throttle", + "services/Topic", "types/MergeModels", "types/TypeCapability", @@ -35,4 +36,4 @@ "views/ViewCapability", "views/ViewProvider" -] \ No newline at end of file +]