1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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);
});
});
|