-
Notifications
You must be signed in to change notification settings - Fork 8k
/
persistable_state.test.ts
37 lines (33 loc) · 1.42 KB
/
persistable_state.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { extract, inject } from './persistable_state';
import { Filter } from '../es_query/filters';
describe('filter manager persistable state tests', () => {
const filters: Filter[] = [
{ meta: { alias: 'test', disabled: false, negate: false, index: 'test' } },
];
describe('reference injection', () => {
test('correctly inserts reference to filter', () => {
const updatedFilters = inject(filters, [{ type: 'index_pattern', name: 'test', id: '123' }]);
expect(updatedFilters[0]).toHaveProperty('meta.index', '123');
});
test('drops index setting if reference is missing', () => {
const updatedFilters = inject(filters, [
{ type: 'index_pattern', name: 'test123', id: '123' },
]);
expect(updatedFilters[0]).toHaveProperty('meta.index', undefined);
});
});
describe('reference extraction', () => {
test('correctly extracts references', () => {
const { state, references } = extract(filters);
expect(state[0]).toHaveProperty('meta.index');
expect(references[0]).toHaveProperty('id', 'test');
});
});
});