mirror of
https://github.com/grafana/grafana.git
synced 2025-02-12 00:25:46 -06:00
- use react-highlight-words - add highlighting (color and border) to the matching substring of the suggested items in the typeahead - extracted match finding from logging datasource - created new utils/text.ts class for text-related functions - added more types
25 lines
938 B
TypeScript
25 lines
938 B
TypeScript
import { findMatchesInText } from './text';
|
|
|
|
describe('findMatchesInText()', () => {
|
|
it('gets no matches for when search and or line are empty', () => {
|
|
expect(findMatchesInText('', '')).toEqual([]);
|
|
expect(findMatchesInText('foo', '')).toEqual([]);
|
|
expect(findMatchesInText('', 'foo')).toEqual([]);
|
|
});
|
|
|
|
it('gets no matches for unmatched search string', () => {
|
|
expect(findMatchesInText('foo', 'bar')).toEqual([]);
|
|
});
|
|
|
|
it('gets matches for matched search string', () => {
|
|
expect(findMatchesInText('foo', 'foo')).toEqual([{ length: 3, start: 0, text: 'foo', end: 3 }]);
|
|
expect(findMatchesInText(' foo ', 'foo')).toEqual([{ length: 3, start: 1, text: 'foo', end: 4 }]);
|
|
});
|
|
|
|
expect(findMatchesInText(' foo foo bar ', 'foo|bar')).toEqual([
|
|
{ length: 3, start: 1, text: 'foo', end: 4 },
|
|
{ length: 3, start: 5, text: 'foo', end: 8 },
|
|
{ length: 3, start: 9, text: 'bar', end: 12 },
|
|
]);
|
|
});
|