Public source validation / validate (push) Failing after 3m8s
31 lines
1.3 KiB
TypeScript
31 lines
1.3 KiB
TypeScript
import { render, screen } from '@testing-library/react';
|
|
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
|
|
import App from '../../src/App';
|
|
|
|
afterEach(() => {
|
|
vi.unstubAllGlobals();
|
|
window.history.replaceState({}, '', '/');
|
|
});
|
|
|
|
describe('dashboard request caching', () => {
|
|
it('does not reuse dashboard responses across authentication or onboarding changes', async () => {
|
|
window.history.replaceState({}, '', '/dashboards');
|
|
const requests: Array<{ url: string; init?: RequestInit }> = [];
|
|
vi.stubGlobal('fetch', vi.fn(async (input: RequestInfo | URL, init?: RequestInit) => {
|
|
const url = String(input);
|
|
requests.push({ url, init });
|
|
if (url.startsWith('/api/v1/dashboards')) {
|
|
return new Response(JSON.stringify({ items: [] }), { status: 200, headers: { 'Content-Type': 'application/json' } });
|
|
}
|
|
return new Response(JSON.stringify({ error: 'not configured' }), { status: 503, headers: { 'Content-Type': 'application/json' } });
|
|
}));
|
|
|
|
render(<App />);
|
|
|
|
expect(await screen.findByRole('heading', { level: 1, name: 'Jouw dashboards' })).toBeVisible();
|
|
const dashboardRequest = requests.find((request) => request.url.startsWith('/api/v1/dashboards'));
|
|
expect(dashboardRequest?.init?.cache).toBe('no-store');
|
|
});
|
|
});
|