-
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.
Description is required for self-dev tag - desktop view
- Loading branch information
Hubert Legec
committed
Sep 13, 2021
1 parent
64d9d4e
commit c021309
Showing
12 changed files
with
288 additions
and
29 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
2 changes: 1 addition & 1 deletion
2
src/components/registrationPage/confirmNewTagsDialog/ConfirmNewTagsDialog.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
99 changes: 99 additions & 0 deletions
99
src/components/registrationPage/selfDevDescriptionDialog/SelfDevDescriptionDialog.spec.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,99 @@ | ||
import { render } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event' | ||
import { noop, repeat } from 'lodash'; | ||
import { SelfDevDescriptionDialog } from './SelfDevDescriptionDialog'; | ||
|
||
describe('Self-dev description dialog', () => { | ||
it('shows content if open', () => { | ||
const { getByRole, getByLabelText } = render( | ||
<SelfDevDescriptionDialog open={true} onCancel={noop} onConfirm={noop} /> | ||
); | ||
|
||
expect(getByLabelText('Self-dev description')).toBeVisible(); | ||
expect(getByRole('button', { name: 'Cancel' })).toBeVisible(); | ||
expect(getByRole('button', { name: 'Confirm' })).toBeVisible(); | ||
}) | ||
|
||
it('does not show content if closed', () => { | ||
const { queryByLabelText, queryByRole } = render( | ||
<SelfDevDescriptionDialog open={true} onCancel={noop} onConfirm={noop} /> | ||
); | ||
|
||
expect(queryByLabelText('Self-dev description')).toBeVisible(); | ||
expect(queryByRole('button', { name: 'Cancel' })).toBeVisible(); | ||
expect(queryByRole('button', { name: 'Confirm' })).toBeVisible(); | ||
}) | ||
|
||
it('returns description on confirm', () => { | ||
const onConfirm = jest.fn(); | ||
const { getByRole } = render( | ||
<SelfDevDescriptionDialog open={true} onCancel={noop} onConfirm={onConfirm}/> | ||
); | ||
|
||
userEvent.type(getByRole('textbox'), 'Some self-dev description'); | ||
userEvent.click(getByRole('button', { name: 'Confirm' })); | ||
|
||
expect(onConfirm).toHaveBeenCalledWith('Some self-dev description'); | ||
}) | ||
|
||
it('discards description on cancel', () => { | ||
const onCancel = jest.fn(); | ||
const { getByRole } = render( | ||
<SelfDevDescriptionDialog open={true} onCancel={onCancel} onConfirm={onCancel}/> | ||
); | ||
|
||
userEvent.click(getByRole('button', { name: 'Cancel' })); | ||
|
||
expect(onCancel).toHaveBeenCalled(); | ||
}) | ||
|
||
it('description cannot be empty', () => { | ||
const onConfirm = jest.fn(); | ||
const { getByRole, getByText } = render( | ||
<SelfDevDescriptionDialog open={true} onCancel={noop} onConfirm={onConfirm}/> | ||
); | ||
|
||
userEvent.click(getByRole('button', { name: 'Confirm' })); | ||
|
||
expect(getByText('Description cannot be empty')).toBeVisible(); | ||
expect(onConfirm).not.toHaveBeenCalled(); | ||
}) | ||
|
||
it('description cannot be blank', () => { | ||
const onConfirm = jest.fn(); | ||
const { getByRole, getByText } = render( | ||
<SelfDevDescriptionDialog open={true} onCancel={noop} onConfirm={onConfirm}/> | ||
); | ||
|
||
userEvent.type(getByRole('textbox'), ' '); | ||
userEvent.click(getByRole('button', { name: 'Confirm' })); | ||
|
||
expect(getByText('Description cannot be empty')).toBeVisible(); | ||
expect(onConfirm).not.toHaveBeenCalled(); | ||
}) | ||
|
||
it('description is trimmed', () => { | ||
const onConfirm = jest.fn(); | ||
const { getByRole } = render( | ||
<SelfDevDescriptionDialog open={true} onCancel={noop} onConfirm={onConfirm}/> | ||
); | ||
|
||
userEvent.type(getByRole('textbox'), ' Text with spaces '); | ||
userEvent.click(getByRole('button', { name: 'Confirm' })); | ||
|
||
expect(onConfirm).toHaveBeenCalledWith('Text with spaces'); | ||
}) | ||
|
||
it('description cannot be longer than 1000 characters', () => { | ||
const onConfirm = jest.fn(); | ||
const { getByRole, getByText } = render( | ||
<SelfDevDescriptionDialog open={true} onCancel={noop} onConfirm={onConfirm}/> | ||
); | ||
|
||
userEvent.type(getByRole('textbox'), repeat('a', 1001)); | ||
userEvent.click(getByRole('button', { name: 'Confirm' })); | ||
|
||
expect(getByText('Description cannot be longer than 1000 characters')).toBeVisible(); | ||
expect(onConfirm).not.toHaveBeenCalled(); | ||
}) | ||
}) |
73 changes: 73 additions & 0 deletions
73
src/components/registrationPage/selfDevDescriptionDialog/SelfDevDescriptionDialog.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,73 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { isEmpty, trim } from 'lodash' | ||
import Button from '@material-ui/core/Button'; | ||
import Dialog from '@material-ui/core/Dialog'; | ||
import DialogActions from '@material-ui/core/DialogActions'; | ||
import DialogContent from '@material-ui/core/DialogContent'; | ||
import DialogTitle from '@material-ui/core/DialogTitle'; | ||
import TextField from '@material-ui/core/TextField'; | ||
|
||
interface SelfDevDescriptionDialogProps { | ||
open: boolean; | ||
onCancel: () => void; | ||
onConfirm: (description: string) => void; | ||
} | ||
|
||
const validateDescription = (description: string) => { | ||
if (isEmpty(trim(description))) { | ||
return 'Description cannot be empty' | ||
} else if (description.length > 1000) { | ||
return 'Description cannot be longer than 1000 characters' | ||
} | ||
return undefined | ||
} | ||
|
||
export const SelfDevDescriptionDialog = ({open, onCancel, onConfirm}: SelfDevDescriptionDialogProps) => { | ||
const [description, setDescription] = useState('') | ||
const [error, setError] = useState(undefined); | ||
|
||
useEffect(() => { | ||
setDescription(''); | ||
setError(undefined); | ||
}, [open]); | ||
|
||
const handleConfirm = () => { | ||
const errorMessage = validateDescription(description) | ||
if (!errorMessage) { | ||
onConfirm(trim(description)) | ||
} else { | ||
setError(errorMessage) | ||
} | ||
} | ||
|
||
const handleChange = v => { | ||
setError(validateDescription(v)); | ||
setDescription(v); | ||
} | ||
|
||
return ( | ||
<Dialog open={open} onClose={onCancel}> | ||
<DialogTitle>Self-dev description</DialogTitle> | ||
<DialogContent> | ||
<p>Short description is required to report a self-dev</p> | ||
<TextField aria-label='Self-dev description' | ||
multiline | ||
type='text' | ||
value={description} | ||
onChange={e => handleChange(e.target.value)} | ||
error={!!error} | ||
size='medium' | ||
helperText={error} | ||
fullWidth /> | ||
</DialogContent> | ||
<DialogActions> | ||
<Button onClick={onCancel}> | ||
Cancel | ||
</Button> | ||
<Button onClick={handleConfirm}> | ||
Confirm | ||
</Button> | ||
</DialogActions> | ||
</Dialog> | ||
); | ||
} |
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
Oops, something went wrong.