-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmirador.test.js
206 lines (147 loc) · 5.84 KB
/
mirador.test.js
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
describe('Mirador | mirador.js', function() {
var $;
beforeEach(function() {
localStorage.clear();
// suppress console messages in Jasmine output
console.error = function() { return true; }
console.log = function() { return true; }
loadFixtures('mirador.html');
Mirador({
id: 'viewer',
data: [{
"manifestUri": "spec/data/Walters/bd183mz0176/manifest.json",
"location": "Stanford University",
"title": "MS 5",
"widgets": []
}]
});
$ = Mirador;
});
// Tests for object initialization
describe('Initialization', function() {
it('should set "manifests" property', function() {
expect(Mirador.manifests).toBeTruthy();
});
it('should set "viewer" property', function() {
expect(Mirador.viewer).toBeTruthy();
});
});
// Tests for utility methods
describe('Utility methods', function() {
beforeEach(function() {
Mirador.DEFAULT_SETTINGS.availableViews = { 'xyzView': { 'label': 'Xyz View' } };
});
it('should validate a view from available views', function() {
expect($.isValidView('newView')).toBeTruthy();
});
it('should convert inArray value to boolean', function() {
expect($.inArrayToBoolean(1)).toBeTruthy();
expect($.inArrayToBoolean(-1)).toBeFalsy();
});
it('should cast an object to array if string, or return the object', function() {
expect($.castToArray('str')).toEqual(['str']);
expect($.castToArray(['str'])).toEqual(['str']);
expect($.castToArray({})).toEqual({});
});
it('should return an unique array from a given array', function() {
expect($.getUniques(['a', 'b', 'b', 'a'])).toEqual(['a', 'b']);
});
it('should return a title prefix from a metadata object', function() {
expect($.getTitlePrefix({ label: 'Collection 123' })).toEqual('Collection 123');
expect($.getTitlePrefix({})).toEqual('');
});
it('should trim string by given length and add ellipsis', function() {
expect($.trimStringBy('The painting is framed by illuminated borders', 25)).toEqual('The painting is framed by...');
expect($.trimStringBy('The painting is framed', 25)).toEqual('The painting is framed');
});
it('should trim trailing whitespaces from a string', function() {
expect($.trimString(' abc ')).toEqual('abc');
});
it('should stringify a JavaScript object with padded HTML for printing', function() {
expect($.stringifyObject('mirador')).toEqual('mirador');
expect($.stringifyObject(new RegExp('ab+c'))).toEqual('/ab+c/');
expect($.stringifyObject([1, 2])).toEqual('[ 1, 2 ]');
expect($.stringifyObject({'Jan' : 1})).toEqual('<div style="margin-left:0px">Jan: 1</div>');
});
it('should return JSON data for a given URL via ajax call', function() {
var data = { 'a': 'b' },
error; // undefined
spyOn(jQuery, 'ajax').and.callFake(function(params) {
if (/success$/.test(params.url)) {
params.success(data);
} else {
params.error(error);
}
});
expect($.getJsonFromUrl('http://manifest/url/success', true)).toEqual(data);
expect($.getJsonFromUrl('http://manifest/url/success', false)).toEqual(data);
expect($.getJsonFromUrl('http://manifest/url/failed', false)).toEqual(error);
});
it('should return label for a given view name', function() {
expect($.getViewLabel('xyzView')).toEqual('Xyz View');
expect($.getViewLabel('unavailableView')).toEqual('unavailableView');
});
it('should extract label from a property attribute/key and titlecase it', function() {
expect($.extractLabelFromAttribute('@id')).toEqual('Id');
expect($.extractLabelFromAttribute('seeAlso')).toEqual('See Also');
});
it('should convert an array to string with delimiter (if array), or return string (if string)', function() {
expect($.toString('str')).toEqual('str');
expect($.toString(['a', 'b'])).toEqual('a b');
expect($.toString(['a', 'b'], ' / ')).toEqual('a / b');
});
});
// Tests for manifest data related methods
describe('Manifest data related methods', function() {
var imagesList = [{
'id': 1,
'title': '1r',
'height': 10,
'width': 20
}, {
'id': 2,
'title': '1v',
'height': 15,
'width': 25
}],
imageTitlesAndIds = [{
'id': 1,
'title': '1r'
}, {
'id': 2,
'title': '1v'
}];
beforeEach(function() {
$.manifests = {
"manifest-1234": {
"uri":"http://xyz.edu/data/Manifest.json",
"metadata": {
"details": {
'label': 'Collection 123'
}
},
"sequences": [{
"imagesList": imagesList
}]
}
};
});
it('should return matching manifest for a given URI', function() {
expect($.getManifestIdByUri('http://xyz.edu/data/Manifest.json')).toEqual('manifest-1234');
expect($.getManifestIdByUri('http://xyz.edu/data/abc.json')).toEqual([]);
});
it('should return manifest metadata for a given manifest id', function() {
expect($.getMetadataByManifestId('manifest-1234')).toEqual({ "details":{ 'label': 'Collection 123' } });
});
it('should return images list for given manifest id', function() {
expect($.getImagesListByManifestId('manifest-1234')).toEqual(imagesList);
});
it('should return a collection title for a given metadata', function() {
expect($.getCollectionTitle({ 'details': { 'label': 'abc' } })).toEqual('abc');
expect($.getCollectionTitle({ 'details': { } })).toEqual('');
});
it('should return array of image titles and ids for a given images list', function() {
expect($.getImageTitlesAndIds(imagesList)).toEqual(imageTitlesAndIds);
});
});
});