mirror of
https://github.com/grafana/grafana.git
synced 2025-02-15 10:03:33 -06:00
A logging query has a selector part and a regexp. The regexp matches are highlighted when results return. This change adds live preview to matches when modifying the regexp in a search field. - delegate retrieval of match query to datasource - datasource returns search expressions to be used to highlight a live preview of matches - logs row now takes preview highlights - logs row renders preview highlights with dotted line to distinguish from query run matches (solid line) - fix react-highlight-words version to ensure custom chunk matcher - custom chunk matcher can now also take incomplete regexps, eg, `(level` without inifinte looping - perf: debounce of live preview to 500ms - perf: only top 100 rows get the live preview - preview is only supported with one query row (multiple rows semantic makes this tricky: regexp for row n should only filter results for query n)
36 lines
1.3 KiB
TypeScript
36 lines
1.3 KiB
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 }]);
|
|
});
|
|
|
|
test('should find all matches for a complete regex', () => {
|
|
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 },
|
|
]);
|
|
});
|
|
|
|
test('not fail on incomplete regex', () => {
|
|
expect(findMatchesInText(' foo foo bar ', 'foo|')).toEqual([
|
|
{ length: 3, start: 1, text: 'foo', end: 4 },
|
|
{ length: 3, start: 5, text: 'foo', end: 8 },
|
|
]);
|
|
expect(findMatchesInText('foo foo bar', '(')).toEqual([]);
|
|
expect(findMatchesInText('foo foo bar', '(foo|')).toEqual([]);
|
|
});
|
|
});
|