feat(email): confirm hub thread unlink

This commit is contained in:
cesnimda
2026-08-10 09:40:59 +02:00
parent 73ee095795
commit 1dabbeb233
3 changed files with 88 additions and 1 deletions
@@ -1,6 +1,6 @@
import React from 'react';
import '@testing-library/jest-dom';
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
import { fireEvent, render, screen, waitFor, within } from '@testing-library/react';
import { MemoryRouter, Navigate, Route, Routes } from 'react-router-dom';
import { ToastProvider } from './toast';
import { ConfirmProvider } from './confirm';
@@ -120,6 +120,27 @@ describe('CorrespondenceInboxPage', () => {
});
});
test('unlinks a Gmail thread only after confirmation and returns it to review', async () => {
mockedApi.post.mockResolvedValue({ data: { threadId: 'thread-1', jobApplicationId: 42, removedMessages: 1, decision: 'review' } } as any);
renderPage();
fireEvent.click(await screen.findByRole('button', { name: /^unlink thread$/i }));
expect(mockedApi.post).not.toHaveBeenCalled();
const dialog = await screen.findByRole('dialog');
expect(within(dialog).getByText(/provider copy is not deleted/i)).toBeInTheDocument();
fireEvent.click(within(dialog).getByRole('button', { name: /^unlink thread$/i }));
await waitFor(() => expect(mockedApi.post).toHaveBeenCalledWith('/gmail/unlink-thread', {
jobApplicationId: 42,
threadId: 'thread-1',
note: 'Unlinked from Job email hub',
nextDecision: 'review',
}));
await waitFor(() => expect(mockedApi.get).toHaveBeenCalledWith('/correspondence', expect.anything()));
expect(await screen.findByText(/returned to recruitment review/i)).toBeInTheDocument();
});
test('falls back to the saved copy when provider detail is unavailable', async () => {
const original = mockedApi.get.getMockImplementation();
mockedApi.get.mockImplementation((url: string, config?: any) => {