Skip to content

Commit

Permalink
Reuse test providers in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
arkadiuszbachorski committed Nov 4, 2024
1 parent 3d6f2eb commit 15e492d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
// SPDX-License-Identifier: MIT
//

import { render, screen } from '@testing-library/react'
import { screen } from '@testing-library/react'
import { userEvent } from '@testing-library/user-event'
import { type Auth } from 'firebase/auth'
import { vitest } from 'vitest'
import { renderWithProviders } from '@/tests/helpers'
import { EmailPasswordForm } from './EmailPasswordForm'
import { Providers } from '../../../../tests/Providers'

const authMock = {} as Auth
const signInWithEmailAndPasswordMock = vitest.fn()
Expand Down Expand Up @@ -48,12 +48,11 @@ describe('EmailPasswordForm', () => {
})

it('calls signIn function', async () => {
render(
renderWithProviders(
<EmailPasswordForm
signInWithEmailAndPassword={signInWithEmailAndPasswordMock}
auth={authMock}
/>,
{ wrapper: Providers },
)
await signIn()

Expand All @@ -66,12 +65,11 @@ describe('EmailPasswordForm', () => {

it('validates against empty values', async () => {
const user = userEvent.setup()
render(
renderWithProviders(
<EmailPasswordForm
signInWithEmailAndPassword={signInWithEmailAndPasswordMock}
auth={authMock}
/>,
{ wrapper: Providers },
)

await user.type(getPasswordField(), 'something')
Expand All @@ -85,12 +83,11 @@ describe('EmailPasswordForm', () => {
signInWithEmailAndPasswordMock.mockImplementation(() => {
throw new InvalidCredsError()
})
render(
renderWithProviders(
<EmailPasswordForm
signInWithEmailAndPassword={signInWithEmailAndPasswordMock}
auth={authMock}
/>,
{ wrapper: Providers },
)

await signIn()
Expand Down
12 changes: 5 additions & 7 deletions src/modules/auth/SignInForm/SignInForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
// SPDX-License-Identifier: MIT
//

import { fireEvent, render, screen } from '@testing-library/react'
import { fireEvent, screen } from '@testing-library/react'
import { type Auth, type AuthProvider } from 'firebase/auth'
import { vitest } from 'vitest'
import { renderWithProviders } from '@/tests/helpers'
import { SignInForm } from './SignInForm'
import { Providers } from '../../../tests/Providers'

const authMock = {} as Auth
const providerMock = {} as AuthProvider
Expand All @@ -34,7 +34,7 @@ describe('SignInForm', () => {
})

it('renders SSO providers and calls signInWithPopup', () => {
render(<SignInForm {...defaultProps} />, { wrapper: Providers })
renderWithProviders(<SignInForm {...defaultProps} />)

const ssoButton = screen.getByRole('button', { name: 'Sign in with Lorem' })
fireEvent.click(ssoButton)
Expand All @@ -43,27 +43,25 @@ describe('SignInForm', () => {
})

it('renders email password form', () => {
render(
renderWithProviders(
<SignInForm
{...defaultProps}
enableEmailPassword={true}
providers={[]}
/>,
{ wrapper: Providers },
)

const input = screen.getByRole('textbox')
expect(input).toBeInTheDocument()
})

it('renders separator only if has providers and email password', () => {
const { rerender } = render(
const { rerender } = renderWithProviders(
<SignInForm
{...defaultProps}
enableEmailPassword={true}
providers={[]}
/>,
{ wrapper: Providers },
)

expect(screen.queryByText('or')).not.toBeInTheDocument()
Expand Down

0 comments on commit 15e492d

Please sign in to comment.