feat: poll in-flight requests on native + refresh after submit (#369)
Native RequestsViewModel gains poll-while-approved (silent reloads, paused when nothing in-flight) for parity with the web auto-poll, and the SSE collector now reloads silently instead of flashing the loading spinner. Web discover submit invalidates qk.myRequests() so a new request appears on /requests immediately.
This commit is contained in:
@@ -31,6 +31,15 @@ vi.mock('$lib/api/requests', () => ({
|
||||
|
||||
vi.mock('$lib/api/client', () => apiClientMock());
|
||||
|
||||
// The page calls useQueryClient() to invalidate qk.myRequests() after a
|
||||
// submit (#369); stub it so rendering doesn't require a real QueryClient and
|
||||
// we can assert the invalidation fires.
|
||||
const queryClientMock = vi.hoisted(() => ({ invalidateQueries: vi.fn() }));
|
||||
vi.mock('@tanstack/svelte-query', async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import('@tanstack/svelte-query')>();
|
||||
return { ...actual, useQueryClient: () => queryClientMock };
|
||||
});
|
||||
|
||||
import DiscoverPage from './+page.svelte';
|
||||
import { createLidarrSearchQuery } from '$lib/api/lidarr';
|
||||
import { createSuggestionsQuery } from '$lib/api/suggestions';
|
||||
@@ -187,6 +196,27 @@ describe('Discover page', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('submitting a request invalidates myRequests so /requests updates (#369)', async () => {
|
||||
vi.useFakeTimers();
|
||||
const r = result({ mbid: 'art-mbid', artist_mbid: 'art-mbid', name: 'Boards of Canada' });
|
||||
mockedCreateQuery.mockReturnValue(mockQuery<LidarrSearchResult[]>({ data: [r] }));
|
||||
render(DiscoverPage);
|
||||
const input = screen.getByLabelText(/search lidarr/i);
|
||||
await fireEvent.input(input, { target: { value: 'boards' } });
|
||||
await vi.advanceTimersByTimeAsync(250);
|
||||
vi.useRealTimers();
|
||||
|
||||
const requestBtn = await screen.findByRole('button', {
|
||||
name: /request boards of canada/i
|
||||
});
|
||||
await fireEvent.click(requestBtn);
|
||||
await waitFor(() => {
|
||||
expect(queryClientMock.invalidateQueries).toHaveBeenCalledWith({
|
||||
queryKey: ['myRequests']
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('track-kind Request click opens confirm modal; Confirm calls createRequest', async () => {
|
||||
vi.useFakeTimers();
|
||||
const r = result({
|
||||
|
||||
Reference in New Issue
Block a user