2021-10-24 06:09:43 +02:00
|
|
|
import { render, fireEvent } from '@testing-library/react'
|
|
|
|
|
2022-02-19 23:20:33 +01:00
|
|
|
import { Input, getInputType } from '.'
|
2021-10-24 06:09:43 +02:00
|
|
|
|
|
|
|
describe('<Input />', () => {
|
2022-02-19 23:20:33 +01:00
|
|
|
it('should render the label', () => {
|
2021-10-24 06:09:43 +02:00
|
|
|
const labelContent = 'label content'
|
|
|
|
const { getByText } = render(<Input label={labelContent} />)
|
|
|
|
expect(getByText(labelContent)).toBeInTheDocument()
|
|
|
|
})
|
|
|
|
|
2022-02-19 23:20:33 +01:00
|
|
|
it('should not render forgot password link', () => {
|
2021-10-24 06:09:43 +02:00
|
|
|
const { queryByTestId } = render(
|
|
|
|
<Input type='text' label='content' showForgotPassword />
|
|
|
|
)
|
|
|
|
const forgotPasswordLink = queryByTestId('forgot-password-link')
|
|
|
|
expect(forgotPasswordLink).not.toBeInTheDocument()
|
|
|
|
})
|
|
|
|
|
2022-02-19 23:20:33 +01:00
|
|
|
it('should render forgot password link', () => {
|
2021-10-24 06:09:43 +02:00
|
|
|
const { queryByTestId } = render(
|
|
|
|
<Input type='password' label='content' showForgotPassword />
|
|
|
|
)
|
|
|
|
const forgotPasswordLink = queryByTestId('forgot-password-link')
|
|
|
|
expect(forgotPasswordLink).toBeInTheDocument()
|
|
|
|
})
|
|
|
|
|
2022-02-19 23:20:33 +01:00
|
|
|
it('should not render the eye icon if the input is not of type "password"', () => {
|
2021-10-24 06:09:43 +02:00
|
|
|
const { queryByTestId } = render(<Input type='text' label='content' />)
|
|
|
|
const passwordEye = queryByTestId('password-eye')
|
|
|
|
expect(passwordEye).not.toBeInTheDocument()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should handlePassword with eye icon', async () => {
|
|
|
|
const { findByTestId } = render(<Input type='password' label='content' />)
|
|
|
|
const passwordEye = await findByTestId('password-eye')
|
|
|
|
const input = await findByTestId('input')
|
|
|
|
expect(input).toHaveAttribute('type', 'password')
|
|
|
|
fireEvent.click(passwordEye)
|
|
|
|
expect(input).toHaveAttribute('type', 'text')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('getInputType', () => {
|
2022-02-19 23:20:33 +01:00
|
|
|
it('should return `text`', () => {
|
2021-10-24 06:09:43 +02:00
|
|
|
expect(getInputType('password')).toEqual('text')
|
|
|
|
})
|
|
|
|
|
2022-02-19 23:20:33 +01:00
|
|
|
it('should return `password`', () => {
|
2021-10-24 06:09:43 +02:00
|
|
|
expect(getInputType('text')).toEqual('password')
|
|
|
|
})
|
|
|
|
})
|