mirror of
https://github.com/bulwarkmail/webmail.git
synced 2026-11-02 00:14:23 +00:00
fix: list the folders in the import dialog when it opens from Settings
This commit is contained in:
@@ -71,6 +71,17 @@ describe('MailImportDialog', () => {
|
||||
expect(startImport).toHaveBeenCalledWith(expect.objectContaining({ accountId: 'acc1', targetMailboxId: null, keepFolders: true }));
|
||||
});
|
||||
|
||||
it('loads the folders when opened from Settings before the mail view did, then picks the Inbox', async () => {
|
||||
const fetchMailboxes = vi.fn(async () => {});
|
||||
const loaded = useEmailStore.getState().mailboxes;
|
||||
useEmailStore.setState({ mailboxes: [], fetchMailboxes } as never);
|
||||
render(<MailTransferHost />);
|
||||
act(() => openMailImport());
|
||||
expect(fetchMailboxes).toHaveBeenCalled();
|
||||
act(() => useEmailStore.setState({ mailboxes: loaded } as never));
|
||||
await waitFor(() => expect((screen.getByTestId('mail-import-target') as HTMLSelectElement).value).toBe('inbox'));
|
||||
});
|
||||
|
||||
it('cannot start without files', () => {
|
||||
render(<MailTransferHost />);
|
||||
act(() => openMailImport());
|
||||
|
||||
@@ -72,6 +72,17 @@ export function MailImportDialog({ request }: { request: ImportRequest }) {
|
||||
const targetId = target === TOP ? null : targetMailbox ? targetMailbox.originalId || targetMailbox.id : null;
|
||||
const effectiveKeep = anyFolders && keepFolders;
|
||||
|
||||
// Opened from Settings, the mail view may not have loaded the folders yet.
|
||||
useEffect(() => {
|
||||
if (client && mailboxes.length === 0) void useEmailStore.getState().fetchMailboxes(client).catch(() => {});
|
||||
}, [client, mailboxes.length]);
|
||||
|
||||
// Keep the choice valid when the folders arrive or the files change.
|
||||
useEffect(() => {
|
||||
const valid = target === TOP ? anyFolders : targets.some((x) => x.mailbox.id === target);
|
||||
if (!valid && target !== initialTarget) setTarget(initialTarget);
|
||||
}, [targets, target, anyFolders, initialTarget]);
|
||||
|
||||
// An earlier import of the same file into the same place that stopped part way.
|
||||
useEffect(() => {
|
||||
let current = true;
|
||||
|
||||
Reference in New Issue
Block a user