Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unhandled promise rejection #114233

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
waitForElementToBeRemoved,
screen,
} from '@testing-library/react';
import { __IntlProvider as IntlProvider } from '@kbn/i18n/react';
import { createMemoryHistory } from 'history';
import * as fetcherHook from '../../../../../hooks/use_fetcher';
import { SelectableUrlList } from './SelectableUrlList';
Expand All @@ -32,54 +33,60 @@ describe('SelectableUrlList', () => {
function WrappedComponent() {
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
return (
<SelectableUrlList
initialValue={'blog'}
loading={false}
data={{ items: [], total: 0 }}
onChange={jest.fn()}
searchValue={'blog'}
onInputChange={jest.fn()}
onTermChange={jest.fn()}
popoverIsOpen={Boolean(isPopoverOpen)}
setPopoverIsOpen={setIsPopoverOpen}
onApply={jest.fn()}
/>
<IntlProvider locale="en">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can move this wrapper to the render method in '../../utils/test_helper'

<SelectableUrlList
initialValue={'blog'}
loading={false}
data={{ items: [], total: 0 }}
onChange={jest.fn()}
searchValue={'blog'}
onInputChange={jest.fn()}
onTermChange={jest.fn()}
popoverIsOpen={Boolean(isPopoverOpen)}
setPopoverIsOpen={setIsPopoverOpen}
onApply={jest.fn()}
/>
</IntlProvider>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this needed to run the apm jest tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was triggering a warning error

);
}

it('it uses search term value from url', () => {
const { getByDisplayValue } = render(
<SelectableUrlList
initialValue={'blog'}
loading={false}
data={{ items: [], total: 0 }}
onChange={jest.fn()}
searchValue={'blog'}
onInputChange={jest.fn()}
onTermChange={jest.fn()}
popoverIsOpen={false}
setPopoverIsOpen={jest.fn()}
onApply={jest.fn()}
/>,
<IntlProvider locale="en">
<SelectableUrlList
initialValue={'blog'}
loading={false}
data={{ items: [], total: 0 }}
onChange={jest.fn()}
searchValue={'blog'}
onInputChange={jest.fn()}
onTermChange={jest.fn()}
popoverIsOpen={false}
setPopoverIsOpen={jest.fn()}
onApply={jest.fn()}
/>
</IntlProvider>,
{ customHistory }
);
expect(getByDisplayValue('blog')).toBeInTheDocument();
});

it('maintains focus on search input field', () => {
const { getByLabelText } = render(
<SelectableUrlList
initialValue={'blog'}
loading={false}
data={{ items: [], total: 0 }}
onChange={jest.fn()}
searchValue={'blog'}
onInputChange={jest.fn()}
onTermChange={jest.fn()}
popoverIsOpen={false}
setPopoverIsOpen={jest.fn()}
onApply={jest.fn()}
/>,
<IntlProvider locale="en">
<SelectableUrlList
initialValue={'blog'}
loading={false}
data={{ items: [], total: 0 }}
onChange={jest.fn()}
searchValue={'blog'}
onInputChange={jest.fn()}
onTermChange={jest.fn()}
popoverIsOpen={false}
setPopoverIsOpen={jest.fn()}
onApply={jest.fn()}
/>
</IntlProvider>,
{ customHistory }
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ import { createMemoryHistory } from 'history';
import { MemoryRouter, RouteComponentProps } from 'react-router-dom';
import { CoreStart, DocLinksStart, HttpStart } from 'kibana/public';
import { createKibanaReactContext } from 'src/plugins/kibana_react/public';
import { createCallApmApi } from '../../../services/rest/createCallApmApi';

const { location } = createMemoryHistory();

const KibanaReactContext = createKibanaReactContext({
notifications: { toasts: { add: () => {} } },
usageCollection: { reportUiCounter: () => {} },
observability: {
navigation: {
Expand All @@ -39,7 +41,7 @@ const KibanaReactContext = createKibanaReactContext({
observability: { guide: '' },
},
} as unknown as DocLinksStart,
} as Partial<CoreStart>);
} as unknown as Partial<CoreStart>);

function Wrapper({ children }: { children?: ReactNode }) {
return (
Expand All @@ -52,6 +54,9 @@ function Wrapper({ children }: { children?: ReactNode }) {
}

describe('Settings', () => {
beforeEach(() => {
createCallApmApi({} as CoreStart);
});
it('renders', async () => {
const routerProps = {
location,
Expand Down