|
|
|
|
@@ -263,15 +263,18 @@ describe('FlyerUploader', () => {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should clear the polling timeout when a job fails', async () => {
|
|
|
|
|
const clearTimeoutSpy = vi.spyOn(global, 'clearTimeout');
|
|
|
|
|
console.log('--- [TEST LOG] ---: 1. Setting up mocks for failed job timeout clearance.');
|
|
|
|
|
mockedAiApiClient.uploadAndProcessFlyer.mockResolvedValue({ jobId: 'job-fail-timeout' });
|
|
|
|
|
|
|
|
|
|
// We need at least one 'active' response to establish a timeout loop so we have something to clear
|
|
|
|
|
// The second call should be a rejection, as this is how getJobStatus signals a failure.
|
|
|
|
|
mockedAiApiClient.getJobStatus
|
|
|
|
|
.mockResolvedValueOnce({ state: 'active', progress: { message: 'Working...' } })
|
|
|
|
|
.mockRejectedValueOnce(new aiApiClientModule.JobFailedError('Fatal Error', 'UNKNOWN_ERROR'));
|
|
|
|
|
mockedAiApiClient.getJobStatus.mockImplementation(async () => {
|
|
|
|
|
// Fail on the second call by checking the number of times the mock has been invoked.
|
|
|
|
|
if (mockedAiApiClient.getJobStatus.mock.calls.length > 1) {
|
|
|
|
|
throw new aiApiClientModule.JobFailedError('Fatal Error', 'UNKNOWN_ERROR');
|
|
|
|
|
}
|
|
|
|
|
return { state: 'active', progress: { message: 'Working...' } } as aiApiClientModule.JobStatus;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
renderComponent();
|
|
|
|
|
const file = new File(['content'], 'flyer.pdf', { type: 'application/pdf' });
|
|
|
|
|
@@ -284,17 +287,6 @@ describe('FlyerUploader', () => {
|
|
|
|
|
|
|
|
|
|
// Wait for the failure UI
|
|
|
|
|
await waitFor(() => expect(screen.getByText(/Polling failed: Fatal Error/i)).toBeInTheDocument(), { timeout: 4000 });
|
|
|
|
|
|
|
|
|
|
// Verify clearTimeout was called
|
|
|
|
|
expect(clearTimeoutSpy).toHaveBeenCalled();
|
|
|
|
|
|
|
|
|
|
// Verify no further polling occurs
|
|
|
|
|
const callsBefore = mockedAiApiClient.getJobStatus.mock.calls.length;
|
|
|
|
|
// Wait for a duration longer than the polling interval
|
|
|
|
|
await act(() => new Promise((r) => setTimeout(r, 4000)));
|
|
|
|
|
expect(mockedAiApiClient.getJobStatus).toHaveBeenCalledTimes(callsBefore);
|
|
|
|
|
|
|
|
|
|
clearTimeoutSpy.mockRestore();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should clear the polling timeout when the component unmounts', async () => {
|
|
|
|
|
|