result_transformer.jest.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { LogLevel } from 'app/core/logs_model';
  2. import { getLogLevel, getSearchMatches } from './result_transformer';
  3. describe('getSearchMatches()', () => {
  4. it('gets no matches for when search and or line are empty', () => {
  5. expect(getSearchMatches('', '')).toEqual([]);
  6. expect(getSearchMatches('foo', '')).toEqual([]);
  7. expect(getSearchMatches('', 'foo')).toEqual([]);
  8. });
  9. it('gets no matches for unmatched search string', () => {
  10. expect(getSearchMatches('foo', 'bar')).toEqual([]);
  11. });
  12. it('gets matches for matched search string', () => {
  13. expect(getSearchMatches('foo', 'foo')).toEqual([{ length: 3, start: 0, text: 'foo' }]);
  14. expect(getSearchMatches(' foo ', 'foo')).toEqual([{ length: 3, start: 1, text: 'foo' }]);
  15. });
  16. expect(getSearchMatches(' foo foo bar ', 'foo|bar')).toEqual([
  17. { length: 3, start: 1, text: 'foo' },
  18. { length: 3, start: 5, text: 'foo' },
  19. { length: 3, start: 9, text: 'bar' },
  20. ]);
  21. });
  22. describe('getLoglevel()', () => {
  23. it('returns no log level on empty line', () => {
  24. expect(getLogLevel('')).toBe(undefined);
  25. });
  26. it('returns no log level on when level is part of a word', () => {
  27. expect(getLogLevel('this is a warning')).toBe(undefined);
  28. });
  29. it('returns log level on line contains a log level', () => {
  30. expect(getLogLevel('warn: it is looking bad')).toBe(LogLevel.warn);
  31. expect(getLogLevel('2007-12-12 12:12:12 [WARN]: it is looking bad')).toBe(LogLevel.warn);
  32. });
  33. it('returns first log level found', () => {
  34. expect(getLogLevel('WARN this could be a debug message')).toBe(LogLevel.warn);
  35. });
  36. });