mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
This commit is contained in:
parent
2aa8f62401
commit
466c4669f4
2 changed files with 42 additions and 4 deletions
|
@ -22,11 +22,47 @@ describe('filterDeps', () => {
|
|||
expect(fd({ level: 'warning' } as DeprecationInfo)).toBe(false);
|
||||
});
|
||||
|
||||
test('filters on search', () => {
|
||||
test('filters on title search', () => {
|
||||
const fd = filterDeps(LevelFilterOption.critical, 'wow');
|
||||
expect(fd({ level: 'critical', message: 'the wow error' } as DeprecationInfo)).toBe(true);
|
||||
expect(fd({ level: 'critical', message: 'other error' } as DeprecationInfo)).toBe(false);
|
||||
});
|
||||
|
||||
test('filters on index search', () => {
|
||||
const fd = filterDeps(LevelFilterOption.critical, 'myIndex');
|
||||
expect(
|
||||
fd({
|
||||
level: 'critical',
|
||||
message: 'the wow error',
|
||||
index: 'myIndex-2',
|
||||
} as EnrichedDeprecationInfo)
|
||||
).toBe(true);
|
||||
expect(
|
||||
fd({
|
||||
level: 'critical',
|
||||
message: 'other error',
|
||||
index: 'notIndex',
|
||||
} as EnrichedDeprecationInfo)
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
test('filters on node search', () => {
|
||||
const fd = filterDeps(LevelFilterOption.critical, 'myNode');
|
||||
expect(
|
||||
fd({
|
||||
level: 'critical',
|
||||
message: 'the wow error',
|
||||
index: 'myNode-123',
|
||||
} as EnrichedDeprecationInfo)
|
||||
).toBe(true);
|
||||
expect(
|
||||
fd({
|
||||
level: 'critical',
|
||||
message: 'other error',
|
||||
index: 'notNode',
|
||||
} as EnrichedDeprecationInfo)
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('GroupedDeprecations', () => {
|
||||
|
|
|
@ -28,7 +28,7 @@ import { DeprecationList } from './list';
|
|||
|
||||
// exported only for testing
|
||||
export const filterDeps = (level: LevelFilterOption, search: string = '') => {
|
||||
const conditions: Array<(dep: DeprecationInfo) => boolean> = [];
|
||||
const conditions: Array<(dep: EnrichedDeprecationInfo) => boolean> = [];
|
||||
|
||||
if (level !== LevelFilterOption.all) {
|
||||
conditions.push((dep: DeprecationInfo) => dep.level === level);
|
||||
|
@ -41,7 +41,9 @@ export const filterDeps = (level: LevelFilterOption, search: string = '') => {
|
|||
const searchReg = new RegExp(search.toLowerCase());
|
||||
return Boolean(
|
||||
dep.message.toLowerCase().match(searchReg) ||
|
||||
(dep.details && dep.details.match(searchReg))
|
||||
(dep.details && dep.details.toLowerCase().match(searchReg)) ||
|
||||
(dep.index && dep.index.toLowerCase().match(searchReg)) ||
|
||||
(dep.node && dep.node.toLowerCase().match(searchReg))
|
||||
);
|
||||
} catch (e) {
|
||||
// ignore any regexp errors.
|
||||
|
@ -51,7 +53,7 @@ export const filterDeps = (level: LevelFilterOption, search: string = '') => {
|
|||
}
|
||||
|
||||
// Return true if every condition function returns true (boolean AND)
|
||||
return (dep: DeprecationInfo) => conditions.map(c => c(dep)).every(t => t);
|
||||
return (dep: EnrichedDeprecationInfo) => conditions.map(c => c(dep)).every(t => t);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue