-
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.
* move rcraprofile to core app * filter RcraSitePermissions by user * HaztrakUserView and HaztrakUserSerializer * add HaztrakUser interface to UserState * add selectUserState selector * add asyncThunk for HaztrakUser and dispatch in app root * user profile form * add placeholder input for user avatar * test suite for user profile
- Loading branch information
1 parent
00af8d6
commit 3898050
Showing
47 changed files
with
687 additions
and
377 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
name: ':bug: Bug Report' | ||
name: '🐞 Bug Report' | ||
about: 'Report an issue.' | ||
title: '' | ||
labels: 'bug' | ||
|
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
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
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { cleanup } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { UserProfile } from 'features/profile/UserProfile'; | ||
import { rest } from 'msw'; | ||
import { setupServer } from 'msw/node'; | ||
import React from 'react'; | ||
import { HaztrakUser } from 'store/userSlice/user.slice'; | ||
import { renderWithProviders, screen } from 'test-utils'; | ||
import { API_BASE_URL } from 'test-utils/mock/handlers'; | ||
import { vi } from 'vitest'; | ||
|
||
const DEFAULT_USER: HaztrakUser = { | ||
username: 'test', | ||
firstName: 'David', | ||
lastName: 'smith', | ||
email: '[email protected]', | ||
}; | ||
|
||
const server = setupServer( | ||
rest.put(`${API_BASE_URL}/api/user/`, (req, res, ctx) => { | ||
const user: HaztrakUser = { ...DEFAULT_USER }; | ||
// @ts-ignore | ||
return res(ctx.status(200), ctx.json({ ...user, ...req.body })); | ||
}) | ||
); | ||
|
||
// pre-/post-test hooks | ||
beforeAll(() => server.listen()); | ||
afterEach(() => { | ||
server.resetHandlers(); | ||
cleanup(); | ||
vi.resetAllMocks(); | ||
}); | ||
afterAll(() => server.close()); // Disable API mocking after the tests are done. | ||
|
||
describe('UserProfile', () => { | ||
test('renders', () => { | ||
const user: HaztrakUser = { | ||
...DEFAULT_USER, | ||
username: 'test', | ||
firstName: 'David', | ||
}; | ||
renderWithProviders(<UserProfile user={user} />, {}); | ||
expect(screen.getByRole('textbox', { name: 'First Name' })).toHaveValue(user.firstName); | ||
expect(screen.getByText(user.username)).toBeInTheDocument(); | ||
}); | ||
test('update profile fields', async () => { | ||
// Arrange | ||
const newEmail = '[email protected]'; | ||
const user: HaztrakUser = { | ||
...DEFAULT_USER, | ||
}; | ||
renderWithProviders(<UserProfile user={user} />, {}); | ||
const editButton = screen.getByRole('button', { name: 'Edit' }); | ||
const emailTextBox = screen.getByRole('textbox', { name: 'Email' }); | ||
// Act | ||
await userEvent.click(editButton); | ||
await userEvent.clear(emailTextBox); | ||
await userEvent.type(emailTextBox, newEmail); | ||
const saveButton = screen.getByRole('button', { name: 'Save' }); | ||
await userEvent.click(saveButton); | ||
// Assert | ||
expect(await screen.findByRole('textbox', { name: 'Email' })).toHaveValue(newEmail); | ||
}); | ||
}); |
Oops, something went wrong.