Skip to content

Commit

Permalink
Fix undhandle promise rejection
Browse files Browse the repository at this point in the history
  • Loading branch information
MiriamAparicio committed Oct 7, 2021
1 parent 95d53a2 commit 06e16e4
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 37 deletions.
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">
<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>
);
}

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

0 comments on commit 06e16e4

Please sign in to comment.