diff --git a/x-pack/plugins/apm/public/components/app/RumDashboard/LocalUIFilters/use_data_view.test.js b/x-pack/plugins/apm/public/components/app/RumDashboard/LocalUIFilters/use_data_view.test.js new file mode 100644 index 0000000000000..d9eef896782ca --- /dev/null +++ b/x-pack/plugins/apm/public/components/app/RumDashboard/LocalUIFilters/use_data_view.test.js @@ -0,0 +1,44 @@ +/* + * 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 * as dynamicDataView from '../../../../hooks/use_dynamic_data_view'; +import { useDataView } from './use_data_view'; +import { MockApmPluginContextWrapper } from '../../../../context/apm_plugin/mock_apm_plugin_context'; +import { KibanaContextProvider } from '../../../../../../../../src/plugins/kibana_react/public'; + +describe('useDataView', () => { + const create = jest.fn(); + const mockDataService = { + data: { + dataViews: { + create, + }, + }, + }; + + const title = 'apm-*'; + jest + .spyOn(dynamicDataView, 'useDynamicDataViewFetcher') + .mockReturnValue({ dataView: { title } }); + + it('returns result as expected', async () => { + const { waitForNextUpdate } = renderHook(() => useDataView(), { + wrapper: ({ children }) => ( + + + {children} + + + ), + }); + + await waitForNextUpdate(); + + expect(create).toBeCalledWith({ title }); + }); +}); diff --git a/x-pack/plugins/apm/public/components/app/RumDashboard/LocalUIFilters/use_data_view.ts b/x-pack/plugins/apm/public/components/app/RumDashboard/LocalUIFilters/use_data_view.ts index ba99729293368..40d0017d8d096 100644 --- a/x-pack/plugins/apm/public/components/app/RumDashboard/LocalUIFilters/use_data_view.ts +++ b/x-pack/plugins/apm/public/components/app/RumDashboard/LocalUIFilters/use_data_view.ts @@ -6,10 +6,7 @@ */ import { useDynamicDataViewFetcher } from '../../../../hooks/use_dynamic_data_view'; -import { - DataView, - DataViewSpec, -} from '../../../../../../../../src/plugins/data/common'; +import { DataView } from '../../../../../../../../src/plugins/data/common'; import { useKibana } from '../../../../../../../../src/plugins/kibana_react/public'; import { useFetcher } from '../../../../hooks/use_fetcher'; import { DataPublicPluginStart } from '../../../../../../../../src/plugins/data/public'; @@ -26,8 +23,8 @@ export function useDataView() { const { data } = useFetcher>(async () => { if (dataView?.title) { return dataViews.create({ - pattern: dataView?.title, - } as DataViewSpec); + title: dataView?.title, + }); } }, [dataView?.title, dataViews]);