Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[indexPattern] Added #toDetailedIndexList() #5638

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 24 additions & 43 deletions src/ui/public/index_patterns/__tests__/_index_pattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,19 @@ describe('index pattern', function () {

// stub calculateIndices
calculateIndices = sinon.spy(function () {
return $injector.get('Promise').resolve(['foo', 'bar']);
return $injector.get('Promise').resolve([
{ index: 'foo', max: Infinity, min: -Infinity },
{ index: 'bar', max: Infinity, min: -Infinity }
]);
});
Private.stub(require('ui/index_patterns/_calculate_indices'), calculateIndices);

// spy on intervals
intervals = Private(require('ui/index_patterns/_intervals'));
sinon.stub(intervals, 'toIndexList').returns(['foo', 'bar']);
sinon.stub(intervals, 'toIndexList').returns([
{ index: 'foo', max: Infinity, min: -Infinity },
{ index: 'bar', max: Infinity, min: -Infinity }
]);

IndexPattern = Private(require('ui/index_patterns/_index_pattern'));
}));
Expand Down Expand Up @@ -290,78 +296,53 @@ describe('index pattern', function () {

describe('#toIndexList', function () {
context('when index pattern is an interval', function () {
require('testUtils/noDigestPromises').activateForSuite();

var interval;
beforeEach(function () {
interval = 'result:getInterval';
sinon.stub(indexPattern, 'getInterval').returns(interval);
});

it('invokes interval toIndexList with given start/stop times', function () {
indexPattern.toIndexList(1, 2);
$rootScope.$apply();

it('invokes interval toIndexList with given start/stop times', async function () {
await indexPattern.toIndexList(1, 2);
var id = indexPattern.id;
expect(intervals.toIndexList.calledWith(id, interval, 1, 2)).to.be(true);
});
it('is fulfilled by the result of interval toIndexList', function () {
var indexList;
indexPattern.toIndexList().then(function (val) {
indexList = val;
});
$rootScope.$apply();

it('is fulfilled by the result of interval toIndexList', async function () {
var indexList = await indexPattern.toIndexList();
expect(indexList[0]).to.equal('foo');
expect(indexList[1]).to.equal('bar');
});

context('with sort order', function () {
require('testUtils/noDigestPromises').activateForSuite();

context('undefined', function () {
it('provides the index list in tact', async function () {
const indexList = await indexPattern.toIndexList();
expect(indexList).to.eql(['foo', 'bar']);
});
});

context('asc', function () {
it('provides the index list in tact', async function () {
const indexList = await indexPattern.toIndexList(1, 2, 'asc');
expect(indexList).to.eql(['foo', 'bar']);
});
});

context('desc', function () {
it('reverses the index list', async function () {
const indexList = await indexPattern.toIndexList(1, 2, 'desc');
expect(indexList).to.eql(['bar', 'foo']);
it('passes the sort order to the intervals module', function () {
return indexPattern.toIndexList(1, 2, 'SORT_DIRECTION')
.then(function () {
expect(intervals.toIndexList.callCount).to.be(1);
expect(intervals.toIndexList.getCall(0).args[4]).to.be('SORT_DIRECTION');
});
});
});
});

context('when index pattern is a time-base wildcard', function () {
require('testUtils/noDigestPromises').activateForSuite();
beforeEach(function () {
sinon.stub(indexPattern, 'getInterval').returns(false);
sinon.stub(indexPattern, 'hasTimeField').returns(true);
sinon.stub(indexPattern, 'isWildcard').returns(true);
});

it('invokes calculateIndices with given start/stop times and sortOrder', function () {
indexPattern.toIndexList(1, 2, 'sortOrder');
$rootScope.$apply();

it('invokes calculateIndices with given start/stop times and sortOrder', async function () {
await indexPattern.toIndexList(1, 2, 'sortOrder');
var id = indexPattern.id;
var field = indexPattern.timeFieldName;
expect(calculateIndices.calledWith(id, field, 1, 2, 'sortOrder')).to.be(true);
});
it('is fulfilled by the result of calculateIndices', function () {
var indexList;
indexPattern.toIndexList().then(function (val) {
indexList = val;
});
$rootScope.$apply();

it('is fulfilled by the result of calculateIndices', async function () {
var indexList = await indexPattern.toIndexList();
expect(indexList[0]).to.equal('foo');
expect(indexList[1]).to.equal('bar');
});
Expand Down
59 changes: 46 additions & 13 deletions src/ui/public/index_patterns/__tests__/calculate_indices.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
describe('ui/index_patterns/_calculate_indices', () => {
const _ = require('lodash');
const pluck = require('lodash').pluck;
const sinon = require('auto-release-sinon');
const expect = require('expect.js');
const ngMock = require('ngMock');
Expand Down Expand Up @@ -40,7 +41,7 @@ describe('ui/index_patterns/_calculate_indices', () => {

function run({ start = undefined, stop = undefined } = {}) {
calculateIndices('wat-*-no', '@something', start, stop).then(value => {
indices = value;
indices = pluck(value, 'index');
});
$rootScope.$apply();
config = _.first(es.fieldStats.lastCall.args);
Expand Down Expand Up @@ -130,29 +131,45 @@ describe('ui/index_patterns/_calculate_indices', () => {
};

return calculateIndices('*', 'time', null, null).then(function (resp) {
expect(resp).to.eql(['c', 'a', 'b']);
expect(pluck(resp, 'index')).to.eql(['c', 'a', 'b']);
});
});
});

context('when sorting desc', function () {
it('returns the indices in max_value order', function () {
context('when sorting asc', function () {
it('resolves to an array of objects, each with index, start, and end properties', function () {
response = {
indices: {
c: { fields: { time: { max_value: 10 } } },
a: { fields: { time: { max_value: 15 } } },
b: { fields: { time: { max_value: 1 } } },
c: { fields: { time: { max_value: 10, min_value: 9 } } },
a: { fields: { time: { max_value: 15, min_value: 5 } } },
b: { fields: { time: { max_value: 1, min_value: 0 } } },
}
};

return calculateIndices('*', 'time', null, null, 'desc').then(function (resp) {
expect(resp).to.eql(['a', 'c', 'b']);
return calculateIndices('*', 'time', null, null, 'asc').then(function (resp) {
expect(resp).to.eql([
{
index: 'b',
min: 0,
max: 1
},
{
index: 'a',
min: 5,
max: 15
},
{
index: 'c',
min: 9,
max: 10
}
]);
});
});
});

context('when sorting asc', function () {
it('returns the indices in min_value order', function () {
context('when sorting desc', function () {
it('resolves to an array of objects, each with index, min, and max properties', function () {
response = {
indices: {
c: { fields: { time: { max_value: 10, min_value: 9 } } },
Expand All @@ -161,8 +178,24 @@ describe('ui/index_patterns/_calculate_indices', () => {
}
};

return calculateIndices('*', 'time', null, null, 'asc').then(function (resp) {
expect(resp).to.eql(['b', 'a', 'c']);
return calculateIndices('*', 'time', null, null, 'desc').then(function (resp) {
expect(resp).to.eql([
{
index: 'a',
max: 15,
min: 5
},
{
index: 'c',
max: 10,
min: 9
},
{
index: 'b',
max: 1,
min: 0
},
]);
});
});
});
Expand Down
Loading