The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/features/dashboard/components/PanelEditor/state/OptionSearchEngine.test.ts

141 lines
4.1 KiB

import { OptionsPaneCategoryDescriptor } from '../OptionsPaneCategoryDescriptor';
import { OptionsPaneItemDescriptor } from '../OptionsPaneItemDescriptor';
import { OptionSearchEngine } from './OptionSearchEngine';
describe('OptionSearchEngine', () => {
it('Can search options based on title', () => {
const engine = new OptionSearchEngine(getOptionCategories(), []);
const results = engine.search('Min');
expect(results.optionHits.length).toBe(2);
expect(results.optionHits[0].props.title).toBe('Min');
});
it('When matching both title and description title should rank higher', () => {
const engine = new OptionSearchEngine(getOptionCategories(), []);
const results = engine.search('DescriptionMatch');
expect(results.optionHits.length).toBe(2);
expect(results.optionHits[0].props.title).toBe('DescriptionMatch');
});
it('When matching both category and title category title should rank higher', () => {
const engine = new OptionSearchEngine(getOptionCategories(), []);
const results = engine.search('frame');
expect(results.optionHits.length).toBe(4);
expect(results.optionHits[0].props.title).toBe('Frame');
});
it('Override hits should contain matcher and matched properties', () => {
const engine = new OptionSearchEngine(getOptionCategories(), getOverrides());
const results = engine.search('Max');
expect(results.overrideHits.length).toBe(2);
expect(results.overrideHits[0].items.length).toBe(2);
expect(results.overrideHits[0].items[0].props.title).toBe('Match by name');
expect(results.overrideHits[0].items[1].props.title).toBe('Max');
});
it('Override hits should not add matcher twice', () => {
const engine = new OptionSearchEngine(getOptionCategories(), getOverrides());
const results = engine.search('Match by name');
expect(results.overrideHits.length).toBe(2);
expect(results.overrideHits[0].items.length).toBe(1);
});
});
function getOptionCategories(): OptionsPaneCategoryDescriptor[] {
return [
new OptionsPaneCategoryDescriptor({
id: 'Panel frame',
title: 'Panel frame',
})
.addItem(
new OptionsPaneItemDescriptor({
title: 'Title',
Component: jest.fn(),
})
)
.addItem(
new OptionsPaneItemDescriptor({
title: 'Min',
Component: jest.fn(),
})
)
.addItem(
new OptionsPaneItemDescriptor({
title: 'ASDSADASDSADA',
description: 'DescriptionMatch',
Component: jest.fn(),
})
),
new OptionsPaneCategoryDescriptor({
id: 'Axis',
title: 'Axis',
})
.addItem(
new OptionsPaneItemDescriptor({
title: 'Min',
Component: jest.fn(),
})
)
.addItem(
new OptionsPaneItemDescriptor({
title: 'DescriptionMatch',
Component: jest.fn(),
})
)
.addItem(
new OptionsPaneItemDescriptor({
title: 'Frame',
Component: jest.fn(),
})
),
];
}
function getOverrides(): OptionsPaneCategoryDescriptor[] {
return [
new OptionsPaneCategoryDescriptor({
id: 'Override 1',
title: 'Override 1',
})
.addItem(
new OptionsPaneItemDescriptor({
title: 'Match by name',
Component: jest.fn(),
})
)
.addItem(
new OptionsPaneItemDescriptor({
title: 'Min',
Component: jest.fn(),
})
)
.addItem(
new OptionsPaneItemDescriptor({
title: 'Max',
Component: jest.fn(),
})
),
new OptionsPaneCategoryDescriptor({
id: 'Override 2',
title: 'Override 2',
})
.addItem(
new OptionsPaneItemDescriptor({
title: 'Match by name',
Component: jest.fn(),
})
)
.addItem(
new OptionsPaneItemDescriptor({
title: 'Threshold',
Component: jest.fn(),
})
)
.addItem(
new OptionsPaneItemDescriptor({
title: 'Max',
Component: jest.fn(),
})
),
];
}