-
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.
Merge pull request #166 from jbrunton/improve-client-tests
test: improve client test coverage
- Loading branch information
Showing
24 changed files
with
130 additions
and
37 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions
6
.../features/room/molecules/AuthorAvatar.tsx → ...features/room/molecules/author-avatar.tsx
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
File renamed without changes.
File renamed without changes.
37 changes: 37 additions & 0 deletions
37
client/src/features/room/molecules/formatted-message.spec.tsx
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,37 @@ | ||
import React from 'react' | ||
import { render, screen } from '@testing-library/react' | ||
import { FormattedMessage } from './formatted-message' | ||
import '@testing-library/jest-dom' | ||
|
||
describe('FormattedMessage', () => { | ||
it('renders the content', () => { | ||
render(<FormattedMessage content='Hello, World!' />) | ||
expect(screen.getByText('Hello, World!')) | ||
}) | ||
|
||
it('renders content as markdown', () => { | ||
const content = '# Action Items\n* Item 1\n* Item 2' | ||
|
||
render(<FormattedMessage content={content} />) | ||
|
||
expect(screen.getByRole('heading')).toHaveTextContent('Action Items') | ||
expect(screen.getAllByRole('list')).toMatchInlineSnapshot(` | ||
[ | ||
<ul> | ||
<li> | ||
Item 1 | ||
</li> | ||
<li> | ||
Item 2 | ||
</li> | ||
</ul>, | ||
] | ||
`) | ||
}) | ||
}) |
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
File renamed without changes.
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 |
---|---|---|
@@ -1,28 +1,67 @@ | ||
import React from 'react' | ||
import { screen, waitFor } from '@testing-library/react' | ||
import { screen, waitFor, within } from '@testing-library/react' | ||
import { RoomPage } from './Room' | ||
import { render } from '../../../test/fixtures' | ||
|
||
describe('RoomPage', () => { | ||
it('loads messages for the room', async () => { | ||
render(<RoomPage />, { | ||
path: '/room/:roomId', | ||
initialEntry: '/room/room:123-can-manage', | ||
initialEntry: '/room/room:100-can-manage', | ||
}) | ||
|
||
await waitFor(() => { | ||
expect(screen.getByText('Hello, World!')) | ||
}) | ||
}) | ||
|
||
it('shows a help message if the user can join the room', async () => { | ||
it('shows a message if the user lacks permissions to read the room', async () => { | ||
render(<RoomPage />, { | ||
path: '/room/:roomId', | ||
initialEntry: '/room/room:456-can-join', | ||
initialEntry: '/room/room:200-can-join', | ||
}) | ||
|
||
await waitFor(() => { | ||
expect(screen.getByText('You do not have permissions to view messages in this room')) | ||
}) | ||
}) | ||
|
||
it('shows an alert if the user can join the room', async () => { | ||
render(<RoomPage />, { | ||
path: '/room/:roomId', | ||
initialEntry: '/room/room:200-can-join', | ||
}) | ||
|
||
await waitFor(() => { | ||
const alert = screen.getByRole('alert') | ||
expect(alert).toHaveTextContent('Join this room to chat.') | ||
expect(within(alert).getByRole('button')).toHaveTextContent('Join') | ||
}) | ||
}) | ||
|
||
it('shows an alert if the user can request to join', async () => { | ||
render(<RoomPage />, { | ||
path: '/room/:roomId', | ||
initialEntry: '/room/room:300-can-request-approval', | ||
}) | ||
|
||
await waitFor(() => { | ||
const alert = screen.getByRole('alert') | ||
expect(alert).toHaveTextContent('Join this room to chat.') | ||
expect(within(alert).getByRole('button')).toHaveTextContent('Request to Join') | ||
}) | ||
}) | ||
|
||
it('shows an alert if the user requires an invite to join', async () => { | ||
render(<RoomPage />, { | ||
path: '/room/:roomId', | ||
initialEntry: '/room/room:400-requires-invite', | ||
}) | ||
|
||
await waitFor(() => { | ||
const alert = screen.getByRole('alert') | ||
expect(alert).toHaveTextContent('You need an invite to join.') | ||
expect(within(alert).queryByRole('button')).not.toBeInTheDocument() | ||
}) | ||
}) | ||
}) |
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
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
.../mocks/rooms/get/room:123-can-manage.json → .../mocks/rooms/get/room:100-can-manage.json
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
4 changes: 2 additions & 2 deletions
4
...rc/mocks/rooms/get/room:456-can-join.json → ...rc/mocks/rooms/get/room:200-can-join.json
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,10 +1,10 @@ | ||
{ | ||
"room": { | ||
"id": "room:456", | ||
"id": "room:200", | ||
"name": "Test Room", | ||
"ownerId": "user:test-user", | ||
"contentPolicy": "private", | ||
"joinPolicy": "anyone" | ||
}, | ||
"roles": ["role"] | ||
"roles": ["join"] | ||
} |
10 changes: 10 additions & 0 deletions
10
client/src/mocks/rooms/get/room:300-can-request-approval.json
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,10 @@ | ||
{ | ||
"room": { | ||
"id": "room:300", | ||
"name": "Test Room", | ||
"ownerId": "user:test-user", | ||
"contentPolicy": "private", | ||
"joinPolicy": "request" | ||
}, | ||
"roles": ["join"] | ||
} |
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,10 @@ | ||
{ | ||
"room": { | ||
"id": "room:300", | ||
"name": "Test Room", | ||
"ownerId": "user:test-user", | ||
"contentPolicy": "private", | ||
"joinPolicy": "invite" | ||
}, | ||
"roles": [] | ||
} |
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 @@ | ||
import '@testing-library/jest-dom/vitest' |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.