diff options
author | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-05-18 18:51:16 +0200 |
---|---|---|
committer | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-05-18 18:51:16 +0200 |
commit | e2e9a79aa3acb0d3a02d81ddbfbdcacc676db2d2 (patch) | |
tree | 85640355ebe88fd3627f9701b803e85713854200 /js/tests/unit | |
parent | aae89820dbb1b21b14272f5358761b9876e8ea09 (diff) |
add model
Diffstat (limited to 'js/tests/unit')
-rw-r--r-- | js/tests/unit/service/ModelSpec.js | 103 | ||||
-rw-r--r-- | js/tests/unit/service/PublisherSpec.js | 26 |
2 files changed, 129 insertions, 0 deletions
diff --git a/js/tests/unit/service/ModelSpec.js b/js/tests/unit/service/ModelSpec.js new file mode 100644 index 000000000..d8aba1520 --- /dev/null +++ b/js/tests/unit/service/ModelSpec.js @@ -0,0 +1,103 @@ +/** + * ownCloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright Bernhard Posselt 2014 + */ +describe('Model', function () { + 'use strict'; + + var childModel; + + beforeEach(module('News')); + + beforeEach(inject(function (Model) { + var ChildModel = function () { + Model.call(this, 'id'); + }; + ChildModel.prototype = Object.create(Model.prototype); + + childModel = new ChildModel(); + })); + + + it('should receive an object', function () { + var objects = [ + { + id: 2 + }, + { + id: 3 + } + ]; + + childModel.receive(objects); + + expect(childModel.size()).toBe(2); + }); + + + it('should add an object', function () { + var object = { + id: 3, + name: 'test' + }; + childModel.add(object); + + expect(childModel.get(3)).toBe(object); + }); + + + it('should overwrite an object if it already exists', function () { + var object1, + object2; + + object1 = { + id: 3, + name: 'test', + test: 'ho' + }; + + object2 = { + id: 3, + name: 'test2' + }; + + childModel.add(object1); + childModel.add(object2); + + expect(childModel.get(3).name).toBe('test2'); + expect(childModel.get(3).test).toBe('ho'); + expect(childModel.size()).toBe(1); + }); + + + it('should delete a model', function () { + var object1, + object2; + + object1 = { + id: 3, + name: 'test', + test: 'ho' + }; + + object2 = { + id: 4, + name: 'test2' + }; + + childModel.add(object1); + childModel.add(object2); + + childModel.delete(3); + + expect(childModel.get(3)).not.toBeDefined(); + expect(childModel.get(4).name).toBe('test2'); + expect(childModel.size()).toBe(1); + }); + +});
\ No newline at end of file diff --git a/js/tests/unit/service/PublisherSpec.js b/js/tests/unit/service/PublisherSpec.js new file mode 100644 index 000000000..8a019f0db --- /dev/null +++ b/js/tests/unit/service/PublisherSpec.js @@ -0,0 +1,26 @@ +/** + * ownCloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright Bernhard Posselt 2014 + */ +describe('Publisher', function () { + 'use strict'; + + beforeEach(module('News')); + + it('should subscribe an object and publish a message', inject(function (Publisher) { + var obj = { + receive: jasmine.createSpy('receive') + }; + Publisher.subscribe(obj).toChannel('test'); + + Publisher.publish('tom').onChannel('test'); + expect(obj.receive).toHaveBeenCalledWith('tom'); + })); + + +});
\ No newline at end of file |