0
Fork 0
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:
simeng-li 2022-08-09 11:00:43 +08:00 committed by GitHub
parent 4b972f2e23
commit 0270bf1be3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 34 additions and 22 deletions

View file

@ -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}>

View file

@ -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}>

View file

@ -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>

View file

@ -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}
>

View file

@ -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);
});
expect(register).toBeCalledWith('username', '123456');
await waitFor(() => {
expect(register).toBeCalledWith('username', '123456');
});
});
});

View file

@ -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,11 +78,13 @@ describe('<EmailPasswordless/>', () => {
const submitButton = getByText('action.continue');
await waitFor(() => {
act(() => {
fireEvent.click(submitButton);
});
expect(sendSignInEmailPasscode).toBeCalledWith('foo@logto.io');
await waitFor(() => {
expect(sendSignInEmailPasscode).toBeCalledWith('foo@logto.io');
});
});
test('should call register method properly', async () => {
@ -103,10 +105,12 @@ describe('<EmailPasswordless/>', () => {
const submitButton = getByText('action.continue');
await waitFor(() => {
act(() => {
fireEvent.click(submitButton);
});
expect(sendRegisterEmailPasscode).toBeCalledWith('foo@logto.io');
await waitFor(() => {
expect(sendRegisterEmailPasscode).toBeCalledWith('foo@logto.io');
});
});
});

View file

@ -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,11 +85,13 @@ describe('<PhonePasswordless/>', () => {
const submitButton = getByText('action.continue');
await waitFor(() => {
act(() => {
fireEvent.click(submitButton);
});
expect(sendSignInSmsPasscode).toBeCalledWith(`${defaultCountryCallingCode}${phoneNumber}`);
await waitFor(() => {
expect(sendSignInSmsPasscode).toBeCalledWith(`${defaultCountryCallingCode}${phoneNumber}`);
});
});
test('should call register method properly', async () => {
@ -110,10 +112,12 @@ describe('<PhonePasswordless/>', () => {
const submitButton = getByText('action.continue');
await waitFor(() => {
act(() => {
fireEvent.click(submitButton);
});
expect(sendRegisterSmsPasscode).toBeCalledWith(`${defaultCountryCallingCode}${phoneNumber}`);
await waitFor(() => {
expect(sendRegisterSmsPasscode).toBeCalledWith(`${defaultCountryCallingCode}${phoneNumber}`);
});
});
});

View file

@ -81,11 +81,13 @@ describe('SecondarySocialSignIn', () => {
const socialButton = container.querySelector('button');
if (socialButton) {
await waitFor(() => {
act(() => {
fireEvent.click(socialButton);
});
expect(invokeSocialSignInSpy).toBeCalled();
void waitFor(() => {
expect(invokeSocialSignInSpy).toBeCalled();
});
}
});

View file

@ -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 />);

View file

@ -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 waitFor(() => {
expect(signInWithSocialSpy).toBeCalled();
await act(async () => {
await waitFor(() => {
expect(signInWithSocialSpy).toBeCalled();
});
});
});
});