-
-
Notifications
You must be signed in to change notification settings - Fork 729
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: trim name and description before validation (#8275)
This fixes a bug where you can input just whitespace for name/description. It also means that you can no longer have both "my role" and "my role " as separate roles. API fix will follow.
- Loading branch information
1 parent
eb01b44
commit e20ef56
Showing
3 changed files
with
62 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
50 changes: 50 additions & 0 deletions
50
frontend/src/component/admin/roles/RoleForm/useRoleForm.test.ts
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,50 @@ | ||
import { renderHook } from '@testing-library/react'; | ||
import { useRoleForm } from './useRoleForm'; | ||
import { act } from 'react-test-renderer'; | ||
import { test } from 'vitest'; | ||
|
||
describe('trim names and description', () => { | ||
test('name is trimmed before being set', () => { | ||
const { result } = renderHook(() => useRoleForm()); | ||
|
||
act(() => { | ||
result.current.setName(' my role '); | ||
}); | ||
|
||
expect(result.current.name).toBe('my role'); | ||
}); | ||
|
||
test('description is trimmed before being set', () => { | ||
const { result } = renderHook(() => useRoleForm()); | ||
|
||
act(() => { | ||
result.current.setDescription(' my description '); | ||
}); | ||
|
||
expect(result.current.description).toBe('my description'); | ||
}); | ||
|
||
test('name that is just whitespace triggers an error', () => { | ||
const { result } = renderHook(() => useRoleForm()); | ||
|
||
act(() => { | ||
result.current.validateName(' '); | ||
}); | ||
|
||
expect(result.current.errors).toMatchObject({ | ||
name: 'Name is required.', | ||
}); | ||
}); | ||
|
||
test('description that is just whitespace triggers an error', () => { | ||
const { result } = renderHook(() => useRoleForm()); | ||
|
||
act(() => { | ||
result.current.validateDescription(' '); | ||
}); | ||
|
||
expect(result.current.errors).toMatchObject({ | ||
description: 'Description is required.', | ||
}); | ||
}); | ||
}); |
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