-
Notifications
You must be signed in to change notification settings - Fork 0
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
57b3d0e
commit 90b5224
Showing
3 changed files
with
144 additions
and
104 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 |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import Form from '../../React/components/Form' | ||
import { render } from '../../helpers/render' | ||
import { screen, fireEvent } from '@testing-library/react' | ||
|
||
const setup = (id) => { | ||
const utils = render(<Form />) | ||
const input = screen.getByTestId(id) | ||
return { | ||
input, | ||
...utils, | ||
} | ||
} | ||
|
||
describe('Form', () => { | ||
test('Should display an error if input firstName is empty', async () => { | ||
const { input } = setup('first-name') | ||
fireEvent.change(input, { target: { value: ' ' } }) | ||
const save = screen.getByTestId('save') | ||
fireEvent.click(save) | ||
expect(screen.getByText('Please fill fields correctly')).toBeTruthy() | ||
}) | ||
test('Should display an error if input lastName is empty', async () => { | ||
const { input } = setup('last-name') | ||
fireEvent.change(input, { target: { value: ' ' } }) | ||
const save = screen.getByTestId('save') | ||
fireEvent.click(save) | ||
expect(screen.getByText('Please fill fields correctly')).toBeTruthy() | ||
}) | ||
test('Should display an error if input date of birth is empty', async () => { | ||
const { input } = setup('date-of-birth') | ||
fireEvent.change(input, { target: { value: ' ' } }) | ||
const save = screen.getByTestId('save') | ||
fireEvent.click(save) | ||
expect(screen.getByText('Please fill fields correctly')).toBeTruthy() | ||
}) | ||
test('Should display an error if input start date is empty', async () => { | ||
const { input } = setup('start-date') | ||
fireEvent.change(input, { target: { value: ' ' } }) | ||
const save = screen.getByTestId('save') | ||
fireEvent.click(save) | ||
expect(screen.getByText('Please fill fields correctly')).toBeTruthy() | ||
}) | ||
test('Should display an error if input street is empty', async () => { | ||
const { input } = setup('street') | ||
fireEvent.change(input, { target: { value: ' ' } }) | ||
const save = screen.getByTestId('save') | ||
fireEvent.click(save) | ||
expect(screen.getByText('Please fill fields correctly')).toBeTruthy() | ||
}) | ||
test('Should display an error if input city is empty', async () => { | ||
const { input } = setup('city') | ||
fireEvent.change(input, { target: { value: ' ' } }) | ||
const save = screen.getByTestId('save') | ||
fireEvent.click(save) | ||
expect(screen.getByText('Please fill fields correctly')).toBeTruthy() | ||
}) | ||
test('Should display an error if input zip code is empty', async () => { | ||
const { input } = setup('city') | ||
fireEvent.change(input, { target: { value: ' ' } }) | ||
const save = screen.getByTestId('save') | ||
fireEvent.click(save) | ||
expect(screen.getByText('Please fill fields correctly')).toBeTruthy() | ||
}) | ||
|
||
test('Should change firstName input value', async () => { | ||
const { input } = setup('first-name') | ||
fireEvent.change(input, { target: { value: 'Bob' } }) | ||
expect(input.value).toBe('Bob') | ||
}) | ||
test('Should change lastName input value', async () => { | ||
const { input } = setup('last-name') | ||
fireEvent.change(input, { target: { value: 'Leponge' } }) | ||
expect(input.value).toBe('Leponge') | ||
}) | ||
test('Should change birth date input value', async () => { | ||
const { input } = setup('date-of-birth') | ||
fireEvent.change(input, { target: { value: '1982-08-28' } }) | ||
expect(input.value).toBe('1982-08-28') | ||
}) | ||
test('Should change start date input value', async () => { | ||
const { input } = setup('start-date') | ||
fireEvent.change(input, { target: { value: '2021-12-10' } }) | ||
expect(input.value).toBe('2021-12-10') | ||
}) | ||
test('Should change street input value', async () => { | ||
const { input } = setup('street') | ||
fireEvent.change(input, { target: { value: '221B Baker street' } }) | ||
expect(input.value).toBe('221B Baker street') | ||
}) | ||
test('Should change city input value', async () => { | ||
const { input } = setup('city') | ||
fireEvent.change(input, { target: { value: 'London' } }) | ||
expect(input.value).toBe('London') | ||
}) | ||
test('Should change zip code input value', async () => { | ||
const { input } = setup('zip-code') | ||
fireEvent.change(input, { target: { value: 45856 } }) | ||
expect(input.value).toBe('45856') | ||
}) | ||
test('Should change state select value', async () => { | ||
const { input } = setup('state') | ||
fireEvent.change(input, { target: { value: 'Alabama' } }) | ||
expect(input.value).toBe('AL') | ||
}) | ||
test('Should change department select value', async () => { | ||
const { input } = setup('department') | ||
fireEvent.change(input, { target: { value: 'Sales' } }) | ||
expect(input.value).toBe('Sales') | ||
}) | ||
}) |
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
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import Select from '../../React/components/Select' | ||
import { render } from '../../helpers/render' | ||
import { screen } from '@testing-library/react' | ||
|
||
const handleChange = jest.fn() | ||
const states = [ | ||
{ | ||
label: 'Alabama', | ||
value: 'AL', | ||
}, | ||
{ | ||
label: 'Alaska', | ||
value: 'AK', | ||
}, | ||
] | ||
|
||
describe('Select', () => { | ||
test('Should render input', async () => { | ||
render( | ||
<Select | ||
direction={'row'} | ||
alignItems={'left'} | ||
forAndId={'state'} | ||
value={'AL'} | ||
onChange={handleChange} | ||
required={true} | ||
optionsList={states} | ||
/> | ||
) | ||
expect(screen.getByTestId('state')).toBeTruthy() | ||
}) | ||
}) |