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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
/**
* 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);
});
it('should clear all models', function () {
var object1,
object2;
object1 = {
id: 3,
name: 'test',
test: 'ho'
};
object2 = {
id: 4,
name: 'test2'
};
childModel.add(object1);
childModel.add(object2);
childModel.clear();
expect(childModel.get(3)).not.toBeDefined();
expect(childModel.get(4)).not.toBeDefined();
expect(childModel.size()).toBe(0);
});
it('should get all models', function () {
var object1,
object2;
object1 = {
id: 3,
name: 'test',
test: 'ho'
};
object2 = {
id: 4,
name: 'test2'
};
childModel.add(object1);
childModel.add(object2);
expect(childModel.getAll()[1].id).toBe(4);
});
});
|