mirror of
https://github.com/glitch-soc/mastodon.git
synced 2025-12-13 15:58:50 +00:00
[Glitch] Storybook Helpers
Port c52848b444 to glitch-soc, kinda
Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
@@ -1,60 +0,0 @@
|
|||||||
import PropTypes from 'prop-types';
|
|
||||||
import type { PropsWithChildren } from 'react';
|
|
||||||
import { Component } from 'react';
|
|
||||||
|
|
||||||
import { IntlProvider } from 'react-intl';
|
|
||||||
|
|
||||||
import { MemoryRouter } from 'react-router';
|
|
||||||
|
|
||||||
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
||||||
import { render as rtlRender } from '@testing-library/react';
|
|
||||||
|
|
||||||
class FakeIdentityWrapper extends Component<
|
|
||||||
PropsWithChildren<{ signedIn: boolean }>
|
|
||||||
> {
|
|
||||||
static childContextTypes = {
|
|
||||||
identity: PropTypes.shape({
|
|
||||||
signedIn: PropTypes.bool.isRequired,
|
|
||||||
accountId: PropTypes.string,
|
|
||||||
disabledAccountId: PropTypes.string,
|
|
||||||
}).isRequired,
|
|
||||||
};
|
|
||||||
|
|
||||||
getChildContext() {
|
|
||||||
return {
|
|
||||||
identity: {
|
|
||||||
signedIn: this.props.signedIn,
|
|
||||||
accountId: '123',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
return this.props.children;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function render(
|
|
||||||
ui: React.ReactElement,
|
|
||||||
{ locale = 'en', signedIn = true, ...renderOptions } = {},
|
|
||||||
) {
|
|
||||||
const Wrapper = (props: { children: React.ReactNode }) => {
|
|
||||||
return (
|
|
||||||
<MemoryRouter>
|
|
||||||
<IntlProvider locale={locale}>
|
|
||||||
<FakeIdentityWrapper signedIn={signedIn}>
|
|
||||||
{props.children}
|
|
||||||
</FakeIdentityWrapper>
|
|
||||||
</IntlProvider>
|
|
||||||
</MemoryRouter>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
return rtlRender(ui, { wrapper: Wrapper, ...renderOptions });
|
|
||||||
}
|
|
||||||
|
|
||||||
// re-export everything
|
|
||||||
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
||||||
export * from '@testing-library/react';
|
|
||||||
|
|
||||||
// override render method
|
|
||||||
export { render };
|
|
||||||
Reference in New Issue
Block a user