-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c3f0765
commit 08ade4f
Showing
1 changed file
with
24 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,67 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
import GeneralInfo from '../index' | ||
import GeneralInfoCard from '../index' | ||
import { fireEvent, render, screen } from '@testing-library/react' | ||
import '@testing-library/jest-dom' | ||
import { act } from 'react-dom/test-utils' | ||
import { SessionProvider } from 'next-auth/react' | ||
|
||
describe('Personal Data', () => { | ||
beforeEach(async () => { | ||
render(<GeneralInfo />) | ||
render( | ||
<SessionProvider session={null}> | ||
<GeneralInfoCard /> | ||
</SessionProvider> | ||
) | ||
}) | ||
|
||
it('should receive data input correctly', async () => { | ||
fireEvent.input(screen.getByPlaceholderText('Nome'), { | ||
const nameInput = screen.getByLabelText('Nome') | ||
fireEvent.change(nameInput, { | ||
target: { | ||
value: 'Zé do alho', | ||
}, | ||
}) | ||
expect(screen.getByPlaceholderText('Nome')).toHaveValue('Zé do alho') | ||
fireEvent.input(screen.getByPlaceholderText('Email'), { | ||
}); | ||
expect(nameInput).toHaveValue('Zé do alho') | ||
|
||
const emailInput = screen.getByLabelText('Email') | ||
fireEvent.input(emailInput, { | ||
target: { | ||
value: '[email protected]', | ||
}, | ||
}) | ||
expect(screen.getByPlaceholderText('Email')).toHaveValue('[email protected]') | ||
fireEvent.input(screen.getByPlaceholderText('Escreva um resumo sobre você'), { | ||
expect(emailInput).toHaveValue('[email protected]') | ||
|
||
const bioInput = screen.getByLabelText('Descreva de maneira breve sua experiência com web3') | ||
fireEvent.input(bioInput, { | ||
target: { | ||
value: 'Eu sou um desenvolvedor', | ||
}, | ||
}) | ||
expect(screen.getByPlaceholderText('Escreva um resumo sobre você')).toHaveValue( | ||
'Eu sou um desenvolvedor' | ||
) | ||
expect(bioInput).toHaveValue('Eu sou um desenvolvedor') | ||
}) | ||
|
||
it('should throw yup error on saving without name', async () => { | ||
expect(screen.getByRole('button', { name: /salvar/i })) | ||
await act(async () => { | ||
fireEvent.submit(screen.getByRole('button', { name: /salvar/i })) | ||
}) | ||
expect(screen.getByText('Nome é obrigatório')).toBeInTheDocument() | ||
}) | ||
|
||
it('should throw yup error on saving name but without email', async () => { | ||
fireEvent.input(screen.getByPlaceholderText('Nome'), { | ||
target: { | ||
value: 'Zé do alho', | ||
}, | ||
}) | ||
expect(screen.getByPlaceholderText('Nome')).toHaveValue('Zé do alho') | ||
expect(screen.getByRole('button', { name: /salvar/i })) | ||
await act(async () => { | ||
fireEvent.submit(screen.getByRole('button', { name: /salvar/i })) | ||
}) | ||
expect(screen.getByText('Email é obrigatório')).toBeInTheDocument() | ||
expect(screen.getAllByText('This field is required')[0]).toBeInTheDocument() | ||
}) | ||
|
||
it('should throw yup error on saving email but without name', async () => { | ||
fireEvent.input(screen.getByPlaceholderText('Email'), { | ||
target: { | ||
value: '[email protected]', | ||
}, | ||
}) | ||
expect(screen.getByPlaceholderText('Email')).toHaveValue('[email protected]') | ||
expect(screen.getByRole('button', { name: /salvar/i })) | ||
await act(async () => { | ||
fireEvent.submit(screen.getByRole('button', { name: /salvar/i })) | ||
}) | ||
expect(screen.getByText('Nome é obrigatório')).toBeInTheDocument() | ||
}) | ||
|
||
it('should save profile data correctly if name and email are filled but bio is not ', async () => { | ||
fireEvent.input(screen.getByPlaceholderText('Nome'), { | ||
target: { | ||
value: 'Zé do alho', | ||
}, | ||
}) | ||
expect(screen.getByPlaceholderText('Nome')).toHaveValue('Zé do alho') | ||
fireEvent.input(screen.getByPlaceholderText('Email'), { | ||
const emailInput = screen.getByLabelText('Email') | ||
fireEvent.change(emailInput, { | ||
target: { | ||
value: '[email protected]', | ||
}, | ||
}) | ||
expect(screen.getByPlaceholderText('Email')).toHaveValue('[email protected]') | ||
expect(emailInput).toHaveValue('[email protected]') | ||
expect(screen.getByRole('button', { name: /salvar/i })) | ||
await act(async () => { | ||
fireEvent.submit(screen.getByRole('button', { name: /salvar/i })) | ||
}) | ||
expect(screen.queryByText('Nome é obrigatório')).not.toBeInTheDocument() | ||
expect(screen.queryByText('Email é obrigatório')).not.toBeInTheDocument() | ||
expect(screen.getAllByText('This field is required')[0]).toBeInTheDocument() | ||
}) | ||
}) |