-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #233 from spenceralger/fix/discover_fetch
Fix discover fetch
- Loading branch information
Showing
7 changed files
with
149 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
define(function (require) { | ||
return function DiffTimePickerValuesFn() { | ||
var _ = require('lodash'); | ||
var angular = require('angular'); | ||
|
||
var valueOf = function (o) { | ||
if (o) return o.valueOf(); | ||
}; | ||
|
||
return function (rangeA, rangeB) { | ||
if (_.isObject(rangeA) && _.isObject(rangeB)) { | ||
if ( | ||
valueOf(rangeA.to) !== valueOf(rangeB.to) | ||
|| valueOf(rangeA.from) !== valueOf(rangeB.from) | ||
) { | ||
return true; | ||
} | ||
} else { | ||
return !angular.equals(rangeA, rangeB); | ||
} | ||
|
||
return false; | ||
}; | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
define(function (require) { | ||
var moment = require('moment'); | ||
|
||
require('angular').module('DiffTimePickerValues', ['kibana']); | ||
|
||
describe('Diff Time Picker Values', function () { | ||
var diffTimePickerValues; | ||
|
||
beforeEach(module('DiffTimePickerValues')); | ||
beforeEach(inject(function (Private) { | ||
diffTimePickerValues = Private(require('utils/diff_time_picker_vals')); | ||
})); | ||
|
||
it('accepts two undefined values', function () { | ||
var diff = diffTimePickerValues(undefined, undefined); | ||
expect(diff).to.be(false); | ||
}); | ||
|
||
describe('datemath ranges', function () { | ||
it('knows a match', function () { | ||
var diff = diffTimePickerValues( | ||
{ | ||
to: 'now', | ||
from: 'now-7d' | ||
}, | ||
{ | ||
to: 'now', | ||
from: 'now-7d' | ||
} | ||
); | ||
|
||
expect(diff).to.be(false); | ||
}); | ||
it('knows a difference', function () { | ||
var diff = diffTimePickerValues( | ||
{ | ||
to: 'now', | ||
from: 'now-7d' | ||
}, | ||
{ | ||
to: 'now', | ||
from: 'now-1h' | ||
} | ||
); | ||
|
||
expect(diff).to.be(true); | ||
}); | ||
}); | ||
|
||
describe('a datemath range, and a moment range', function () { | ||
it('is always different', function () { | ||
var diff = diffTimePickerValues( | ||
{ | ||
to: moment(), | ||
from: moment() | ||
}, | ||
{ | ||
to: 'now', | ||
from: 'now-1h' | ||
} | ||
); | ||
|
||
expect(diff).to.be(true); | ||
}); | ||
}); | ||
|
||
describe('moment ranges', function () { | ||
it('uses the time value of moments for comparison', function () { | ||
var to = moment(); | ||
var from = moment().add(1, 'day'); | ||
|
||
var diff = diffTimePickerValues( | ||
{ | ||
to: to.clone(), | ||
from: from.clone() | ||
}, | ||
{ | ||
to: to.clone(), | ||
from: from.clone() | ||
} | ||
); | ||
|
||
expect(diff).to.be(false); | ||
}); | ||
|
||
it('fails if any to or from is different', function () { | ||
var to = moment(); | ||
var from = moment().add(1, 'day'); | ||
var from2 = moment().add(2, 'day'); | ||
|
||
var diff = diffTimePickerValues( | ||
{ | ||
to: to.clone(), | ||
from: from.clone() | ||
}, | ||
{ | ||
to: to.clone(), | ||
from: from2.clone() | ||
} | ||
); | ||
|
||
expect(diff).to.be(true); | ||
}); | ||
}); | ||
|
||
it('does not fall apart with unusual values', function () { | ||
var diff = diffTimePickerValues({}, {}); | ||
expect(diff).to.be(false); | ||
}); | ||
}); | ||
}); |