useDetailState.test.ts 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { TraceLog } from '@jaegertracing/jaeger-ui-components/src/types/trace';
  2. import { act, renderHook } from '@testing-library/react-hooks';
  3. import { DataFrame } from '@grafana/data';
  4. import { useDetailState } from './useDetailState';
  5. const sampleFrame: DataFrame = {
  6. name: 'trace',
  7. fields: [],
  8. length: 0,
  9. };
  10. describe('useDetailState', () => {
  11. it('toggles detail', async () => {
  12. const { result } = renderHook(() => useDetailState(sampleFrame));
  13. expect(result.current.detailStates.size).toBe(0);
  14. act(() => result.current.toggleDetail('span1'));
  15. expect(result.current.detailStates.size).toBe(1);
  16. expect(result.current.detailStates.has('span1')).toBe(true);
  17. act(() => result.current.toggleDetail('span1'));
  18. expect(result.current.detailStates.size).toBe(0);
  19. });
  20. it('toggles logs and logs items', async () => {
  21. const { result } = renderHook(() => useDetailState(sampleFrame));
  22. act(() => result.current.toggleDetail('span1'));
  23. act(() => result.current.detailLogsToggle('span1'));
  24. expect(result.current.detailStates.get('span1')?.logs.isOpen).toBe(true);
  25. const log = { timestamp: 1 } as TraceLog;
  26. act(() => result.current.detailLogItemToggle('span1', log));
  27. expect(result.current.detailStates.get('span1')?.logs.openedItems.has(log)).toBe(true);
  28. });
  29. it('toggles warnings', async () => {
  30. const { result } = renderHook(() => useDetailState(sampleFrame));
  31. act(() => result.current.toggleDetail('span1'));
  32. act(() => result.current.detailWarningsToggle('span1'));
  33. expect(result.current.detailStates.get('span1')?.isWarningsOpen).toBe(true);
  34. });
  35. it('toggles references', async () => {
  36. const { result } = renderHook(() => useDetailState(sampleFrame));
  37. act(() => result.current.toggleDetail('span1'));
  38. act(() => result.current.detailReferencesToggle('span1'));
  39. expect(result.current.detailStates.get('span1')?.references.isOpen).toBe(true);
  40. });
  41. it('toggles processes', async () => {
  42. const { result } = renderHook(() => useDetailState(sampleFrame));
  43. act(() => result.current.toggleDetail('span1'));
  44. act(() => result.current.detailProcessToggle('span1'));
  45. expect(result.current.detailStates.get('span1')?.isProcessOpen).toBe(true);
  46. });
  47. it('toggles tags', async () => {
  48. const { result } = renderHook(() => useDetailState(sampleFrame));
  49. act(() => result.current.toggleDetail('span1'));
  50. act(() => result.current.detailTagsToggle('span1'));
  51. expect(result.current.detailStates.get('span1')?.isTagsOpen).toBe(true);
  52. });
  53. });