Skip to content

Commit

Permalink
fix: allow you to add spaces to role descriptions (#8475)
Browse files Browse the repository at this point in the history
This fixes a bug where we didn't allow spaces in role descriptions.
The bug came about because we wanted to disallow empty descriptions,
but that means we need to trim them before validating, not necessarily
before setting it.

However, that does mean that you can have descriptions with leading
and trailing spaces now, but that's probably fine.

To fix this, we'd have to do the trimming of the description only at
submission time, I think.
  • Loading branch information
thomasheartman authored Oct 18, 2024
1 parent 9f0c438 commit 88f396f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ describe('trim names and description', () => {
expect(result.current.name).toBe('my role');
});

test('description is trimmed before being set', () => {
test('description is not trimmed before being set', () => {
const { result } = renderHook(() => useRoleForm());

act(() => {
result.current.setDescription(' my description ');
});

expect(result.current.description).toBe('my description');
expect(result.current.description).toBe(' my description ');
});

test('name that is just whitespace triggers an error', () => {
Expand Down
4 changes: 1 addition & 3 deletions frontend/src/component/admin/roles/RoleForm/useRoleForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ export const useRoleForm = (
const [name, setName] = useState(initialName);
const setTrimmedName = (newName: string) => setName(newName.trim());
const [description, setDescription] = useState(initialDescription);
const setTrimmedDescription = (newDescription: string) =>
setDescription(newDescription.trim());
const [checkedPermissions, setCheckedPermissions] =
useState<ICheckedPermissions>({});
const [errors, setErrors] = useState<IRoleFormErrors>(DEFAULT_ERRORS);
Expand Down Expand Up @@ -147,7 +145,7 @@ export const useRoleForm = (
setName: setTrimmedName,
validateName,
description,
setDescription: setTrimmedDescription,
setDescription,
validateDescription,
checkedPermissions,
setCheckedPermissions,
Expand Down

0 comments on commit 88f396f

Please sign in to comment.