1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- import { TraceLog } from '@jaegertracing/jaeger-ui-components/src/types/trace';
- import { act, renderHook } from '@testing-library/react-hooks';
- import { DataFrame } from '@grafana/data';
- import { useDetailState } from './useDetailState';
- const sampleFrame: DataFrame = {
- name: 'trace',
- fields: [],
- length: 0,
- };
- describe('useDetailState', () => {
- it('toggles detail', async () => {
- const { result } = renderHook(() => useDetailState(sampleFrame));
- expect(result.current.detailStates.size).toBe(0);
- act(() => result.current.toggleDetail('span1'));
- expect(result.current.detailStates.size).toBe(1);
- expect(result.current.detailStates.has('span1')).toBe(true);
- act(() => result.current.toggleDetail('span1'));
- expect(result.current.detailStates.size).toBe(0);
- });
- it('toggles logs and logs items', async () => {
- const { result } = renderHook(() => useDetailState(sampleFrame));
- act(() => result.current.toggleDetail('span1'));
- act(() => result.current.detailLogsToggle('span1'));
- expect(result.current.detailStates.get('span1')?.logs.isOpen).toBe(true);
- const log = { timestamp: 1 } as TraceLog;
- act(() => result.current.detailLogItemToggle('span1', log));
- expect(result.current.detailStates.get('span1')?.logs.openedItems.has(log)).toBe(true);
- });
- it('toggles warnings', async () => {
- const { result } = renderHook(() => useDetailState(sampleFrame));
- act(() => result.current.toggleDetail('span1'));
- act(() => result.current.detailWarningsToggle('span1'));
- expect(result.current.detailStates.get('span1')?.isWarningsOpen).toBe(true);
- });
- it('toggles references', async () => {
- const { result } = renderHook(() => useDetailState(sampleFrame));
- act(() => result.current.toggleDetail('span1'));
- act(() => result.current.detailReferencesToggle('span1'));
- expect(result.current.detailStates.get('span1')?.references.isOpen).toBe(true);
- });
- it('toggles processes', async () => {
- const { result } = renderHook(() => useDetailState(sampleFrame));
- act(() => result.current.toggleDetail('span1'));
- act(() => result.current.detailProcessToggle('span1'));
- expect(result.current.detailStates.get('span1')?.isProcessOpen).toBe(true);
- });
- it('toggles tags', async () => {
- const { result } = renderHook(() => useDetailState(sampleFrame));
- act(() => result.current.toggleDetail('span1'));
- act(() => result.current.detailTagsToggle('span1'));
- expect(result.current.detailStates.get('span1')?.isTagsOpen).toBe(true);
- });
- });
|