useSearch.test.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { act, renderHook } from '@testing-library/react-hooks';
  2. import { TraceSpan } from '@jaegertracing/jaeger-ui-components';
  3. import { useSearch } from './useSearch';
  4. describe('useSearch', () => {
  5. it('returns matching span IDs', async () => {
  6. const { result } = renderHook(() =>
  7. useSearch([
  8. {
  9. spanID: 'span1',
  10. operationName: 'operation1',
  11. process: {
  12. serviceName: 'service1',
  13. tags: [],
  14. },
  15. tags: [],
  16. logs: [],
  17. } as unknown as TraceSpan,
  18. {
  19. spanID: 'span2',
  20. operationName: 'operation2',
  21. process: {
  22. serviceName: 'service2',
  23. tags: [],
  24. },
  25. tags: [],
  26. logs: [],
  27. } as unknown as TraceSpan,
  28. ])
  29. );
  30. act(() => result.current.setSearch('service1'));
  31. expect(result.current.spanFindMatches?.size).toBe(1);
  32. expect(result.current.spanFindMatches?.has('span1')).toBe(true);
  33. });
  34. it('works without spans', async () => {
  35. const { result } = renderHook(() => useSearch());
  36. act(() => result.current.setSearch('service1'));
  37. expect(result.current.spanFindMatches).toBe(undefined);
  38. });
  39. });