Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 committed Dec 16, 2021
1 parent 1347895 commit f4cc494
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,57 +99,6 @@ export default function ({
expect(getCell(result, 0, 1)).to.be(4763);
});

it('shifts multiple metrics with previous and date histograms', async () => {
const expression = `
kibana_context timeRange={timerange from='${timeRange.from}' to='${timeRange.to}'}
| esaggs index={indexPatternLoad id='logstash-*'}
aggs={aggDateHistogram id="0" enabled=true schema="bucket" field="@timestamp" interval="4h" min_doc_count="1"}
aggs={aggCount id="1" enabled=true schema="metric"}
aggs={aggCount id="2" enabled=true schema="metric" timeShift="previous"}
`;
const result = await expectExpression(
'esaggs_shift_multi_metric_previous_date_histogram',
expression
).getResponse();
expect(result.rows).to.eql([
{
'col-0-0': 1442788200000,
'col-1-1': 30,
'col-2-2': 20,
},
{
'col-0-0': 1442802600000,
'col-1-1': 292,
'col-2-2': 309,
},
{
'col-0-0': 1442817000000,
'col-1-1': 1218,
'col-2-2': 1346,
},
{
'col-0-0': 1442831400000,
'col-1-1': 1970,
'col-2-2': 1940,
},
{
'col-0-0': 1442845800000,
'col-1-1': 952,
'col-2-2': 973,
},
{
'col-0-0': 1442860200000,
'col-1-1': 148,
'col-2-2': 164,
},
{
'col-0-0': 1442874600000,
'col-1-1': 8,
'col-2-2': 11,
},
]);
});

it('shifts single percentile', async () => {
const expression = `
kibana_context timeRange={timerange from='${timeRange.from}' to='${timeRange.to}'}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { getDisallowedPreviousShiftMessage } from './time_shift_utils';
import { IndexPatternLayer } from './types';

describe('time_shift_utils', () => {
describe('getDisallowedPreviousShiftMessage', () => {
const layer: IndexPatternLayer = {
indexPatternId: '',
columnOrder: [],
columns: {
a: {
operationType: 'date_histogram',
dataType: 'date',
isBucketed: true,
label: '',
references: [],
sourceField: 'timestamp',
},
b: {
operationType: 'count',
dataType: 'number',
isBucketed: false,
label: 'non shifted',
references: [],
sourceField: 'records',
},
c: {
operationType: 'count',
dataType: 'number',
isBucketed: false,
label: 'shifted',
timeShift: '1d',
references: [],
sourceField: 'records',
},
},
};

it('shoud not produce an error for no shift', () => {
expect(getDisallowedPreviousShiftMessage(layer, 'b')).toBeUndefined();
});

it('shoud not produce an error for non-previous shift', () => {
expect(getDisallowedPreviousShiftMessage(layer, 'c')).toBeUndefined();
});

it('shoud produce an error for previous shift with date histogram', () => {
expect(
getDisallowedPreviousShiftMessage(
{
...layer,
columns: { ...layer.columns, c: { ...layer.columns.c, timeShift: 'previous' } },
},
'c'
)
).toHaveLength(1);
});

it('shoud not produce an error for previous shift without date histogram', () => {
expect(
getDisallowedPreviousShiftMessage(
{
...layer,
columns: {
...layer.columns,
a: { ...layer.columns.a, operationType: 'terms' },
c: { ...layer.columns.c, timeShift: 'previous' },
},
},
'c'
)
).toBeUndefined();
});
});
});

0 comments on commit f4cc494

Please sign in to comment.