Skip to content

Commit f65f126

Browse files
committed
test(matrix-to): add RTL integration tests for config→matrix-to wiring
1 parent 55fd9bb commit f65f126

1 file changed

Lines changed: 99 additions & 0 deletions

File tree

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/**
2+
* Integration tests: exercises the full config-load → setMatrixToBase → URL
3+
* generation pipeline that App.tsx runs on startup.
4+
*
5+
* The pattern under test mirrors App.tsx:
6+
* <ClientConfigLoader>
7+
* {(config) => { setMatrixToBase(config.matrixToBaseUrl); ... }}
8+
* </ClientConfigLoader>
9+
*
10+
* We mock fetch so we don't need a real config.json or a live matrix.to instance.
11+
*/
12+
import { describe, it, expect, vi, afterEach } from 'vitest';
13+
import { render, screen, waitFor } from '@testing-library/react';
14+
import { setMatrixToBase, getMatrixToRoom, getMatrixToUser } from '$plugins/matrix-to';
15+
import { ClientConfigLoader } from './ClientConfigLoader';
16+
17+
afterEach(() => {
18+
setMatrixToBase(); // reset module state to 'https://matrix.to'
19+
vi.unstubAllGlobals();
20+
});
21+
22+
const mockFetch = (config: object) =>
23+
vi.stubGlobal('fetch', vi.fn().mockResolvedValue({ json: () => Promise.resolve(config) }));
24+
25+
describe('ClientConfigLoader + matrix-to wiring', () => {
26+
it('generates a standard matrix.to URL when no custom base is configured', async () => {
27+
mockFetch({});
28+
29+
render(
30+
<ClientConfigLoader>
31+
{(config) => {
32+
setMatrixToBase(config.matrixToBaseUrl);
33+
return <span data-testid="link">{getMatrixToRoom('!room:example.com')}</span>;
34+
}}
35+
</ClientConfigLoader>
36+
);
37+
38+
await waitFor(() =>
39+
expect(screen.getByTestId('link')).toHaveTextContent('https://matrix.to/#/!room:example.com')
40+
);
41+
});
42+
43+
it('generates a custom-base URL for rooms when matrixToBaseUrl is set', async () => {
44+
mockFetch({ matrixToBaseUrl: 'https://custom.example.org' });
45+
46+
render(
47+
<ClientConfigLoader>
48+
{(config) => {
49+
setMatrixToBase(config.matrixToBaseUrl);
50+
return <span data-testid="link">{getMatrixToRoom('!room:example.com')}</span>;
51+
}}
52+
</ClientConfigLoader>
53+
);
54+
55+
await waitFor(() =>
56+
expect(screen.getByTestId('link')).toHaveTextContent(
57+
'https://custom.example.org/#/!room:example.com'
58+
)
59+
);
60+
});
61+
62+
it('generates a custom-base URL for users when matrixToBaseUrl is set', async () => {
63+
mockFetch({ matrixToBaseUrl: 'https://custom.example.org' });
64+
65+
render(
66+
<ClientConfigLoader>
67+
{(config) => {
68+
setMatrixToBase(config.matrixToBaseUrl);
69+
return <span data-testid="user">{getMatrixToUser('@alice:example.com')}</span>;
70+
}}
71+
</ClientConfigLoader>
72+
);
73+
74+
await waitFor(() =>
75+
expect(screen.getByTestId('user')).toHaveTextContent(
76+
'https://custom.example.org/#/@alice:example.com'
77+
)
78+
);
79+
});
80+
81+
it('strips a trailing slash from matrixToBaseUrl', async () => {
82+
mockFetch({ matrixToBaseUrl: 'https://custom.example.org/' });
83+
84+
render(
85+
<ClientConfigLoader>
86+
{(config) => {
87+
setMatrixToBase(config.matrixToBaseUrl);
88+
return <span data-testid="link">{getMatrixToRoom('!room:example.com')}</span>;
89+
}}
90+
</ClientConfigLoader>
91+
);
92+
93+
await waitFor(() =>
94+
expect(screen.getByTestId('link')).toHaveTextContent(
95+
'https://custom.example.org/#/!room:example.com'
96+
)
97+
);
98+
});
99+
});

0 commit comments

Comments
 (0)