-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
26e4664
commit 0035625
Showing
2 changed files
with
91 additions
and
119 deletions.
There are no files selected for viewing
119 changes: 0 additions & 119 deletions
119
...ublic/apps/synthetics/components/monitors_page/common/monitor_filters/use_filters.test.ts
This file was deleted.
Oops, something went wrong.
91 changes: 91 additions & 0 deletions
91
...blic/apps/synthetics/components/monitors_page/common/monitor_filters/use_filters.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import React from 'react'; | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import { useFilters } from './use_filters'; | ||
import { useDispatch } from 'react-redux'; | ||
import { WrappedHelper } from '../../../../utils/testing'; | ||
import { fetchMonitorFiltersAction } from '../../../../state'; | ||
|
||
jest.mock('react-redux', () => ({ | ||
...jest.requireActual('react-redux'), | ||
useDispatch: jest.fn().mockReturnValue(jest.fn()), | ||
})); | ||
|
||
describe('useMonitorListFilters', () => { | ||
jest.useFakeTimers(); | ||
|
||
it('returns expected results', () => { | ||
const { result } = renderHook(() => useFilters(), { wrapper: WrappedHelper }); | ||
|
||
expect(result.current).toStrictEqual({ | ||
locations: [], | ||
tags: [], | ||
monitorTypes: [], | ||
projects: [], | ||
schedules: [], | ||
}); | ||
}); | ||
|
||
it('dispatches action when filters are null', () => { | ||
const Wrapper = ({ children }: { children: React.ReactElement }) => { | ||
return ( | ||
<WrappedHelper | ||
state={{ | ||
monitorList: { | ||
monitorFilterOptions: null, | ||
}, | ||
}} | ||
> | ||
{children} | ||
</WrappedHelper> | ||
); | ||
}; | ||
const spy = jest.fn(); | ||
// @ts-ignore | ||
useDispatch.mockReturnValue(spy); | ||
const { result } = renderHook(() => useFilters(), { wrapper: Wrapper }); | ||
|
||
expect(result.current).toStrictEqual(null); | ||
expect(spy).toBeCalledWith(fetchMonitorFiltersAction.get()); | ||
}); | ||
|
||
it('picks up results from filters selector', () => { | ||
const filters = { | ||
locations: [ | ||
{ | ||
label: 'North America', | ||
count: 1, | ||
}, | ||
], | ||
tags: [], | ||
monitorTypes: [{ label: 'http', count: 1 }], | ||
projects: [], | ||
schedules: [], | ||
}; | ||
const Wrapper = ({ children }: { children: React.ReactElement }) => { | ||
return ( | ||
<WrappedHelper | ||
state={{ | ||
monitorList: { | ||
monitorFilterOptions: filters, | ||
}, | ||
}} | ||
> | ||
{children} | ||
</WrappedHelper> | ||
); | ||
}; | ||
const spy = jest.fn(); | ||
// @ts-ignore | ||
useDispatch.mockReturnValue(spy); | ||
const { result } = renderHook(() => useFilters(), { wrapper: Wrapper }); | ||
|
||
expect(result.current).toStrictEqual(filters); | ||
expect(spy).toBeCalledWith(fetchMonitorFiltersAction.get()); | ||
}); | ||
}); |