Ordering.spec.js 1.54 KB
define(function(require) {
    'use strict';
    var Backbone = require('backbone');
    var Ordering = require('solr/model/Ordering');

    describe('Ordering', function() {
        it('loads', function() {
            expect(Ordering).toBeDefined();
        });
        describe(':items', function() {
            var items = [
                {value: 'a', label: 'A'},
                {value: 'b', label: 'B'},
                {value: 'c', label: 'C'},
            ];
            it('default value is not shared globally', function() {
                var o1 = new Ordering(), o2 = new Ordering();
                expect(o1.get('items')).not.toBe(o2.get('items'));
            });
            it('array is converted to collection without specifying parse', function() {
                var o = new Ordering({items: items});
                expect(o.get('items')).not.toBe(items);
            });
            it('same passed value is not shared globally', function() {
                var o1 = new Ordering({items: items}, {parse: false});
                var o2 = new Ordering({items: items}, {parse: false});
                expect(o1.get('items')).not.toBe(o2.get('items'));
            });
            it(':value is first item', function() {
                var o = new Ordering({items: items});
                expect(o.get('value')).toBe('a');
            });
            it(':value is not changed', function() {
                var o = new Ordering({items: items, value: '1'});
                expect(o.get('value')).toBe('1');
            });
        });
    });
});