-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
3 changed files
with
140 additions
and
89 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
.../infra/public/containers/metrics_explorer/with_metrics_explorer_options_url_state.test.ts
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,70 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { omit } from 'lodash'; | ||
import { mapToUrlState } from './with_metrics_explorer_options_url_state'; | ||
|
||
describe('WithMetricsExplorerOptionsUrlState', () => { | ||
describe('mapToUrlState', () => { | ||
it('loads a valid URL state', () => { | ||
expect(mapToUrlState(validState)).toEqual(validState); | ||
}); | ||
it('discards invalid properties and loads valid properties into the URL', () => { | ||
expect(mapToUrlState(invalidState)).toEqual(omit(invalidState, 'options')); | ||
}); | ||
}); | ||
}); | ||
|
||
const validState = { | ||
chartOptions: { | ||
stack: false, | ||
type: 'line', | ||
yAxisMode: 'fromZero', | ||
}, | ||
options: { | ||
aggregation: 'avg', | ||
filterQuery: '', | ||
groupBy: ['host.hostname'], | ||
metrics: [ | ||
{ | ||
aggregation: 'avg', | ||
color: 'color0', | ||
field: 'system.cpu.user.pct', | ||
}, | ||
{ | ||
aggregation: 'avg', | ||
color: 'color1', | ||
field: 'system.load.1', | ||
}, | ||
], | ||
source: 'url', | ||
}, | ||
timerange: { | ||
from: 'now-1h', | ||
interval: '>=10s', | ||
to: 'now', | ||
}, | ||
}; | ||
|
||
const invalidState = { | ||
chartOptions: { | ||
stack: false, | ||
type: 'line', | ||
yAxisMode: 'fromZero', | ||
}, | ||
options: { | ||
aggregation: 'avg', | ||
filterQuery: '', | ||
groupBy: ['host.hostname'], | ||
metrics: 'this is the wrong data type', | ||
source: 'url', | ||
}, | ||
timerange: { | ||
from: 'now-1h', | ||
interval: '>=10s', | ||
to: 'now', | ||
}, | ||
}; |
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