Fix a warning when running JS Tests because of FakeIdentityContext using deprecated context API (#30368)
parent
0f07e1cd4c
commit
990a0c19a9
|
@ -1,7 +1,3 @@
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
import type { PropsWithChildren } from 'react';
|
|
||||||
import { Component } from 'react';
|
|
||||||
|
|
||||||
import { IntlProvider } from 'react-intl';
|
import { IntlProvider } from 'react-intl';
|
||||||
|
|
||||||
import { MemoryRouter } from 'react-router';
|
import { MemoryRouter } from 'react-router';
|
||||||
|
@ -9,44 +5,27 @@ import { MemoryRouter } from 'react-router';
|
||||||
// eslint-disable-next-line import/no-extraneous-dependencies
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||||
import { render as rtlRender } from '@testing-library/react';
|
import { render as rtlRender } from '@testing-library/react';
|
||||||
|
|
||||||
class FakeIdentityWrapper extends Component<
|
import { IdentityContext } from './identity_context';
|
||||||
PropsWithChildren<{ signedIn: boolean }>
|
|
||||||
> {
|
|
||||||
static childContextTypes = {
|
|
||||||
identity: PropTypes.shape({
|
|
||||||
signedIn: PropTypes.bool.isRequired,
|
|
||||||
accountId: PropTypes.string,
|
|
||||||
disabledAccountId: PropTypes.string,
|
|
||||||
accessToken: PropTypes.string,
|
|
||||||
}).isRequired,
|
|
||||||
};
|
|
||||||
|
|
||||||
getChildContext() {
|
|
||||||
return {
|
|
||||||
identity: {
|
|
||||||
signedIn: this.props.signedIn,
|
|
||||||
accountId: '123',
|
|
||||||
accessToken: 'test-access-token',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
return this.props.children;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function render(
|
function render(
|
||||||
ui: React.ReactElement,
|
ui: React.ReactElement,
|
||||||
{ locale = 'en', signedIn = true, ...renderOptions } = {},
|
{ locale = 'en', signedIn = true, ...renderOptions } = {},
|
||||||
) {
|
) {
|
||||||
|
const fakeIdentity = {
|
||||||
|
signedIn: signedIn,
|
||||||
|
accountId: '123',
|
||||||
|
accessToken: 'test-access-token',
|
||||||
|
disabledAccountId: undefined,
|
||||||
|
permissions: 0,
|
||||||
|
};
|
||||||
|
|
||||||
const Wrapper = (props: { children: React.ReactNode }) => {
|
const Wrapper = (props: { children: React.ReactNode }) => {
|
||||||
return (
|
return (
|
||||||
<MemoryRouter>
|
<MemoryRouter>
|
||||||
<IntlProvider locale={locale}>
|
<IntlProvider locale={locale}>
|
||||||
<FakeIdentityWrapper signedIn={signedIn}>
|
<IdentityContext.Provider value={fakeIdentity}>
|
||||||
{props.children}
|
{props.children}
|
||||||
</FakeIdentityWrapper>
|
</IdentityContext.Provider>
|
||||||
</IntlProvider>
|
</IntlProvider>
|
||||||
</MemoryRouter>
|
</MemoryRouter>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue