Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HAI-1866 Add length limit for hanke name #389

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/common/components/textInput/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { getInputErrorText } from '../../utils/form';
type PropTypes = {
name: string;
label?: string;
maxLength?: number | undefined;
disabled?: boolean;
required?: boolean;
readOnly?: boolean;
Expand All @@ -23,6 +24,7 @@ type PropTypes = {
const TextInput: React.FC<React.PropsWithChildren<PropTypes>> = ({
name,
label,
maxLength = undefined,
disabled,
tooltip,
required,
Expand All @@ -48,6 +50,7 @@ const TextInput: React.FC<React.PropsWithChildren<PropTypes>> = ({
className={className}
label={label || t(`hankeForm:labels:${name}`)}
value={value || ''}
maxLength={maxLength}
helperText={helperText}
placeholder={placeholder}
errorText={getInputErrorText(t, error)}
Expand Down
17 changes: 17 additions & 0 deletions src/domain/hanke/edit/HankeForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,23 @@ describe('HankeForm', () => {
expect(screen.getByTestId(FORMFIELD.KUVAUS)).toHaveValue(hankkeenKuvaus);
});

test('Hanke nimi should be limited to 100 characters and not exceed the limit with additional characters', async () => {
const { user } = render(<HankeFormContainer />);
const initialName = 'b'.repeat(90);

fireEvent.change(screen.getByRole('textbox', { name: /hankkeen nimi/i }), {
target: { value: initialName },
});

await user.type(
screen.getByRole('textbox', { name: /hankkeen nimi/i }),
'additional_characters',
);

const result = screen.getByRole('textbox', { name: /hankkeen nimi/i });
expect(result).toHaveValue(initialName.concat('additional'));
});

test('Yhteystiedot can be filled', async () => {
const { user } = await setupYhteystiedotPage(<HankeFormContainer hankeTunnus="HAI22-1" />);

Expand Down
2 changes: 1 addition & 1 deletion src/domain/hanke/edit/HankeFormPerustiedot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const HankeFormPerustiedot: React.FC<React.PropsWithChildren<FormProps>> = ({
<p>{t('form:requiredInstruction')}</p>
</Box>
<div className="formWpr">
<TextInput name={FORMFIELD.NIMI} required />
<TextInput name={FORMFIELD.NIMI} maxLength={100} required />
</div>
<div className="formWpr">
<TextArea
Expand Down
Loading