UNPKG

linagora-rse

Version:
94 lines (70 loc) 3.05 kB
'use strict'; /* global chai: false */ var expect = chai.expect; describe('The Search Form Angular module', function() { beforeEach(function() { angular.mock.module('esn.search'); }); describe('searchForm directive', function() { beforeEach(module('jadeTemplates')); beforeEach(inject(['$compile', '$rootScope', function($c, $r) { this.$compile = $c; this.$rootScope = $r; }])); beforeEach(function() { this.checkGeneratedElement = function(element, spinnerKey, spinnerConf) { var checkGeneratedAttributeValue = function(element, attrName, attrValue) { expect(element.find('span')[0].attributes.getNamedItem(attrName).value).to.equal(attrValue); }; checkGeneratedAttributeValue(element, 'spinner-key', spinnerKey); checkGeneratedAttributeValue(element, 'us-spinner', JSON.stringify(spinnerConf)); }; }); it('should fill the search-form template with default throbber values if no values were defined in the scope', inject(function(defaultSpinnerConfiguration) { var html = '<search-form></search-form>'; var element = this.$compile(html)(this.$rootScope); this.$rootScope.$digest(); this.checkGeneratedElement(element, defaultSpinnerConfiguration.spinnerKey, defaultSpinnerConfiguration.spinnerConf); })); it('should fill the search-form template with throbber values from the scope', function() { var html = '<search-form></search-form>'; this.$rootScope.spinnerKey = 'spinnerKey'; this.$rootScope.spinnerConf = {radius: 30, width: 8, length: 16}; var element = this.$compile(html)(this.$rootScope); this.$rootScope.$digest(); this.checkGeneratedElement(element, 'spinnerKey', {radius: 30, width: 8, length: 16}); }); }); describe('The esnSearchResultSizeFormatter service', function() { var service; beforeEach(function() { inject(function($injector) { service = $injector.get('esnSearchResultSizeFormatter'); }); }); it('should return 0 when input is undefined', function() { expect(service().hits).to.equal(0); expect(service().isFormatted).to.be.false; }); it('should return 0 when input is 0', function() { expect(service(0).hits).to.equal(0); expect(service(0).isFormatted).to.be.false; }); it('should return the input when lower than limit', function() { expect(service(555).hits).to.equal(555); expect(service(555).isFormatted).to.be.false; }); it('should return limit when input is around limit', function() { expect(service(1001).hits).to.equal(1000); expect(service(1001).isFormatted).to.be.true; }); it('should round to lower ten', function() { expect(service(2542).hits).to.equal(2540); expect(service(2542).isFormatted).to.be.true; }); it('should round to higher ten', function() { expect(service(2546).hits).to.equal(2550); expect(service(2546).isFormatted).to.be.true; }); }); });