-
Notifications
You must be signed in to change notification settings - Fork 27
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
662/asterner profile tests #673
Changes from all commits
807a51a
cd77d37
d319b8f
0033d80
dce4146
a8fea76
dc17215
01f2c44
503ccd9
1f8628a
b146047
a7b7984
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React from 'react'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see we're making mock contexts for the tests. I'm fine with this since it'll be useful in case multiple tests need the same context. |
||
import { vi } from 'vitest'; | ||
import { SignedInUserContext } from '@contexts'; | ||
import * as profileHelper from '../../../src/model-helpers/Profile'; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we're going to keep this, we can leave a TODO note here to import it elsewhere. I'm pretty sure there are other tests that can make use of this but not as part of this PR There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What would you like to add as a TODO? I don't see the SignedInUserContext used in other tests (other than the tests for the context itself). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll put a pin in that idea. I want to think it over more |
||
const profileInfo = { | ||
profileName: null, | ||
nickname: null, | ||
profileImg: null | ||
}; | ||
|
||
const mockSignedInUserContextMemo = { | ||
updateProfileInfo: vi.fn(), | ||
setProfileData: vi.fn(), | ||
profileData: profileInfo, | ||
fetchProfileInfo: vi.spyOn(profileHelper, 'fetchProfileInfo').mockResolvedValue({ | ||
profileData: profileInfo | ||
}) | ||
}; | ||
|
||
/** | ||
* @param {object} props - The properties of the component | ||
* @param {React.JSX.Element} [props.children] - The child elements to be rendered inside the main content area | ||
* @returns {React.JSX.Element} SignedInUserContext - an element which allows querying profile info | ||
*/ | ||
const MockSignedInUserContext = ({ children }) => ( | ||
<SignedInUserContext.Provider value={mockSignedInUserContextMemo}> | ||
{children} | ||
</SignedInUserContext.Provider> | ||
); | ||
|
||
export default MockSignedInUserContext; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import React from 'react'; | ||
import { BrowserRouter } from 'react-router-dom'; | ||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; | ||
import { act } from 'react-dom/test-utils'; | ||
import { render, screen, cleanup, waitForElementToBeRemoved } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { describe, expect, it, beforeEach, afterEach } from 'vitest'; | ||
import { Profile } from '@pages'; | ||
import MockSignedInUserContext from '../mocks/contexts/MockSignedInUserContext'; | ||
|
||
const queryClient = new QueryClient(); | ||
|
||
const renderProfile = () => | ||
render( | ||
<QueryClientProvider client={queryClient}> | ||
<MockSignedInUserContext> | ||
<BrowserRouter> | ||
<Profile /> | ||
</BrowserRouter> | ||
</MockSignedInUserContext> | ||
</QueryClientProvider> | ||
); | ||
|
||
describe('Profile Page', () => { | ||
afterEach(() => { | ||
cleanup(); | ||
}); | ||
|
||
beforeEach(() => { | ||
act(() => { | ||
renderProfile(); | ||
}); | ||
}); | ||
|
||
it('renders', async () => { | ||
const heading = await screen.findByRole('heading', { name: 'My Profile' }, { timeout: 2000 }); | ||
expect(heading).toHaveAccessibleName('My Profile'); | ||
}); | ||
|
||
it('can show and hide the share documents modal', async () => { | ||
const user = userEvent.setup(); | ||
|
||
const shareDocumentsButton = await screen.findByRole( | ||
'button', | ||
{ name: 'Share Documents' }, | ||
{ timeout: 2000 } | ||
); | ||
expect(shareDocumentsButton).toHaveAccessibleName('Share Documents'); | ||
|
||
// Open share document modal | ||
user.click(shareDocumentsButton); | ||
const shareHeading = await screen.findByRole('heading', { name: 'Share All Documents' }); | ||
expect(shareHeading).toBeVisible(); | ||
|
||
// Close share document modal | ||
user.keyboard('{escape}'); | ||
await waitForElementToBeRemoved(shareHeading, { timeout: 5000 }); | ||
}); | ||
|
||
it('can show and hide the add document modal', async () => { | ||
const user = userEvent.setup(); | ||
|
||
const addDocumentButton = await screen.findByRole( | ||
'button', | ||
{ name: 'Add Document' }, | ||
{ timeout: 2000 } | ||
); | ||
expect(addDocumentButton).toHaveAccessibleName('Add Document'); | ||
|
||
// Open add document modal | ||
user.click(addDocumentButton); | ||
const addHeading = await screen.findByRole('heading', { name: 'Upload Document' }); | ||
|
||
// close add document modal | ||
user.keyboard('{escape}'); | ||
await waitForElementToBeRemoved(addHeading, { timeout: 5000 }); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change makes this text into a proper heading without modifying the visual rendering
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking over it, I'm not certain whether we need it to say "My Profile" at the top at all. The breadcrumb basically covers the same role already and we don't really apply this same concept to other pages (such as the Contacts page). But that's a different discussion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. I attempted to make minimal changes to the page itself. This seems like something we can take a look at post MVP.