grafana/public/app/features/explore/TraceView/useSearch.test.ts
Andre Pereira afd39c18ba
Explore: Refactor trace view and move to core (#61938)
* Move TraceView to core grafana

* Remove unused code

* yarn install

* Remove jaeger-ui-components from CODEOWNERS and other tools

* Type fixes

* yarn install

* Remove mock that we no longer need

* Fix merge conflicts

* Re-add Apache license for trace view components

* Use an exclamation-circle instead of triangle to denote errors

* Remove eslint disables and update betterer results instead
2023-01-27 14:13:17 +00:00

46 lines
1.2 KiB
TypeScript

import { act, renderHook } from '@testing-library/react-hooks';
import { TraceSpan } from './components';
import { useSearch } from './useSearch';
describe('useSearch', () => {
it('returns matching span IDs', async () => {
const { result } = renderHook(() =>
useSearch([
{
spanID: 'span1',
operationName: 'operation1',
process: {
serviceName: 'service1',
tags: [],
},
tags: [],
logs: [],
} as unknown as TraceSpan,
{
spanID: 'span2',
operationName: 'operation2',
process: {
serviceName: 'service2',
tags: [],
},
tags: [],
logs: [],
} as unknown as TraceSpan,
])
);
act(() => result.current.setSearch('service1'));
expect(result.current.spanFindMatches?.size).toBe(1);
expect(result.current.spanFindMatches?.has('span1')).toBe(true);
});
it('works without spans', async () => {
const { result } = renderHook(() => useSearch());
act(() => result.current.setSearch('service1'));
expect(result.current.spanFindMatches).toBe(undefined);
});
});