mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
fix(ui): extract ReactModal elementApp and fix act warning in ut (#1756)
extract ReactModal elementApp and fix act warning in ut
This commit is contained in:
parent
4b972f2e23
commit
0270bf1be3
10 changed files with 34 additions and 22 deletions
|
@ -27,7 +27,6 @@ const AcModal = ({
|
|||
isOpen={isOpen}
|
||||
className={classNames(styles.modal, className)}
|
||||
overlayClassName={classNames(modalStyles.overlay, styles.overlay)}
|
||||
appElement={document.querySelector('main') ?? undefined}
|
||||
>
|
||||
<div className={styles.container}>
|
||||
<div className={styles.header}>
|
||||
|
|
|
@ -32,7 +32,6 @@ const IframeConfirmModal = ({
|
|||
isOpen={isOpen}
|
||||
className={classNames(styles.modal, className)}
|
||||
overlayClassName={classNames(modalStyles.overlay, styles.overlay)}
|
||||
appElement={document.querySelector('main') ?? undefined}
|
||||
>
|
||||
<div className={styles.container}>
|
||||
<div className={styles.content}>
|
||||
|
|
|
@ -25,7 +25,6 @@ const MobileModal = ({
|
|||
isOpen={isOpen}
|
||||
className={classNames(styles.modal, className)}
|
||||
overlayClassName={classNames(modalStyles.overlay, styles.overlay)}
|
||||
appElement={document.querySelector('main') ?? undefined}
|
||||
>
|
||||
<div className={styles.container}>
|
||||
<div className={styles.content}>{children}</div>
|
||||
|
|
|
@ -23,7 +23,6 @@ const Drawer = ({ className, isOpen = false, children, onClose }: Props) => {
|
|||
isOpen={isOpen}
|
||||
className={classNames(styles.drawer, className)}
|
||||
overlayClassName={modalStyles.overlay}
|
||||
appElement={document.querySelector('main') ?? undefined}
|
||||
closeTimeoutMS={300}
|
||||
onRequestClose={onClose}
|
||||
>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { fireEvent, waitFor } from '@testing-library/react';
|
||||
import { fireEvent, waitFor, act } from '@testing-library/react';
|
||||
|
||||
import renderWithPageContext from '@/__mocks__/RenderWithPageContext';
|
||||
import SettingsProvider from '@/__mocks__/RenderWithPageContext/SettingsProvider';
|
||||
|
@ -218,10 +218,12 @@ describe('<CreateAccount/>', () => {
|
|||
const termsButton = getByText('description.agree_with_terms');
|
||||
fireEvent.click(termsButton);
|
||||
|
||||
await waitFor(() => {
|
||||
act(() => {
|
||||
fireEvent.click(submitButton);
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(register).toBeCalledWith('username', '123456');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { fireEvent, waitFor } from '@testing-library/react';
|
||||
import { fireEvent, waitFor, act } from '@testing-library/react';
|
||||
import { MemoryRouter } from 'react-router-dom';
|
||||
|
||||
import renderWithPageContext from '@/__mocks__/RenderWithPageContext';
|
||||
|
@ -78,12 +78,14 @@ describe('<EmailPasswordless/>', () => {
|
|||
|
||||
const submitButton = getByText('action.continue');
|
||||
|
||||
await waitFor(() => {
|
||||
act(() => {
|
||||
fireEvent.click(submitButton);
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(sendSignInEmailPasscode).toBeCalledWith('foo@logto.io');
|
||||
});
|
||||
});
|
||||
|
||||
test('should call register method properly', async () => {
|
||||
const { container, getByText } = renderWithPageContext(
|
||||
|
@ -103,10 +105,12 @@ describe('<EmailPasswordless/>', () => {
|
|||
|
||||
const submitButton = getByText('action.continue');
|
||||
|
||||
await waitFor(() => {
|
||||
act(() => {
|
||||
fireEvent.click(submitButton);
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(sendRegisterEmailPasscode).toBeCalledWith('foo@logto.io');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { fireEvent, waitFor } from '@testing-library/react';
|
||||
import { fireEvent, waitFor, act } from '@testing-library/react';
|
||||
import { MemoryRouter } from 'react-router-dom';
|
||||
|
||||
import renderWithPageContext from '@/__mocks__/RenderWithPageContext';
|
||||
|
@ -85,12 +85,14 @@ describe('<PhonePasswordless/>', () => {
|
|||
|
||||
const submitButton = getByText('action.continue');
|
||||
|
||||
await waitFor(() => {
|
||||
act(() => {
|
||||
fireEvent.click(submitButton);
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(sendSignInSmsPasscode).toBeCalledWith(`${defaultCountryCallingCode}${phoneNumber}`);
|
||||
});
|
||||
});
|
||||
|
||||
test('should call register method properly', async () => {
|
||||
const { container, getByText } = renderWithPageContext(
|
||||
|
@ -110,10 +112,12 @@ describe('<PhonePasswordless/>', () => {
|
|||
|
||||
const submitButton = getByText('action.continue');
|
||||
|
||||
await waitFor(() => {
|
||||
act(() => {
|
||||
fireEvent.click(submitButton);
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(sendRegisterSmsPasscode).toBeCalledWith(`${defaultCountryCallingCode}${phoneNumber}`);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -81,11 +81,13 @@ describe('SecondarySocialSignIn', () => {
|
|||
const socialButton = container.querySelector('button');
|
||||
|
||||
if (socialButton) {
|
||||
await waitFor(() => {
|
||||
act(() => {
|
||||
fireEvent.click(socialButton);
|
||||
});
|
||||
|
||||
void waitFor(() => {
|
||||
expect(invokeSocialSignInSpy).toBeCalled();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
import { createRoot } from 'react-dom/client';
|
||||
import ReactModal from 'react-modal';
|
||||
|
||||
import App from './App';
|
||||
|
||||
const app = document.querySelector('#app');
|
||||
const root = app && createRoot(app);
|
||||
ReactModal.setAppElement('#app');
|
||||
root?.render(<App />);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { waitFor } from '@testing-library/react';
|
||||
import { waitFor, act } from '@testing-library/react';
|
||||
import { MemoryRouter, Route, Routes } from 'react-router-dom';
|
||||
|
||||
import renderWithPageContext from '@/__mocks__/RenderWithPageContext';
|
||||
|
@ -41,8 +41,10 @@ describe('SocialCallbackPage with code', () => {
|
|||
</SettingsProvider>
|
||||
);
|
||||
|
||||
await act(async () => {
|
||||
await waitFor(() => {
|
||||
expect(signInWithSocialSpy).toBeCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue