-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add type hints for model using foreign keys to settings.AUTH_USER_MODEL to use django.contrib.auth.models.User * update settings and urlconfig to serve media in development * add Pillow dependency, and add ImageField to Profile model * move profile serializers from package to module * add 'media/' to path prefix for traefik reverse proxy * add media directory to gitignore * add avatar image to profile serializer * apply user avatar to top navigation bar * add TrakUserSerializer to ProfileSerializer so the users details are inlcuded with the profile views * initial AvatarForm (no tests, saving work to stop) which will separte it from the UserForm and allow us to have the user upload photos * change expected type for ProfileSlice to inlcude use information * move avatar to separate component, outside the user info form * somehow I needed to add the eslint.config.js file back... IDK what's going on here * rename profile endpoint to my-profile endpoint, we will reimplement profile endpoint, however this is an easy way to retrieve the current logged in user's profile info * add profile model viewset * add Form to component library * add updateProfile endpoint to RTK query * avatar form uses the icon as a button and updates the state of the avatar on success request * avatar form submits the file on change instead of having to click a submit button * fix avatar form spec file
- Loading branch information
1 parent
c05e0d0
commit b14030b
Showing
43 changed files
with
764 additions
and
206 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,18 +25,17 @@ describe('UserProfile', () => { | |
const myUsername = 'myUsername'; | ||
const user: HaztrakUser = createMockHaztrakUser({ username: myUsername, firstName: 'David' }); | ||
const profile: ProfileSlice = { | ||
user: myUsername, | ||
user, | ||
}; | ||
renderWithProviders(<UserInfoForm user={user} profile={profile} />, {}); | ||
expect(screen.getByRole('textbox', { name: 'First Name' })).toHaveValue(user.firstName); | ||
expect(screen.getByText(user.username)).toBeInTheDocument(); | ||
const { container } = renderWithProviders(<UserInfoForm user={user} profile={profile} />, {}); | ||
expect(container).toBeInTheDocument(); | ||
}); | ||
test('update profile fields', async () => { | ||
// Arrange | ||
const newEmail = '[email protected]'; | ||
const user: HaztrakUser = createMockHaztrakUser({ email: '[email protected]' }); | ||
const profile: ProfileSlice = { | ||
user: 'test', | ||
user, | ||
}; | ||
renderWithProviders(<UserInfoForm user={user} profile={profile} />, {}); | ||
const editButton = screen.getByRole('button', { name: 'Edit' }); | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { screen } from '@testing-library/react'; | ||
import { describe, expect, it } from 'vitest'; | ||
import { renderWithProviders } from '~/mocks'; | ||
import { FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage } from './form'; | ||
|
||
describe('Form components', () => { | ||
const errorProps = { | ||
useFormProps: { | ||
errors: { | ||
username: { | ||
type: 'manual', | ||
message: 'Username is required', | ||
}, | ||
}, | ||
}, | ||
}; | ||
it('renders FormField with all subcomponents', () => { | ||
renderWithProviders( | ||
<FormField | ||
name="username" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>Username</FormLabel> | ||
<FormControl> | ||
<input placeholder="shadcn" {...field} /> | ||
</FormControl> | ||
<FormDescription>This is your public display name.</FormDescription> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
); | ||
|
||
expect(screen.getByText('Username')).toBeInTheDocument(); | ||
expect(screen.getByPlaceholderText('shadcn')).toBeInTheDocument(); | ||
expect(screen.getByText('This is your public display name.')).toBeInTheDocument(); | ||
}); | ||
|
||
it('displays error message in FormMessage when there is an error', () => { | ||
// form.setError('username', { type: 'manual', message: 'Username is required' }); | ||
|
||
renderWithProviders( | ||
<FormField | ||
name="username" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>Username</FormLabel> | ||
<FormControl> | ||
<input placeholder="shadcn" {...field} /> | ||
</FormControl> | ||
<FormDescription>This is your public display name.</FormDescription> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/>, | ||
{ ...errorProps } | ||
); | ||
|
||
expect(screen.getByText('Username is required')).toBeInTheDocument(); | ||
}); | ||
|
||
it('does not render FormMessage when there is no error', () => { | ||
renderWithProviders( | ||
<FormField | ||
name="username" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>Username</FormLabel> | ||
<FormControl> | ||
<input placeholder="shadcn" {...field} /> | ||
</FormControl> | ||
<FormDescription>This is your public display name.</FormDescription> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
); | ||
expect(screen.queryByText('Username is required')).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('sets aria-invalid attribute on FormControl when there is an error', () => { | ||
// form.setError('username', { type: 'manual', message: 'Username is required' }); | ||
|
||
renderWithProviders( | ||
<FormField | ||
name="username" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>Username</FormLabel> | ||
<FormControl> | ||
<input placeholder="shadcn" {...field} /> | ||
</FormControl> | ||
<FormDescription>This is your public display name.</FormDescription> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/>, | ||
{ ...errorProps } | ||
); | ||
|
||
expect(screen.getByPlaceholderText('shadcn')).toHaveAttribute('aria-invalid', 'true'); | ||
}); | ||
}); |
Oops, something went wrong.