Skip to content

Commit

Permalink
fix: personal data tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Guboehm authored and nomadbitcoin committed Aug 15, 2024
1 parent c3f0765 commit 08ade4f
Showing 1 changed file with 24 additions and 50 deletions.
74 changes: 24 additions & 50 deletions components/Card/GeneralInfo/PersonalData/index.spec.js
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()
})
})

0 comments on commit 08ade4f

Please sign in to comment.