Merges Renovate's kit 3 (PR #149) and adapter-static 4 (PR #148) bumps, plus the migration they need. The mechanical part is `sv migrate sveltekit-3`, run one task at a time and reviewed: - svelte.config.js is gone. Its options move into sveltekit() in vite.config.ts, exported as kitOptions so vitest.config.ts runs the same kit setup, including the $test-utils alias the tests import. - $lib becomes #lib through package.json "imports". There is no src/lib/index, so only the "#lib/*" entry is kept. - tsconfig extends $app/tsconfig. - Peer floors raised to kit 3's requirements: svelte ^5.57.1, vite ^8.0.12, svelte-check ^4.7.5. By hand, from the codemod's list of non-automated tasks: - goto's replaceState option is now replace; keepFocus becomes reset: false. For the search typeahead, reset: false also stops the scroll-to-top, which is wanted while typing. - The test setup mocks drop pushState/replaceState and $app/paths base/assets, which kit 3 removed, and mock refreshAll in place of invalidateAll. - The other flagged files only read page.url or goto internal routes, so they needed no change. TypeScript goes to ^6, not the ^7 Renovate offers: kit 3 declares typescript ^6 as a peer and svelte-check 4.7 accepts ^5 || ^6. Move to 7 once both accept it. With Tailwind 4 and kit 3 in, `npm audit` on the whole tree reports 0, so the web lane now audits every dependency rather than only what ships to browsers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
110 lines
4.1 KiB
TypeScript
110 lines
4.1 KiB
TypeScript
import { describe, expect, test, vi, beforeEach } from 'vitest';
|
|
import { render, screen, fireEvent, waitFor } from '@testing-library/svelte';
|
|
import NetworkSettingsCard from './NetworkSettingsCard.svelte';
|
|
|
|
const getNetworkSettings = vi.fn();
|
|
const updateNetworkSettings = vi.fn();
|
|
|
|
vi.mock('#lib/api/admin.js', () => ({
|
|
getNetworkSettings: () => getNetworkSettings(),
|
|
updateNetworkSettings: (hops: number) => updateNetworkSettings(hops)
|
|
}));
|
|
|
|
vi.mock('#lib/stores/toast.svelte.js', () => ({ pushToast: vi.fn() }));
|
|
|
|
function settings(over: Record<string, unknown> = {}) {
|
|
return {
|
|
trusted_proxy_hops: 1,
|
|
max_hops: 10,
|
|
detected_client_ip: '198.51.100.7',
|
|
forwarded_chain: '198.51.100.7',
|
|
remote_addr: '172.18.0.1:40000',
|
|
...over
|
|
};
|
|
}
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
describe('NetworkSettingsCard', () => {
|
|
// The detected address is the card's verification affordance — the number
|
|
// is abstract, this is checkable against the machine you're sitting at.
|
|
test('shows the address the current setting resolves to', async () => {
|
|
getNetworkSettings.mockResolvedValue(settings());
|
|
render(NetworkSettingsCard);
|
|
|
|
// The address legitimately appears twice — as the detected client and
|
|
// inside the forwarded chain — so wait on the unique label, not the value.
|
|
await screen.findByText('Your address right now');
|
|
expect(screen.getAllByText('198.51.100.7').length).toBeGreaterThan(0);
|
|
expect(screen.getByText('172.18.0.1:40000')).toBeTruthy();
|
|
});
|
|
|
|
test('save is inert until the value actually changes', async () => {
|
|
getNetworkSettings.mockResolvedValue(settings({ trusted_proxy_hops: 1 }));
|
|
render(NetworkSettingsCard);
|
|
|
|
const save = await screen.findByRole('button', { name: /Save/ });
|
|
expect(save).toBeDisabled();
|
|
|
|
const input = screen.getByRole('spinbutton');
|
|
await fireEvent.input(input, { target: { value: '2' } });
|
|
await waitFor(() => expect(save).not.toBeDisabled());
|
|
});
|
|
|
|
test('saving sends the new depth and adopts the echoed value', async () => {
|
|
getNetworkSettings.mockResolvedValue(settings({ trusted_proxy_hops: 1 }));
|
|
updateNetworkSettings.mockResolvedValue(
|
|
settings({ trusted_proxy_hops: 2, detected_client_ip: '203.0.113.9' })
|
|
);
|
|
render(NetworkSettingsCard);
|
|
|
|
const input = await screen.findByRole('spinbutton');
|
|
await fireEvent.input(input, { target: { value: '2' } });
|
|
await fireEvent.click(screen.getByRole('button', { name: /Save/ }));
|
|
|
|
await waitFor(() => expect(updateNetworkSettings).toHaveBeenCalledWith(2));
|
|
// The recomputed address proves the change took effect on this request.
|
|
expect(await screen.findByText('203.0.113.9')).toBeTruthy();
|
|
});
|
|
|
|
// Counting proxies is the operator's job and the hint is how they do it
|
|
// without guessing.
|
|
test('hints the likely depth when it disagrees with the arriving chain', async () => {
|
|
getNetworkSettings.mockResolvedValue(
|
|
settings({ trusted_proxy_hops: 1, forwarded_chain: '198.51.100.7, 203.0.113.50' })
|
|
);
|
|
render(NetworkSettingsCard);
|
|
|
|
expect(await screen.findByText(/arrived with 2 forwarded addresses/)).toBeTruthy();
|
|
});
|
|
|
|
test('no hint when the setting already matches the chain length', async () => {
|
|
getNetworkSettings.mockResolvedValue(
|
|
settings({ trusted_proxy_hops: 1, forwarded_chain: '198.51.100.7' })
|
|
);
|
|
render(NetworkSettingsCard);
|
|
|
|
await screen.findByText('Your address right now');
|
|
expect(screen.queryByText(/arrived with/)).toBeNull();
|
|
});
|
|
|
|
test('states the mis-set risk rather than only exposing a number', async () => {
|
|
getNetworkSettings.mockResolvedValue(settings());
|
|
render(NetworkSettingsCard);
|
|
|
|
expect(await screen.findByText(/Count your proxies/)).toBeTruthy();
|
|
});
|
|
|
|
test('offers a retry when loading fails', async () => {
|
|
getNetworkSettings.mockRejectedValue(new Error('boom'));
|
|
render(NetworkSettingsCard);
|
|
|
|
const retry = await screen.findByRole('button', { name: 'Try again' });
|
|
getNetworkSettings.mockResolvedValue(settings());
|
|
await fireEvent.click(retry);
|
|
await screen.findByText('Your address right now');
|
|
});
|
|
});
|