forked from michael-benin-CN/gifshot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.js
323 lines (270 loc) · 11 KB
/
tests.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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
var chai = require('chai');
var gifshot = require('../src/gifshot.js');
var expect = chai.expect;
var gifshotUtils = gifshot.utils.default;
var gifshotDefaultOptions = gifshot.defaultOptions.default;
describe('gifshot', function () {
describe('#utils', function () {
it('should check gifshotUtils is an object', function () {
expect(gifshotUtils).not.to.equal(undefined);
});
it('should check URL is undefined', function () {
expect(gifshotUtils.URL).to.equal(undefined);
});
it('should check getUserMedia is undefined', function () {
expect(gifshotUtils.getUserMedia).to.equal(undefined);
});
it('should check Blob is undefined', function () {
expect(gifshotUtils.Blob).to.equal(undefined);
});
it('should check btoa is a function', function () {
expect(gifshotUtils.isFunction(gifshotUtils.btoa)).to.equal(true);
});
it('should correctly detect objects', function () {
var obj = {
'test': true
};
var func = function () {};
var arr = [];
var str = new String('test');
var str1 = 'test';
var num = new Number(1);
var num1 = 1;
expect(gifshotUtils.isObject(obj)).to.equal(true);
expect(gifshotUtils.isObject(func)).to.equal(false);
expect(gifshotUtils.isObject(arr)).to.equal(false);
expect(gifshotUtils.isObject(str)).to.equal(false);
expect(gifshotUtils.isObject(str1)).to.equal(false);
expect(gifshotUtils.isObject(num)).to.equal(false);
expect(gifshotUtils.isObject(num1)).to.equal(false);
});
it('should correctly detect empty objects', function () {
var obj = {
'test': true
};
var obj1 = {};
var func = function () {};
var arr = [];
var str = new String('test');
var str1 = 'test';
var num = new Number(1);
var num1 = 1;
expect(gifshotUtils.isEmptyObject(obj1)).to.equal(true);
expect(gifshotUtils.isEmptyObject(obj)).to.equal(false);
expect(gifshotUtils.isEmptyObject(func)).to.equal(false);
expect(gifshotUtils.isEmptyObject(arr)).to.equal(false);
expect(gifshotUtils.isEmptyObject(str)).to.equal(false);
expect(gifshotUtils.isEmptyObject(str1)).to.equal(false);
expect(gifshotUtils.isEmptyObject(num)).to.equal(false);
expect(gifshotUtils.isEmptyObject(num1)).to.equal(false);
});
it('should correctly detect arrays', function () {
var obj = {
'test': true
};
var func = function () {};
var arr = [];
var str = new String('test');
var str1 = 'test';
var num = new Number(1);
var num1 = 1;
expect(gifshotUtils.isArray(arr)).to.equal(true);
expect(gifshotUtils.isArray(obj)).to.equal(false);
expect(gifshotUtils.isArray(func)).to.equal(false);
expect(gifshotUtils.isArray(str)).to.equal(false);
expect(gifshotUtils.isArray(str1)).to.equal(false);
expect(gifshotUtils.isArray(num)).to.equal(false);
expect(gifshotUtils.isArray(num1)).to.equal(false);
});
it('should correctly detect functions', function () {
var obj = {
'test': true
};
var func = function () {};
var arr = [];
var str = new String('test');
var str1 = 'test';
var num = new Number(1);
var num1 = 1;
expect(gifshotUtils.isFunction(func)).to.equal(true);
expect(gifshotUtils.isFunction(arr)).to.equal(false);
expect(gifshotUtils.isFunction(obj)).to.equal(false);
expect(gifshotUtils.isFunction(str)).to.equal(false);
expect(gifshotUtils.isFunction(str1)).to.equal(false);
expect(gifshotUtils.isFunction(num)).to.equal(false);
expect(gifshotUtils.isFunction(num1)).to.equal(false);
});
it('should correctly detect strings', function () {
expect(gifshotUtils.isElement({})).to.equal(false);
});
it('should correctly detect strings', function () {
var obj = {
'test': true
};
var func = function () {};
var arr = [];
var str = new String('test');
var str1 = 'test';
var num = new Number(1);
var num1 = 1;
expect(gifshotUtils.isString(str)).to.equal(true);
expect(gifshotUtils.isString(str1)).to.equal(true);
expect(gifshotUtils.isString(func)).to.equal(false);
expect(gifshotUtils.isString(arr)).to.equal(false);
expect(gifshotUtils.isString(obj)).to.equal(false);
expect(gifshotUtils.isString(num)).to.equal(false);
expect(gifshotUtils.isString(num1)).to.equal(false);
});
it('should have a check for canvas support', function () {
expect(gifshotUtils.isSupported.canvas).not.to.equal(undefined);
});
it('should have a check for web workers support', function () {
expect(gifshotUtils.isSupported.webworkers).not.to.equal(undefined);
});
it('should have a check for Blob support', function () {
expect(gifshotUtils.isSupported.blob).not.to.equal(undefined);
});
it('should have a check for 8-int Typed Arrays support', function () {
expect(gifshotUtils.isSupported.Uint8Array).not.to.equal(undefined);
expect(gifshotUtils.isSupported.Uint8Array()).to.equal(undefined);
});
it('should have a check for 32-int Typed Arrays support', function () {
expect(gifshotUtils.isSupported.Uint32Array).not.to.equal(undefined);
expect(gifshotUtils.isSupported.Uint32Array()).to.equal(undefined);
});
it('should have a check for videoCodecs support', function () {
expect(gifshotUtils.isSupported.videoCodecs).not.to.equal(undefined);
});
it('should return an empty function for noop', function () {
expect(gifshotUtils.isFunction(gifshotUtils.noop)).to.equal(true);
});
it('should correctly iterate arrays and objects with the each method', function () {
var arr = ['test', 'testing'];
var arrCount = 0;
var obj = {
'test': 'hmm',
'testing': 'check'
};
var objCount = 0;
gifshotUtils.each(arr, function () {
arrCount += 1;
});
gifshotUtils.each(obj, function () {
objCount += 1;
});
expect(arrCount).to.equal(2);
expect(objCount).to.equal(2);
});
it('should correctly merge objects together', function () {
var defaultOptions = {
'test': 'testing',
'nestedTest': {
'test': 'blah'
}
};
var userOptions = {
'nestedTest': {
'test': 'this is a test'
}
};
var mergedOptions = gifshotUtils.mergeOptions(defaultOptions, userOptions);
expect(mergedOptions.test).to.equal('testing');
expect(mergedOptions.nestedTest.test).to.equal('this is a test');
});
it('should test the progress callback', function () {
expect(gifshotDefaultOptions.progressCallback()).to.equal(undefined);
expect(gifshotDefaultOptions.completeCallback()).to.equal(undefined);
});
it('should set css attributes', function () {
expect(gifshotUtils.setCSSAttr()).to.equal(undefined);
});
it('should remove an element', function () {
expect(gifshotUtils.removeElement()).to.equal(undefined);
});
it('should create a web worker', function () {
expect(gifshotUtils.isEmptyObject(gifshotUtils.createWebWorker())).to.equal(true);
});
it('should get file extension', function () {
expect(gifshotUtils.getExtension('test.gif')).to.equal('gif');
});
it('should resize text', function () {
expect(gifshotUtils.getFontSize('test', 200, 18, 20)).to.equal(undefined);
});
});
describe('#apiMethods', function () {
describe('#createGIF', function () {
it('should have a createGIF method', function () {
expect(gifshot.createGIF).not.to.equal(undefined);
});
it('should correctly return the provided callback function', function () {
gifshot.createGIF({}, function (obj) {
expect(gifshotUtils.isObject(obj)).to.equal(true);
expect(obj.error).to.equal(true);
});
});
});
describe('#takeSnapShot', function () {
it('should have a takeSnapShot method', function () {
expect(gifshot.takeSnapShot).not.to.equal(undefined);
});
it ('should correctly return the provided callback function', function () {
gifshot.takeSnapShot({}, function (obj) {
expect(gifshotUtils.isObject(obj)).to.equal(true);
expect(obj.error).to.equal(true);
});
});
});
describe('#stopVideoStreaming', function () {
it ('should have a stopVideoStreaming method', function () {
expect(gifshot.stopVideoStreaming).not.to.equal(undefined);
});
});
describe('#isSupported', function () {
it ('should have an isSupported method', function () {
expect(gifshot.isSupported).not.to.equal(undefined);
});
it ('should call isSupported', function () {
expect(gifshot.isSupported()).not.to.equal(undefined);
});
});
describe('#isWebCamGIFSupported', function () {
it ('should have an isWebCamGIFSupported method', function () {
expect(gifshot.isWebCamGIFSupported).not.to.equal(undefined);
});
it ('should call isWebCamGIFSupported', function () {
expect(gifshot.isWebCamGIFSupported()).not.to.equal(undefined);
});
});
describe('#isExistingVideoGIFSupported', function () {
it('should have an isExistingVideoGIFSupported method', function () {
expect(gifshot.isExistingVideoGIFSupported).not.to.equal(undefined);
});
it('should call isExistingVideoGIFSupported', function () {
expect(gifshot.isExistingVideoGIFSupported()).not.to.equal(undefined);
});
});
describe('#isExistingImagesGIFSupported', function () {
it('should have an isExistingImagesGIFSupported method', function () {
expect(gifshot.isExistingImagesGIFSupported).not.to.equal(undefined);
});
it('should call isExistingImagesGIFSupported', function () {
expect(gifshot.isExistingImagesGIFSupported()).not.to.equal(undefined);
});
});
});
describe('#error', function () {
var error = gifshot.error.default;
it('should check the error object', function () {
expect(gifshotUtils.isObject(error.validate())).to.equal(true);
});
it('should check is valid', function () {
expect(error.isValid()).to.equal(false);
});
it('should check is valid', function () {
expect(error.isValid({
'getUserMedia': true,
'canvas': true
})).to.equal(false);
});
});
});