-
Notifications
You must be signed in to change notification settings - Fork 6
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
Showing
11 changed files
with
299 additions
and
7 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,16 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import Icon from './Icon'; | ||
|
||
const user = userEvent.setup(); | ||
|
||
describe('Testing Icon Component', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('Should render icon', async () => { | ||
render(<Icon name="info" role="img" />); | ||
expect(screen.getByRole('img')); | ||
}); | ||
}); |
52 changes: 52 additions & 0 deletions
52
web-app/client/src/components/Inputs/MultiSelect/MultiSelect.test.tsx
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,52 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import MultiSelect from './MultiSelect'; | ||
import { countries } from 'countries-list'; | ||
|
||
const user = userEvent.setup(); | ||
|
||
describe('Testing multi select dropdown', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
const countryNames = Object.entries(countries).map( | ||
([, country]) => country, | ||
); | ||
|
||
test('Should open dropdown, select first and second option, close by click outside', async () => { | ||
render( | ||
<> | ||
<MultiSelect | ||
label="Country" | ||
placeholder="Germany" | ||
options={countryNames.map(({ emoji, native, name }) => ({ | ||
label: `${emoji} ${native}`, | ||
value: name, | ||
}))} | ||
/> | ||
<div>Outside</div> | ||
</>, | ||
); | ||
const trigger = screen.getByText('Germany'); | ||
await user.click(trigger); | ||
const andorra = () => screen.getByText('🇦🇩 Andorra'); | ||
const anguilla = () => screen.getByText('🇦🇮 Anguilla'); | ||
const antiguaQuery = () => screen.queryByText('🇦🇬 Antigua and Barbuda'); | ||
const anguillaQuery = () => screen.queryByText('🇦🇮 Anguilla'); | ||
expect(andorra() && anguilla()); | ||
expect(antiguaQuery()).not.toBeNull(); | ||
|
||
await user.click(andorra()); | ||
expect(andorra()); | ||
expect(anguillaQuery()).toBeNull(); | ||
|
||
await user.click(andorra()); | ||
await user.click(anguilla()); | ||
expect(anguillaQuery()).not.toBeNull(); | ||
expect(antiguaQuery()).toBeNull(); | ||
|
||
await user.click(screen.getByText('Outside')); | ||
expect(antiguaQuery()).toBeNull(); | ||
}); | ||
}); |
46 changes: 46 additions & 0 deletions
46
web-app/client/src/components/Inputs/Select/Select.test.tsx
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,46 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import Select from './Select'; | ||
import { countries } from 'countries-list'; | ||
|
||
const user = userEvent.setup(); | ||
|
||
describe('Testing select dropdown', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
const countryNames = Object.entries(countries).map(([, country]) => country); | ||
|
||
test('Should open dropdown, select option, close by click outside', async () => { | ||
render( | ||
<> | ||
<Select | ||
label="Country" | ||
placeholder="Germany" | ||
options={countryNames.map(({ emoji, native, name }) => ({ | ||
label: `${emoji} ${native}`, | ||
value: name, | ||
}))} | ||
/> | ||
<div>Outside</div> | ||
</>, | ||
); | ||
const trigger = screen.getByText('Germany'); | ||
await user.click(trigger); | ||
const andorra = () => screen.getByText('🇦🇩 Andorra'); | ||
const anguilla = screen.getByText('🇦🇮 Anguilla'); | ||
const anguillaQuery = () => screen.queryByText('🇦🇮 Anguilla'); | ||
expect(andorra()); | ||
expect(anguilla); | ||
|
||
await user.click(andorra()); | ||
expect(andorra()); | ||
expect(anguillaQuery()).toBeNull(); | ||
|
||
await user.click(andorra()); | ||
expect(anguillaQuery()).not.toBeNull(); | ||
await user.click(screen.getByText('Outside')); | ||
expect(anguillaQuery()).toBeNull(); | ||
}); | ||
}); |
64 changes: 64 additions & 0 deletions
64
web-app/client/src/components/LogInModal/steps/Password.test.tsx
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,64 @@ | ||
import { fireEvent, render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
import { TestPassword } from './TestPassword'; | ||
|
||
const user = userEvent.setup(); | ||
|
||
describe('Testing variants for password', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
const prepare = () => { | ||
render(<TestPassword />); | ||
const input = screen.getByPlaceholderText('admin1234'); | ||
const trigger = screen.getByRole('submit'); | ||
const errorQuery = () => | ||
screen.queryByText('The password does not match the pattern (see tooltip)'); | ||
return { input, trigger, errorQuery }; | ||
}; | ||
|
||
test('Too shot password', async () => { | ||
const { input, trigger, errorQuery } = prepare(); | ||
fireEvent.change(input, { target: { value: 'Aa23.0' } }); | ||
await user.click(trigger); | ||
expect(errorQuery()).not.toBeNull(); | ||
}); | ||
|
||
test('Password without digit', async () => { | ||
const { input, trigger, errorQuery } = prepare(); | ||
fireEvent.change(input, { target: { value: 'Aaaaaa.a' } }); | ||
await user.click(trigger); | ||
expect(errorQuery()).not.toBeNull(); | ||
}); | ||
|
||
test('Password without special symbol', async () => { | ||
const { input, trigger, errorQuery } = prepare(); | ||
fireEvent.change(input, { target: { value: 'Aaaa2312' } }); | ||
await user.click(trigger); | ||
expect(errorQuery()).not.toBeNull(); | ||
}); | ||
|
||
test('Password without uppercase letter', async () => { | ||
const { input, trigger, errorQuery } = prepare(); | ||
fireEvent.change(input, { target: { value: 'aaaa23.0' } }); | ||
await user.click(trigger); | ||
expect(errorQuery()).not.toBeNull(); | ||
}); | ||
|
||
test('Password without lowercase letter', async () => { | ||
const { input, trigger, errorQuery } = prepare(); | ||
fireEvent.change(input, { target: { value: 'AAAA23.0' } }); | ||
await user.click(trigger); | ||
expect(errorQuery()).not.toBeNull(); | ||
}); | ||
|
||
test('Good password', async () => { | ||
const { input, trigger, errorQuery } = prepare(); | ||
fireEvent.change(input, { target: { value: 'Aaaa23.0' } }); | ||
await user.click(trigger); | ||
expect(errorQuery()).toBeNull(); | ||
}); | ||
}); | ||
|
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
59 changes: 59 additions & 0 deletions
59
web-app/client/src/components/LogInModal/steps/TestPassword.tsx
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,59 @@ | ||
import { FC } from 'react'; | ||
import { useForm } from 'react-hook-form'; | ||
import isStrongPassword from 'validator/lib/isStrongPassword'; | ||
import Button from '@components/Button'; | ||
import { Text } from '@components/Inputs'; | ||
import { passwordTooltip } from '@components/SignUpModal/steps/CoreInfo'; | ||
import styles from '../LogInModal.module.scss'; | ||
|
||
type Inputs = { | ||
password: string; | ||
}; | ||
|
||
const defaultValues: Inputs = { | ||
password: '', | ||
}; | ||
|
||
export const TestPassword: FC = () => { | ||
|
||
const { | ||
register, | ||
handleSubmit, | ||
formState: { errors, isSubmitting }, | ||
} = useForm<Inputs>({ | ||
defaultValues, | ||
}); | ||
|
||
const onSubmit = handleSubmit(async (values) => { | ||
console.log('submit') | ||
}); | ||
|
||
return ( | ||
<> | ||
<h4 className={styles.title}>Recovery</h4> | ||
<form onSubmit={onSubmit} className={styles.formContainer}> | ||
<div className={styles.inputGroup}> | ||
<Text | ||
label="Password" | ||
type="password" | ||
placeholder="admin1234" | ||
tooltip={passwordTooltip} | ||
{...register('password', { | ||
required: 'Required', | ||
validate: (value) => | ||
isStrongPassword(value) || | ||
'The password does not match the pattern (see tooltip)', | ||
})} | ||
error={errors.password?.message} | ||
/> | ||
</div> | ||
|
||
<div className={styles.buttons}> | ||
<Button variant="primary" type="submit" disabled={isSubmitting} role='submit'> | ||
Update Password | ||
</Button> | ||
</div> | ||
</form> | ||
</> | ||
); | ||
}; |
30 changes: 30 additions & 0 deletions
30
web-app/client/src/components/ModalContainer/ModalContainer.test.tsx
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,30 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { TestModal } from './TestModal'; | ||
|
||
const user = userEvent.setup(); | ||
|
||
describe('Testing Modal Container as Test Modal window', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
|
||
test('Should open, close by button and click outside', async () => { | ||
render(<TestModal />); | ||
|
||
const triggerOpen = screen.getByText('Test Button'); | ||
await user.click(triggerOpen); | ||
expect(screen.getByText('Test Modal')); | ||
|
||
const triggerClose = screen.getByRole('close'); | ||
await user.click(triggerClose); | ||
expect(screen.queryByText('Test Modal')).toBeNull(); | ||
|
||
await user.click(triggerOpen); | ||
await user.click(screen.getByText('Outside')); | ||
expect(screen.queryByText('Test Modal')).toBeNull(); | ||
}); | ||
|
||
|
||
}); |
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
22 changes: 22 additions & 0 deletions
22
web-app/client/src/components/ModalContainer/TestModal.tsx
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,22 @@ | ||
import Button from '@components/Button'; | ||
import { FC, useState } from 'react'; | ||
import ModalContainer from './ModalContainer'; | ||
|
||
export const TestModal: FC = () => { | ||
const [isOpen, setIsOpen] = useState(false); | ||
const onClose = () => { | ||
setIsOpen(!isOpen); | ||
}; | ||
|
||
return ( | ||
<> | ||
<div>Outside</div> | ||
<Button variant="secondary" size="sm" onClick={() => setIsOpen(true)}> | ||
Test Button | ||
</Button> | ||
<ModalContainer isOpen={isOpen} onClose={onClose}> | ||
Test Modal | ||
</ModalContainer> | ||
</> | ||
); | ||
}; |
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