Sort.spec.js
1.7 KB
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
define(function(require) {
'use strict';
var _ = require('underscore');
var Backbone = require('backbone');
var Sort = require('solr/model/Sort');
describe('Sort', function() {
it('loads', function() {
expect(Sort).toBeDefined();
});
it('standard(number)', function() {
var array = [5, 4, 2, 2, 3, 1, 5];
array.sort(Sort.standard);
expect(array).toEqual([1, 2, 2, 3, 4, 5, 5]);
});
it('standard(string)', function() {
var array = ['1', '500', '2', '400', '3', '300', '4', '200', '5', '100'];
array.sort(Sort.standard);
expect(array).toEqual(['1', '100', '2', '200', '3', '300', '4', '400', '5', '500']);
});
it('date', function() {
var array = [
'2016-02-05T13:25:06-0600',
'2015-02-05T13:25:06-0600',
'2014-02-05T13:25:06-0600',
'2013-02-05T13:25:06-0600',
'2012-02-05T13:25:06-0600',
'2011-02-05T13:25:06-0600',
];
array.sort(Sort.date);
expect(array).toEqual([
'2011-02-05T13:25:06-0600',
'2012-02-05T13:25:06-0600',
'2013-02-05T13:25:06-0600',
'2014-02-05T13:25:06-0600',
'2015-02-05T13:25:06-0600',
'2016-02-05T13:25:06-0600',
]);
});
it('number', function() {
var array = ['1', '500', '2', '400', '3', '300', '4', '200', '5', '100'];
array.sort(Sort.number);
expect(array).toEqual(['1', '2', '3', '4', '5', '100', '200', '300', '400', '500']);
});
});
});