-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make userprofile image visible in navs (#15)
Fixes #12
- Loading branch information
1 parent
2bfad28
commit d01b645
Showing
8 changed files
with
202 additions
and
5 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,105 @@ | ||
import { rest } from 'msw'; | ||
import { | ||
screen, | ||
renderWithRouter, | ||
mockLogin, | ||
mockLogout, | ||
waitFor, | ||
within, | ||
} from '../utils/test-utils'; | ||
import App from '../../app/App'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
import { fakeUser } from '../mocks/handlers'; | ||
import server from '../mocks/server'; | ||
import { apiSlice } from '../../app/apiSlice'; | ||
import { store } from '../../app/store'; | ||
|
||
beforeAll(() => server.listen()); | ||
beforeEach(() => { | ||
const fakeTokenInfo = { | ||
username: fakeUser.username, | ||
token: 'supersecrettoken', | ||
}; | ||
mockLogin({ fakeTokenInfo }); | ||
}); | ||
afterEach(() => { | ||
mockLogout({ resetApiState: true }); | ||
server.resetHandlers(); | ||
}); | ||
afterAll(() => server.close()); | ||
|
||
test('when user has a profile image, it is displayed in mobile nav', async () => { | ||
const imageSrc = 'https://i.picsum.photos/id/237/200/300.jpg?hmac=TmmQSbShHz9CdQm0NkEjx1Dyh_Y984R9LpNrpvH2D_U'; | ||
server.use( | ||
rest.get('/api/users', (req, res, ctx) => res(ctx.status(200), ctx.json([{ | ||
...fakeUser, | ||
image: { | ||
url: imageSrc, | ||
publicId: 'fakePublicId', | ||
}, | ||
}]))), | ||
); | ||
|
||
store.dispatch(apiSlice.endpoints.getUsers.initiate()); | ||
renderWithRouter(<App />, { route: '/' }); | ||
|
||
await waitFor(() => { | ||
const avatar = screen.getByTestId('bottom-nav-avatar'); | ||
const profileImage = within(avatar).getByRole('img'); | ||
|
||
expect(profileImage).toHaveAttribute('src', imageSrc); | ||
}); | ||
}); | ||
|
||
test('when user has no profile image, a default image is displayed in mobile nav', async () => { | ||
store.dispatch(apiSlice.endpoints.getUsers.initiate()); | ||
renderWithRouter(<App />, { route: '/' }); | ||
|
||
const avatar = await screen.findByTestId('bottom-nav-avatar'); | ||
|
||
await waitFor(() => { | ||
const image = within(avatar).queryByRole('img'); | ||
const placeholderSvg = avatar.querySelector('svg'); | ||
|
||
expect(placeholderSvg).not.toBeNull(); | ||
expect(image).toBeNull(); | ||
}); | ||
}); | ||
|
||
test('when user has no profile image, a default image is displayed in desktop nav', async () => { | ||
store.dispatch(apiSlice.endpoints.getUsers.initiate()); | ||
renderWithRouter(<App />, { route: '/' }); | ||
|
||
const avatar = await screen.findByTestId('desktop-nav-avatar'); | ||
|
||
await waitFor(() => { | ||
const image = within(avatar).queryByRole('img'); | ||
const placeholderSvg = avatar.querySelector('svg'); | ||
|
||
expect(placeholderSvg).not.toBeNull(); | ||
expect(image).toBeNull(); | ||
}); | ||
}); | ||
|
||
test('when user has a profile image, it is displayed in desktop nav', async () => { | ||
const imageSrc = 'https://i.picsum.photos/id/237/200/300.jpg?hmac=TmmQSbShHz9CdQm0NkEjx1Dyh_Y984R9LpNrpvH2D_U'; | ||
server.use( | ||
rest.get('/api/users', (req, res, ctx) => res(ctx.status(200), ctx.json([{ | ||
...fakeUser, | ||
image: { | ||
url: imageSrc, | ||
publicId: 'fakePublicId', | ||
}, | ||
}]))), | ||
); | ||
|
||
store.dispatch(apiSlice.endpoints.getUsers.initiate()); | ||
renderWithRouter(<App />, { route: '/' }); | ||
|
||
await waitFor(() => { | ||
const avatar = screen.getByTestId('bottom-nav-avatar'); | ||
const profileImage = within(avatar).getByRole('img'); | ||
|
||
expect(profileImage).toHaveAttribute('src', imageSrc); | ||
}); | ||
}); |
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