-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #673 from codeforpdx/662/asterner-profile-tests
662/asterner profile tests
- Loading branch information
Showing
5 changed files
with
120 additions
and
34 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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React from 'react'; | ||
import { vi } from 'vitest'; | ||
import { SignedInUserContext } from '@contexts'; | ||
import * as profileHelper from '../../../src/model-helpers/Profile'; | ||
|
||
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; |
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,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 }); | ||
}); | ||
}); |