Skip to content

Commit ac692d4

Browse files
committed
tests: home, docs, login, 404, support
1 parent 017bf15 commit ac692d4

File tree

5 files changed

+202
-0
lines changed

5 files changed

+202
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { cleanup, render, screen } from '@testing-library/react';
2+
import { afterEach, describe, expect, it } from 'vitest';
3+
import DocsPage from '../../../app/(protected)/docs/page';
4+
5+
describe('Docs page', () => {
6+
afterEach(() => {
7+
cleanup();
8+
});
9+
10+
it('renders the docs placeholder', () => {
11+
render(<DocsPage />);
12+
13+
expect(screen.getByText('Docs')).toBeInTheDocument();
14+
});
15+
});
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { cleanup, render, screen } from '@testing-library/react';
2+
import { afterEach, describe, expect, it, vi } from 'vitest';
3+
import HomePage from '../../../app/(protected)/home/page';
4+
5+
const deploymentMocks = vi.hoisted(() => ({
6+
apps: {
7+
groupA: {
8+
jobA: {},
9+
jobB: {},
10+
},
11+
groupB: {
12+
jobC: {},
13+
},
14+
},
15+
escrowContractAddress: '0x1234567890abcdef1234',
16+
}));
17+
18+
vi.mock('@lib/contexts/deployment', () => ({
19+
useDeploymentContext: () => ({
20+
apps: deploymentMocks.apps,
21+
escrowContractAddress: deploymentMocks.escrowContractAddress,
22+
}),
23+
}));
24+
25+
vi.mock('@lib/config', () => ({
26+
getCurrentEpoch: () => 42,
27+
getNextEpochTimestamp: () => new Date('2025-01-01T00:00:00Z'),
28+
}));
29+
30+
describe('Home page', () => {
31+
afterEach(() => {
32+
cleanup();
33+
});
34+
35+
it('renders summary cards', () => {
36+
render(<HomePage />);
37+
38+
expect(screen.getByText('Escrow SC Addr.')).toBeInTheDocument();
39+
expect(screen.getByText('Running Jobs')).toBeInTheDocument();
40+
expect(screen.getByText('Current Epoch')).toBeInTheDocument();
41+
expect(screen.getByText('42')).toBeInTheDocument();
42+
expect(screen.getByText('3')).toBeInTheDocument();
43+
expect(screen.getByText(/0x/)).toBeInTheDocument();
44+
});
45+
});
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import { cleanup, render, screen, waitFor } from '@testing-library/react';
2+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
3+
import LoginPage from '../../../app/(public)/login/page';
4+
5+
const authMocks = vi.hoisted(() => ({
6+
state: {
7+
isSignedIn: false,
8+
},
9+
}));
10+
11+
const deploymentMocks = vi.hoisted(() => ({
12+
fetchEscrowAccess: vi.fn(),
13+
isFetchAppsRequired: undefined as boolean | undefined,
14+
setEscrowContractAddress: vi.fn(),
15+
}));
16+
17+
const wagmiMocks = vi.hoisted(() => ({
18+
useAccount: vi.fn(),
19+
usePublicClient: vi.fn(),
20+
}));
21+
22+
const connectKitMocks = vi.hoisted(() => ({
23+
open: false,
24+
openSIWE: vi.fn(),
25+
}));
26+
27+
const routerMocks = vi.hoisted(() => ({
28+
replace: vi.fn(),
29+
}));
30+
31+
vi.mock('@assets/logo.svg', () => ({
32+
default: 'logo.svg',
33+
}));
34+
35+
vi.mock('@components/auth/LoginCard', () => ({
36+
default: ({ hasOracles }: { hasOracles: boolean }) => <div>LoginCard {String(hasOracles)}</div>,
37+
}));
38+
39+
vi.mock('@components/auth/RestrictedAccess', () => ({
40+
default: () => <div>RestrictedAccess</div>,
41+
}));
42+
43+
vi.mock('@lib/contexts/authentication', () => ({
44+
useAuthenticationContext: () => authMocks.state,
45+
}));
46+
47+
vi.mock('@lib/contexts/deployment', () => ({
48+
useDeploymentContext: () => ({
49+
fetchEscrowAccess: deploymentMocks.fetchEscrowAccess,
50+
isFetchAppsRequired: deploymentMocks.isFetchAppsRequired,
51+
setEscrowContractAddress: deploymentMocks.setEscrowContractAddress,
52+
}),
53+
}));
54+
55+
vi.mock('connectkit', () => ({
56+
ConnectKitButton: () => <div>ConnectKitButton</div>,
57+
useModal: () => ({
58+
open: connectKitMocks.open,
59+
openSIWE: connectKitMocks.openSIWE,
60+
}),
61+
}));
62+
63+
vi.mock('wagmi', () => ({
64+
useAccount: wagmiMocks.useAccount,
65+
usePublicClient: wagmiMocks.usePublicClient,
66+
}));
67+
68+
vi.mock('next/navigation', () => ({
69+
useRouter: () => ({
70+
replace: routerMocks.replace,
71+
}),
72+
}));
73+
74+
describe('Login page', () => {
75+
beforeEach(() => {
76+
vi.clearAllMocks();
77+
authMocks.state.isSignedIn = false;
78+
deploymentMocks.isFetchAppsRequired = undefined;
79+
wagmiMocks.useAccount.mockReturnValue({ address: undefined });
80+
wagmiMocks.usePublicClient.mockReturnValue(undefined);
81+
connectKitMocks.open = false;
82+
});
83+
84+
afterEach(() => {
85+
cleanup();
86+
});
87+
88+
it('opens the SIWE modal when signed out', async () => {
89+
render(<LoginPage />);
90+
91+
await waitFor(() => {
92+
expect(connectKitMocks.openSIWE).toHaveBeenCalled();
93+
});
94+
});
95+
96+
it('renders the login card for connected users', async () => {
97+
authMocks.state.isSignedIn = true;
98+
const readContract = vi.fn().mockResolvedValue(true);
99+
100+
wagmiMocks.useAccount.mockReturnValue({ address: '0xabc' });
101+
wagmiMocks.usePublicClient.mockReturnValue({ readContract });
102+
deploymentMocks.fetchEscrowAccess.mockResolvedValue({ escrowAddress: '0xdef' });
103+
104+
render(<LoginPage />);
105+
106+
expect(await screen.findByText('LoginCard true')).toBeInTheDocument();
107+
expect(readContract).toHaveBeenCalled();
108+
});
109+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { cleanup, render, screen } from '@testing-library/react';
2+
import { afterEach, describe, expect, it } from 'vitest';
3+
import NotFoundPage from '../../../app/(public)/404/page';
4+
5+
describe('404 page', () => {
6+
afterEach(() => {
7+
cleanup();
8+
});
9+
10+
it('renders the 404 message', () => {
11+
render(<NotFoundPage />);
12+
13+
expect(screen.getByText('404')).toBeInTheDocument();
14+
expect(
15+
screen.getByText("The page or resource you're trying to reach is invalid or it doesn't exist anymore"),
16+
).toBeInTheDocument();
17+
});
18+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { cleanup, render, screen } from '@testing-library/react';
2+
import { afterEach, describe, expect, it } from 'vitest';
3+
import SupportPage from '../../../app/(protected)/support/page';
4+
5+
describe('Support page', () => {
6+
afterEach(() => {
7+
cleanup();
8+
});
9+
10+
it('renders the support placeholder', () => {
11+
render(<SupportPage />);
12+
13+
expect(screen.getByText('Support')).toBeInTheDocument();
14+
});
15+
});

0 commit comments

Comments
 (0)