-
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.
- Loading branch information
Showing
13 changed files
with
6,762 additions
and
516 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React from 'react' | ||
import { screen, waitFor } 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', | ||
}) | ||
|
||
await waitFor(() => { | ||
expect(screen.getByText('Hello, World!')) | ||
}) | ||
}) | ||
|
||
it('shows a help message if the user can join the room', async () => { | ||
render(<RoomPage />, { | ||
path: '/room/:roomId', | ||
initialEntry: '/room/room:456-can-join', | ||
}) | ||
|
||
await waitFor(() => { | ||
expect(screen.getByText('You do not have permissions to view messages in this room')) | ||
}) | ||
}) | ||
}) |
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,23 @@ | ||
import { rest } from 'msw' | ||
import { readFileSync } from 'fs' | ||
import { resolve } from 'path' | ||
|
||
export const handlers = [ | ||
rest.get('/rooms/:roomId', (req, res, ctx) => { | ||
const roomId = req.params['roomId'] | ||
const response = loadResponse(`./rooms/get/${roomId}.json`) | ||
return res(ctx.json(response)) | ||
}), | ||
|
||
rest.get('/messages/:roomId', (req, res, ctx) => { | ||
const roomId = req.params['roomId'] | ||
const response = loadResponse(`./messages/get/${roomId}.json`) | ||
return res(ctx.json(response)) | ||
}), | ||
] | ||
|
||
const loadResponse = (relativePath: string): JSON => { | ||
const path = resolve(__dirname, relativePath) | ||
const contents = readFileSync(path, { encoding: 'utf-8' }) | ||
return JSON.parse(contents) | ||
} |
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,16 @@ | ||
[ | ||
{ | ||
"id": "message:a1b2c3", | ||
"roomId": "room:123", | ||
"content": "Hello, World!", | ||
"authorId": "system", | ||
"time": 1690030739801 | ||
}, | ||
{ | ||
"id": "message:d4e5f6", | ||
"roomId": "room:123", | ||
"content": "Test message", | ||
"authorId": "user:test-user", | ||
"time": 1690551939302 | ||
} | ||
] |
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:123", | ||
"name": "Test Room", | ||
"ownerId": "user:test-user", | ||
"contentPolicy": "private", | ||
"joinPolicy": "anyone" | ||
}, | ||
"roles": ["read", "write", "manage", "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:456", | ||
"name": "Test Room", | ||
"ownerId": "user:test-user", | ||
"contentPolicy": "private", | ||
"joinPolicy": "anyone" | ||
}, | ||
"roles": ["role"] | ||
} |
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,4 @@ | ||
import { setupServer } from 'msw/node' | ||
import { handlers } from './handlers' | ||
|
||
export const server = setupServer(...handlers) |
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,30 @@ | ||
import React from 'react' | ||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query' | ||
import { render } from '@testing-library/react' | ||
import { ReactElement } from 'react' | ||
import { RouterProvider, createMemoryRouter } from 'react-router-dom' | ||
|
||
export type RenderOptions = { | ||
path: string | ||
initialEntry: string | ||
} | ||
|
||
const customRender = (ui: ReactElement, opts: RenderOptions | undefined) => { | ||
const queryClient = new QueryClient({ | ||
defaultOptions: { | ||
queries: { | ||
retry: false, | ||
}, | ||
}, | ||
}) | ||
const router = opts | ||
? createMemoryRouter([{ path: opts.path, element: ui }], { | ||
initialEntries: [opts.initialEntry], | ||
}) | ||
: undefined | ||
render( | ||
<QueryClientProvider client={queryClient}>{router ? <RouterProvider router={router} /> : ui}</QueryClientProvider>, | ||
) | ||
} | ||
|
||
export { customRender as render } |
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,7 @@ | ||
import { server } from '../mocks/server' | ||
|
||
beforeAll(() => server.listen()) | ||
|
||
afterAll(() => server.close()) | ||
|
||
afterEach(() => server.resetHandlers()) |
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