Sort.js 1.7 KB
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']);
        });
    });
});