Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui): extract ReactModal elementApp and fix act warning in ut #1756

Merged
merged 1 commit into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/ui/src/components/ConfirmModal/AcModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}>
Expand Down
1 change: 0 additions & 1 deletion packages/ui/src/components/ConfirmModal/MobileModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
1 change: 0 additions & 1 deletion packages/ui/src/components/Drawer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}
>
Expand Down
8 changes: 5 additions & 3 deletions packages/ui/src/containers/CreateAccount/index.test.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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');
});
});
});
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -78,11 +78,13 @@ describe('<EmailPasswordless/>', () => {

const submitButton = getByText('action.continue');

await waitFor(() => {
act(() => {
fireEvent.click(submitButton);
});

expect(sendSignInEmailPasscode).toBeCalledWith('[email protected]');
await waitFor(() => {
expect(sendSignInEmailPasscode).toBeCalledWith('[email protected]');
});
});

test('should call register method properly', async () => {
Expand All @@ -103,10 +105,12 @@ describe('<EmailPasswordless/>', () => {

const submitButton = getByText('action.continue');

await waitFor(() => {
act(() => {
fireEvent.click(submitButton);
});

expect(sendRegisterEmailPasscode).toBeCalledWith('[email protected]');
await waitFor(() => {
expect(sendRegisterEmailPasscode).toBeCalledWith('[email protected]');
});
});
});
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 () => {
Expand All @@ -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}`);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}
});

Expand Down
2 changes: 2 additions & 0 deletions packages/ui/src/index.tsx
Original file line number Diff line number Diff line change
@@ -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 />);
8 changes: 5 additions & 3 deletions packages/ui/src/pages/SocialSignInCallback/index.test.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -41,8 +41,10 @@ describe('SocialCallbackPage with code', () => {
</SettingsProvider>
);

await waitFor(() => {
expect(signInWithSocialSpy).toBeCalled();
await act(async () => {
await waitFor(() => {
expect(signInWithSocialSpy).toBeCalled();
});
});
});
});