Skip to content

Commit

Permalink
add some tests
Browse files Browse the repository at this point in the history
Signed-off-by: Kawika Avilla <[email protected]>
  • Loading branch information
kavilla committed Nov 15, 2024
1 parent 87f7cc7 commit 361c850
Showing 1 changed file with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,48 @@ describe('useSearch', () => {
});
});

it('should initialize with uninitialized state when dataset type config search on page load is disabled', async () => {
const services = createMockServices();
(services.uiSettings.get as jest.Mock).mockReturnValueOnce(true);
(services.data.query.queryString.getDatasetService as jest.Mock).mockReturnValue({
meta: { searchOnLoad: false },
});
(services.data.query.timefilter.timefilter.getRefreshInterval as jest.Mock).mockReturnValue({
pause: true,
value: 10,
});

const { result, waitForNextUpdate } = renderHook(() => useSearch(services), { wrapper });
expect(result.current.data$.getValue()).toEqual(
expect.objectContaining({ status: ResultStatus.UNINITIALIZED })
);

await act(async () => {
await waitForNextUpdate();
});
});

it('should initialize with uninitialized state when dataset type config search on page load is enabled but the UI setting is disabled', async () => {
const services = createMockServices();
(services.uiSettings.get as jest.Mock).mockReturnValueOnce(false);
(services.data.query.queryString.getDatasetService as jest.Mock).mockReturnValue({
meta: { searchOnLoad: true },
});
(services.data.query.timefilter.timefilter.getRefreshInterval as jest.Mock).mockReturnValue({
pause: true,
value: 10,
});

const { result, waitForNextUpdate } = renderHook(() => useSearch(services), { wrapper });
expect(result.current.data$.getValue()).toEqual(
expect.objectContaining({ status: ResultStatus.UNINITIALIZED })
);

await act(async () => {
await waitForNextUpdate();
});
});

it('should update startTime when hook rerenders', async () => {
const services = createMockServices();

Expand Down

0 comments on commit 361c850

Please sign in to comment.