Skip to content

Commit fbf92aa

Browse files
committed
Merge remote-tracking branch 'origin/develop'
2 parents bdccccf + 07f9b96 commit fbf92aa

13 files changed

Lines changed: 149 additions & 30 deletions

File tree

apps/node-chess/src/Server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ const start = (app: App, appConfig: AppConfig): ServerType => {
2727

2828
// graceful shutdown
2929
process.on('SIGINT', () => {
30+
app.close();
3031
server.close();
31-
app.socketRouter.close();
3232
process.exit(0);
3333
});
3434
process.on('SIGTERM', () => {

apps/web-chess/src/app/features/auth/components/UsernameForm.tsx

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Button, Flex } from '@radix-ui/themes';
1+
import { Box, Button, Flex, Text } from '@radix-ui/themes';
22
import { FC } from 'react';
33
import { Alert } from '../../../components/Alert';
44
import { UsernameField } from './UsernameField';
@@ -32,17 +32,22 @@ export const UsernameForm: FC<Props> = ({
3232
>
3333
<Flex direction="column" gap="3">
3434
<Alert text={error} />
35-
36-
<UsernameField
37-
name="username"
38-
defaultValue={initialUsername}
39-
type="text"
40-
placeholder="Username"
41-
isUsernameAvailable={isUsernameAvailable}
42-
required
43-
disabled={isLoading}
44-
onChange={(e) => onUsernameChange(e.target.value)}
45-
/>
35+
<Box>
36+
<Text as="label" htmlFor="username">
37+
Username
38+
</Text>
39+
<UsernameField
40+
id="username"
41+
name="username"
42+
defaultValue={initialUsername}
43+
type="text"
44+
placeholder="Username"
45+
isUsernameAvailable={isUsernameAvailable}
46+
required
47+
disabled={isLoading}
48+
onChange={(e) => onUsernameChange(e.target.value)}
49+
/>
50+
</Box>
4651

4752
<Button
4853
mt={'1'}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import {
2+
render,
3+
screen,
4+
} from '../../../../../test/utils/custom-testing-library';
5+
import { UsernameFormContainer } from '../UsernameFormContainer';
6+
7+
describe('UsernameFormContainer', () => {
8+
it('should render correctly with default value', async () => {
9+
render(<UsernameFormContainer />);
10+
11+
const usernameInput = await screen.findByLabelText('Username');
12+
expect(usernameInput).toBeEnabled();
13+
expect(usernameInput).toHaveValue('');
14+
await screen.findByDisplayValue('testuser');
15+
const submitButton = screen.getByRole('button', { name: /submit/i });
16+
expect(submitButton).toBeEnabled();
17+
});
18+
});

apps/web-chess/src/app/features/lobby/__tests__/GameLobby.spec.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import {
88
import { GameLobby } from '../GameLobby';
99

1010
describe('GameLobby', () => {
11-
it('should render the game lobby header', () => {
12-
const { getByText } = render(<GameLobby />);
11+
it('should render the game lobby header', async () => {
12+
const { getByText, findByText } = render(<GameLobby />);
1313

14-
expect(getByText('Lobby')).toBeTruthy();
14+
expect(await findByText('Lobby')).toBeTruthy();
1515
expect(getByText('+ Create Game')).toBeTruthy();
1616
});
1717

@@ -33,10 +33,9 @@ describe('GameLobby', () => {
3333
data: gameDetailsMockV1,
3434
});
3535

36-
const { getByText } = render(<GameLobby onCreateGame={onCreateGame} />);
36+
const { findByRole } = render(<GameLobby onCreateGame={onCreateGame} />);
3737

38-
const createButton = getByText('+ Create Game');
39-
expect(createButton).toBeTruthy();
38+
const createButton = await findByRole('button', { name: '+ Create Game' });
4039

4140
await user.click(createButton);
4241

apps/web-chess/src/app/pages/WelcomePage.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Maybe } from '@michess/common-utils';
2-
import { Card, Flex, Text } from '@radix-ui/themes';
2+
import { Card, Flex } from '@radix-ui/themes';
33
import { FC } from 'react';
44
import { useAuth } from '../api/hooks/useAuth';
55
import { Link } from '../components/Link';
@@ -25,9 +25,6 @@ export const WelcomePage: FC<Props> = ({ type }) => {
2525
/>
2626
{type === 'social' && (
2727
<Flex direction="column" gap="2">
28-
<Text as={'label'} color="gray">
29-
Change username
30-
</Text>
3128
<UsernameFormContainer />
3229
</Flex>
3330
)}

apps/web-chess/src/test/mocks/node-chess.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export const mswHandlers = [
1414
image: null,
1515
id: 'test-user-id',
1616
name: 'Test User',
17+
username: 'testuser',
1718
email: 'test@example.com',
1819
},
1920
session: {

apps/web-chess/src/test/utils/custom-testing-library.tsx

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import { Theme } from '@radix-ui/themes';
22
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
3+
import {
4+
createRootRoute,
5+
createRoute,
6+
createRouter,
7+
Outlet,
8+
RouterProvider,
9+
} from '@tanstack/react-router';
310
import { render, RenderOptions } from '@testing-library/react';
4-
import React, { ReactElement } from 'react';
11+
import { ReactElement } from 'react';
512
import { Api } from '../../app/api/Api';
613
import { ApiContext } from '../../app/api/context/ApiContext';
714
import { AuthClient } from '../../app/api/infra/AuthClient';
@@ -22,11 +29,13 @@ const api = Api.create(
2229
socketClient,
2330
);
2431

25-
const AllTheProviders = ({ children }: { children: React.ReactNode }) => {
32+
const AllTheProviders = () => {
2633
return (
2734
<QueryClientProvider client={queryClient}>
2835
<ApiContext.Provider value={api}>
29-
<Theme>{children}</Theme>
36+
<Theme>
37+
<Outlet />
38+
</Theme>
3039
</ApiContext.Provider>
3140
</QueryClientProvider>
3241
);
@@ -35,7 +44,29 @@ const AllTheProviders = ({ children }: { children: React.ReactNode }) => {
3544
const customRender = (
3645
ui: ReactElement,
3746
options?: Omit<RenderOptions, 'wrapper'>,
38-
) => render(ui, { wrapper: AllTheProviders, ...options });
47+
) => {
48+
const rootRoute = createRootRoute({
49+
component: AllTheProviders,
50+
});
51+
52+
const indexRoute = createRoute({
53+
getParentRoute: () => rootRoute,
54+
path: '/',
55+
56+
component: () => {
57+
return ui;
58+
},
59+
});
60+
61+
const routerTree = rootRoute.addChildren([indexRoute]);
62+
const router = createRouter({
63+
routeTree: routerTree,
64+
defaultPendingMinMs: 0,
65+
defaultPendingMs: 0,
66+
});
67+
68+
return render(<RouterProvider router={router} />, { ...options });
69+
};
3970

4071
export * from '@testing-library/react';
4172
export { api, queryClient, customRender as render, socketClient };

apps/web-chess/src/test/utils/setup-tests.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import '@testing-library/jest-dom/vitest';
12
import { fetch } from 'cross-fetch';
23
import { server } from '../mocks/node-chess';
34
global.fetch = fetch;

apps/web-chess/tsconfig.spec.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"vitest/globals",
77
"vitest/importMeta",
88
"vite/client",
9+
"@testing-library/jest-dom/vitest",
910
"node",
1011
"vitest",
1112
"@nx/react/typings/cssmodule.d.ts",

libs/api-router/src/lib/App.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export type App = {
1111
restRouter: Hono<any>;
1212
socketRouter: Server;
1313
init: () => Promise<void>;
14+
close: () => Promise<void>;
1415
};
1516

1617
const from = (
@@ -24,8 +25,14 @@ const from = (
2425
restRouter,
2526
socketRouter,
2627
init: async () => {
28+
await api.games.initialize();
2729
await api.usageMetrics.initialize();
2830
},
31+
close: async () => {
32+
socketRouter.close();
33+
await api.games.close();
34+
await api.usageMetrics.close();
35+
},
2936
};
3037
};
3138
export const App = {

0 commit comments

Comments
 (0)