-
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.
[Synthetics] filters - remove public so client usage (#158095)
Co-authored-by: shahzad31 <shahzad31comp@gmail.com>
- Loading branch information
1 parent
0deffa4
commit 8f16d9e
Showing
46 changed files
with
420 additions
and
298 deletions.
There are no files selected for viewing
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
25 changes: 25 additions & 0 deletions
25
x-pack/plugins/synthetics/common/runtime_types/monitor_management/filters.ts
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,25 @@ | ||
/* | ||
* 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 * as t from 'io-ts'; | ||
|
||
const MonitorFilterCodec = t.interface({ | ||
label: t.string, | ||
count: t.number, | ||
}); | ||
|
||
export type MonitorFilter = t.TypeOf<typeof MonitorFilterCodec>; | ||
|
||
export const MonitorFiltersResultCodec = t.interface({ | ||
monitorTypes: t.array(MonitorFilterCodec), | ||
tags: t.array(MonitorFilterCodec), | ||
locations: t.array(MonitorFilterCodec), | ||
projects: t.array(MonitorFilterCodec), | ||
schedules: t.array(MonitorFilterCodec), | ||
}); | ||
|
||
export type MonitorFiltersResult = t.TypeOf<typeof MonitorFiltersResultCodec>; |
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
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
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
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()); | ||
}); | ||
}); |
Oops, something went wrong.