Add tests for moment, startFrom and uriescape filters

This commit is contained in:
Rashid Khan 2014-06-17 14:20:08 -07:00
parent dc1aafa746
commit 90401e8ea3
5 changed files with 148 additions and 1 deletions

View file

@ -5,7 +5,7 @@ define(function (require) {
require('modules')
.get('kibana/filters')
.filter('moment', function (config) {
return function (datetime, roundUp) {
return function (datetime) {
var format = config.get('dateFormat');
if (moment.isMoment(datetime)) return datetime.format(format);
if (_.isDate(datetime)) return moment(datetime).format(format);

View file

@ -54,6 +54,9 @@
'specs/directives/truncate',
'specs/directives/css_truncate',
'specs/filters/field_type',
'specs/filters/uriescape',
'specs/filters/moment',
'specs/filters/start_from',
'specs/utils/datemath',
'specs/utils/interval',
], function (sinon) {

View file

@ -0,0 +1,57 @@
define(function (require) {
var angular = require('angular');
var mocks = require('angular-mocks');
var sinon = require('sinon/sinon');
var moment = require('moment');
// Load the kibana app dependencies.
require('angular-route');
// Load kibana and its applications
require('index');
require('filters/moment');
var filter, config;
var clock, anchor = '2014-01-01T06:06:06.666';
var init = function (expandable) {
// Load the application
module('kibana');
clock = sinon.useFakeTimers(moment(anchor).valueOf());
// Create the scope
inject(function ($filter, _config_) {
filter = $filter('moment');
config = _config_;
});
};
describe('moment formatting filter', function () {
beforeEach(function () {
init();
});
it('should have a moment filter', function () {
expect(filter).to.not.be(null);
});
// MMMM Do YYYY, HH:mm:ss.SSS
it('should format moments', function () {
expect(filter(moment())).to.be('January 1st 2014, 06:06:06.666');
});
it('should format dates', function () {
expect(filter(new Date())).to.be('January 1st 2014, 06:06:06.666');
});
it('should return the original value if passed anything other than a moment or Date', function () {
expect(filter('beer')).to.be('beer');
expect(filter(1)).to.be(1);
expect(filter([])).to.eql([]);
});
});
});

View file

@ -0,0 +1,45 @@
define(function (require) {
var angular = require('angular');
var mocks = require('angular-mocks');
// Load the kibana app dependencies.
require('angular-route');
// Load kibana and its applications
require('index');
require('filters/start_from');
var filter;
var init = function (expandable) {
// Load the application
module('kibana');
// Create the scope
inject(function ($filter) {
filter = $filter('startFrom');
});
};
describe('startFrom array filter', function () {
beforeEach(function () {
init();
});
it('should have a startFrom filter', function () {
expect(filter).to.not.be(null);
});
it('should return an empty array if passed undefined', function () {
expect(filter(undefined, 10)).to.eql([]);
});
it('should return an array with the first 3 elements removed', function () {
expect(filter([1, 2, 3, 4, 5, 6, 7, 8, 9], 3).length).to.be(6);
});
});
});

View file

@ -0,0 +1,42 @@
define(function (require) {
var angular = require('angular');
var mocks = require('angular-mocks');
var _ = require('lodash');
// Load the kibana app dependencies.
require('angular-route');
// Load kibana and its applications
require('index');
require('apps/discover/index');
var filter;
var init = function (expandable) {
// Load the application
module('kibana');
// Create the scope
inject(function ($filter) {
filter = $filter('uriescape');
});
};
describe('uriescape filter', function () {
beforeEach(function () {
init();
});
it('should have a uriescape filter', function () {
expect(filter).to.not.be(null);
});
it('should encodeURIComponent a string', function () {
expect(filter('this and that')).to.be('this%20and%20that');
});
});
});