@octarq/plugin-mail 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,116 @@
1
+ import { Code, Field, Input, Textarea, Guide, Modal, Switch, timeAgo, ScreenWrap, PageHeader, GlassCard, Badge, Button, Select, Alert, confirmDialog, FormError, useTranslation, roleSatisfies, useCurrentRole } from "@octarq/plugin-sdk";
2
+ import { useEffect, useState } from "react";
3
+ import { useSearchParams } from "react-router-dom";
4
+ import { mailApi, Attachment, Email, Mailbox } from "../api";
5
+ import { Inbox, Send, Plus, CheckCircle, Mail as MailIcon, Paperclip, Settings, Trash2, Reply, Download, X, AlertTriangle } from "lucide-react";
6
+ import { MailSettings } from "./MailSettings";
7
+ import { SMTPSenders } from "./SMTPSenders";
8
+
9
+ export function MailboxEditor({
10
+ box,
11
+ hosts,
12
+ onClose,
13
+ onSaved,
14
+ }: {
15
+ box: Mailbox | null;
16
+ hosts: string[];
17
+ onClose: () => void;
18
+ onSaved: () => void;
19
+ }) {
20
+ const { t } = useTranslation();
21
+ const { role, isInstanceAdmin } = useCurrentRole();
22
+ const canDeleteBox = roleSatisfies("admin", role, isInstanceAdmin);
23
+ const [prefix, setPrefix] = useState("");
24
+ const [domain, setDomain] = useState(hosts[0] ?? "");
25
+ const [note, setNote] = useState(box?.note ?? "");
26
+ const [enabled, setEnabled] = useState(box?.enabled ?? true);
27
+ const [err, setErr] = useState<string | { message?: string; status?: number; requestId?: string }>("");
28
+
29
+ useEffect(() => {
30
+ if (hosts.length > 0 && !domain) setDomain(hosts[0]);
31
+ }, [hosts]);
32
+
33
+ async function save() {
34
+ setErr("");
35
+ try {
36
+ if (box) {
37
+ await mailApi.updateMailbox(box.id, { note, enabled });
38
+ } else {
39
+ if (!prefix.trim() || !domain) return setErr(t("mail.prefixDomainRequired"));
40
+ await mailApi.createMailbox({ address: `${prefix.trim()}@${domain}`, note, enabled });
41
+ }
42
+ onSaved();
43
+ } catch (e: any) {
44
+ setErr(e);
45
+ }
46
+ }
47
+
48
+ return (
49
+ <Modal title={box ? t("mail.editMailbox") : t("mail.createMailbox")} onClose={onClose}>
50
+ <div className="space-y-4">
51
+ {box ? (
52
+ <Field label={t("mail.mailboxAddress")}>
53
+ <Input className="font-mono text-sm" value={box.address} disabled />
54
+ </Field>
55
+ ) : hosts.length === 0 ? (
56
+ <Alert variant="warning" className="p-3 text-xs flex items-center gap-1.5 font-normal">
57
+ <AlertTriangle className="h-4 w-4" />
58
+ {t("mail.noHosts")}
59
+ </Alert>
60
+ ) : (
61
+ <Field label={t("mail.mailboxPrefix")} hint={t("mail.prefixHint")}>
62
+ <div className="flex items-center gap-2">
63
+ <Input
64
+ className="font-mono text-sm"
65
+ value={prefix}
66
+ onChange={(e) => setPrefix(e.target.value)}
67
+ placeholder={t("mail.prefixPlaceholder")}
68
+ autoFocus
69
+ />
70
+ <span className="text-muted-foreground">@</span>
71
+ <div className="min-w-0 flex-1">
72
+ <Select
73
+ className="text-sm"
74
+ value={domain}
75
+ onValueChange={setDomain}
76
+ options={hosts.map((h) => ({ value: h, label: h }))}
77
+ />
78
+ </div>
79
+ </div>
80
+ </Field>
81
+ )}
82
+ <Field label={t("mail.noteMemo")}>
83
+ <Textarea className="text-sm" rows={2} value={note} onChange={(e) => setNote(e.target.value)} placeholder={t("mail.noteMemoPlaceholder")} />
84
+ </Field>
85
+ <div className="flex items-center gap-3 py-1">
86
+ <Switch checked={enabled} onCheckedChange={setEnabled} aria-label={t("mail.mailReceivingEnabled")} />
87
+ <span className="text-sm text-muted-foreground select-none">{t("mail.mailReceivingEnabled")}</span>
88
+ </div>
89
+ {canDeleteBox && box && (
90
+ <Button
91
+ variant="danger"
92
+ onClick={async () => {
93
+ if (await confirmDialog(t("mail.deleteMailboxConfirm", { address: box.address }))) {
94
+ await mailApi.deleteMailbox(box.id);
95
+ onSaved();
96
+ }
97
+ }}
98
+ className="text-xs py-1.5 border-0 mt-2"
99
+ >
100
+ {t("mail.deleteMailboxCompletely")}
101
+ </Button>
102
+ )}
103
+ {err && <FormError err={err} />}
104
+ <div className="flex justify-end gap-2.5 pt-4 border-t border-border">
105
+ <Button variant="ghost" onClick={onClose}>
106
+ {t("mail.cancel")}
107
+ </Button>
108
+ <Button variant="primary" onClick={save}>
109
+ {t("mail.saveConfiguration")}
110
+ </Button>
111
+ </div>
112
+ </div>
113
+ </Modal>
114
+ );
115
+ }
116
+
@@ -0,0 +1,280 @@
1
+ import { Empty, Field, Input, Modal, Badge, Button, Panel, toast, confirmDialog, FormError, useTranslation, roleSatisfies, useCurrentRole } from "@octarq/plugin-sdk";
2
+ import { useEffect, useState } from "react";
3
+ import { NavLink } from "react-router-dom";
4
+ import { mailApi, SMTPSender } from "../api";
5
+ import { KeyRound, Send, Blocks } from "lucide-react";
6
+
7
+ // Which registry owns the sender rows. An instance with the Integrations Hub
8
+ // mounted uses hub credentials; a standalone Core instance has no hub and uses
9
+ // the local mail_smtp_senders table. The two registries number rows
10
+ // independently, so a page must read exactly one of them.
11
+ type SenderMode = "integration" | "local" | null;
12
+
13
+ export function SMTPSenders() {
14
+ const { t } = useTranslation();
15
+ const { role, isInstanceAdmin } = useCurrentRole();
16
+ const canManageSMTP = roleSatisfies("admin", role, isInstanceAdmin);
17
+ const [mode, setMode] = useState<SenderMode>(null);
18
+ const [senders, setSenders] = useState<any[]>([]);
19
+ const [loading, setLoading] = useState(true);
20
+ const [creating, setCreating] = useState(false);
21
+ const [editing, setEditing] = useState<any | null>(null);
22
+ const [testingId, setTestingId] = useState<number | null>(null);
23
+
24
+ async function load() {
25
+ setLoading(true);
26
+ try {
27
+ const res = await fetch("/api/integrations?provider_type=communication", {
28
+ credentials: "same-origin",
29
+ });
30
+ if (res.status === 404) {
31
+ setMode("local");
32
+ setSenders(await mailApi.smtpSenders());
33
+ return;
34
+ }
35
+ if (!res.ok) {
36
+ setMode(null);
37
+ setSenders([]);
38
+ return;
39
+ }
40
+ const data = await res.json();
41
+ setMode("integration");
42
+ setSenders(
43
+ (Array.isArray(data) ? data : []).filter(
44
+ (item: any) => item.provider === "smtp" || item.provider === "resend"
45
+ )
46
+ );
47
+ } catch {
48
+ setMode(null);
49
+ setSenders([]);
50
+ } finally {
51
+ setLoading(false);
52
+ }
53
+ }
54
+ useEffect(() => { load(); }, []);
55
+
56
+ async function remove(id: number) {
57
+ if (!(await confirmDialog(t("settings.confirmRemoveSmtp")))) return;
58
+ try {
59
+ await mailApi.deleteSMTPSender(id);
60
+ load();
61
+ } catch (e: any) {
62
+ toast.error(e.message || t("settings.failedRemove"));
63
+ }
64
+ }
65
+
66
+ async function test(sender: any) {
67
+ setTestingId(sender.id);
68
+ try {
69
+ if (mode === "local") {
70
+ await mailApi.testSMTPSender(sender.id);
71
+ toast.success(t("settings.smtpTestSent", { to: sender.fromEmail }));
72
+ } else {
73
+ const res = await fetch(`/api/integrations/${sender.id}/test`, {
74
+ method: "POST",
75
+ credentials: "same-origin",
76
+ });
77
+ const data = await res.json().catch(() => ({}));
78
+ if (!res.ok || data.ok === false) {
79
+ throw new Error(data.detail || data.message || "Connection test failed");
80
+ }
81
+ toast.success(data.message || t("settings.smtpTestSent", { to: sender.name }));
82
+ }
83
+ } catch (e: any) {
84
+ toast.error(t("settings.testFailed", { msg: e?.message || "unknown error" }));
85
+ } finally {
86
+ setTestingId(null);
87
+ }
88
+ }
89
+
90
+ return (
91
+ <Panel
92
+ title={t("settings.smtpOutgoingGateways")}
93
+ description={t("settings.smtpOutgoingGatewaysDesc")}
94
+ action={
95
+ canManageSMTP && mode === "local" ? (
96
+ <Button variant="primary" className="text-xs py-1 px-2.5" onClick={() => setCreating(true)}>
97
+ {t("settings.addSmtp")}
98
+ </Button>
99
+ ) : canManageSMTP && mode === "integration" ? (
100
+ <NavLink to="/settings/integrations?category=communication">
101
+ <Button variant="primary" className="text-xs py-1 px-2.5">
102
+ {t("settings.openIntegrationsHub")}
103
+ </Button>
104
+ </NavLink>
105
+ ) : null
106
+ }
107
+ >
108
+
109
+ {mode === "integration" && (
110
+ <div className="flex items-center justify-between p-3 rounded-lg border border-primary/20 bg-accent-soft text-xs text-foreground">
111
+ <div className="flex items-center gap-2">
112
+ <Blocks className="h-4 w-4 text-accent-fg shrink-0" />
113
+ <span>{t("settings.integrationsHubBanner")}</span>
114
+ </div>
115
+ <NavLink
116
+ to="/settings/integrations?category=communication"
117
+ className="ml-3 inline-flex min-h-8 items-center whitespace-nowrap text-xs font-medium text-accent-fg hover:underline"
118
+ >
119
+ {t("settings.openIntegrationsHub")} →
120
+ </NavLink>
121
+ </div>
122
+ )}
123
+
124
+ {loading ? (
125
+ <div className="text-muted-foreground text-sm py-6 text-center">{t("settings.loadingLower")}</div>
126
+ ) : senders.length === 0 ? (
127
+ // The heading carries the add/open control, so the empty state states
128
+ // the fact and adds no second button.
129
+ <Empty reason={t("settings.noSmtpSenders")}>
130
+ <Send />
131
+ </Empty>
132
+ ) : (
133
+ <div className="divide-y divide-border border border-border rounded-xl bg-well overflow-hidden">
134
+ {senders.map(s => (
135
+ <div key={s.id} className="flex items-center justify-between p-4 group">
136
+ <div>
137
+ <div className="font-semibold text-sm text-foreground flex items-center gap-1.5">
138
+ {s.name}
139
+ {mode === "integration" ? (
140
+ <>
141
+ <Badge tone={s.provider === "resend" ? "indigo" : "cyan"} className="uppercase tracking-wider text-[10px]">
142
+ {s.provider}
143
+ </Badge>
144
+ {s.configured ?? true
145
+ ? <Badge tone="green" className="text-[10px]"><KeyRound className="h-2.5 w-2.5 mr-0.5 inline" />{t("settings.smtpPasswordSet")}</Badge>
146
+ : <Badge tone="amber" className="text-[10px]">{t("settings.smtpNoPassword")}</Badge>}
147
+ </>
148
+ ) : (
149
+ s.passSet
150
+ ? <Badge tone="green" className="text-[10px]"><KeyRound className="h-2.5 w-2.5 mr-0.5 inline" />{t("settings.smtpPasswordSet")}</Badge>
151
+ : <Badge tone="amber" className="text-[10px]">{t("settings.smtpNoPassword")}</Badge>
152
+ )}
153
+ </div>
154
+ <div className="text-xs text-muted-foreground mt-1 font-mono">
155
+ {mode === "integration"
156
+ ? (s.summary || `${s.fromEmail} via ${s.host}:${s.port || 587}`)
157
+ : `${s.fromEmail} via ${s.host}:${s.port}`}
158
+ </div>
159
+ </div>
160
+ {canManageSMTP && (
161
+ <div className="flex items-center gap-2">
162
+ <Button
163
+ variant="subtle"
164
+ onClick={() => test(s)}
165
+ disabled={testingId === s.id}
166
+ className="text-xs py-1 px-2.5"
167
+ >
168
+ {testingId === s.id ? t("settings.testing") : t("settings.test")}
169
+ </Button>
170
+ {mode === "integration" ? (
171
+ <NavLink to="/settings/integrations?category=communication">
172
+ <Button variant="subtle" className="text-xs py-1 px-2.5">
173
+ {t("settings.openIntegrationsHub")}
174
+ </Button>
175
+ </NavLink>
176
+ ) : (
177
+ <>
178
+ <Button variant="subtle" onClick={() => setEditing(s)} className="text-xs py-1 px-2.5">
179
+ {t("settings.editSmtp")}
180
+ </Button>
181
+ <Button
182
+ variant="danger"
183
+ onClick={() => remove(s.id)}
184
+ className="text-xs py-1 px-2.5 border-0"
185
+ >
186
+ {t("settings.remove")}
187
+ </Button>
188
+ </>
189
+ )}
190
+ </div>
191
+ )}
192
+ </div>
193
+ ))}
194
+ </div>
195
+ )}
196
+ {(creating || editing) && (
197
+ <SMTPSenderModal
198
+ sender={editing}
199
+ onClose={() => { setCreating(false); setEditing(null); }}
200
+ onSaved={() => { setCreating(false); setEditing(null); load(); }}
201
+ />
202
+ )}
203
+ </Panel>
204
+ );
205
+ }
206
+
207
+ function SMTPSenderModal({ sender, onClose, onSaved }: { sender: any; onClose: () => void; onSaved: () => void }) {
208
+ const { t } = useTranslation();
209
+ const [name, setName] = useState(sender?.name || "");
210
+ const [host, setHost] = useState(sender?.host || "");
211
+ const [port, setPort] = useState(sender?.port?.toString() || "");
212
+ const [user, setUser] = useState(sender?.user || "");
213
+ const [pass, setPass] = useState("");
214
+ const [fromEmail, setFromEmail] = useState(sender?.fromEmail || "");
215
+ const [err, setErr] = useState<string | { message?: string; status?: number; requestId?: string }>("");
216
+ const [busy, setBusy] = useState(false);
217
+
218
+ async function submit(e: React.FormEvent) {
219
+ e.preventDefault();
220
+ setBusy(true); setErr("");
221
+ try {
222
+ const payload = { name, host, port: parseInt(port, 10), user, pass, fromEmail };
223
+ if (sender) {
224
+ await mailApi.updateSMTPSender(sender.id, payload);
225
+ } else {
226
+ await mailApi.createSMTPSender(payload);
227
+ }
228
+ toast.success(t("settings.saved"));
229
+ onSaved();
230
+ } catch (e: any) {
231
+ setErr(e);
232
+ toast.error(e?.message || t("settings.saveFailed", "Failed to save settings"));
233
+ } finally {
234
+ setBusy(false);
235
+ }
236
+ }
237
+
238
+ return (
239
+ <Modal title={sender ? t("settings.modifySmtpRelay") : t("settings.configureSmtpRelay")} onClose={onClose}>
240
+ <form onSubmit={submit} className="space-y-4">
241
+ <Field label={t("settings.senderConnectionName")}>
242
+ <Input value={name} onChange={(e: any) => setName(e.target.value)} placeholder={t("settings.senderConnectionPlaceholder")} required autoFocus />
243
+ </Field>
244
+
245
+ <div className="flex gap-4">
246
+ <div className="flex-[3]">
247
+ <Field label={t("settings.smtpHostLabel")}>
248
+ <Input className="font-mono text-xs" value={host} onChange={(e: any) => setHost(e.target.value)} placeholder="smtp.mailgun.org" required />
249
+ </Field>
250
+ </div>
251
+ <div className="flex-1">
252
+ <Field label={t("settings.smtpPortLabel")}>
253
+ <Input type="number" className="font-mono text-xs" value={port} onChange={(e: any) => setPort(e.target.value)} placeholder="587" required />
254
+ </Field>
255
+ </div>
256
+ </div>
257
+
258
+ <Field label={t("settings.smtpUsernameLabel")}>
259
+ <Input className="font-mono text-xs" value={user} onChange={(e: any) => setUser(e.target.value)} placeholder={t("settings.smtpUsernamePlaceholder")} required />
260
+ </Field>
261
+
262
+ <Field label={t("settings.smtpPasswordLabel")} hint={sender ? t("settings.smtpPasswordHint") : ""}>
263
+ <Input type="password" className="font-mono text-xs" value={pass} onChange={(e: any) => setPass(e.target.value)} placeholder="••••••••" required={!sender} />
264
+ </Field>
265
+
266
+ <Field label={t("settings.defaultFromAddress")} hint={t("settings.defaultFromHint")}>
267
+ <Input className="font-mono text-xs" value={fromEmail} onChange={(e: any) => setFromEmail(e.target.value)} placeholder="noreply@domain.com" required />
268
+ </Field>
269
+
270
+ {err && <FormError err={err} />}
271
+ <div className="flex justify-end gap-2.5 pt-4 border-t border-border">
272
+ <Button type="button" variant="ghost" onClick={onClose}>{t("settings.cancel")}</Button>
273
+ <Button type="submit" variant="primary" disabled={busy || !name.trim() || !host.trim() || !port || !user.trim()}>
274
+ {busy ? t("settings.savingDots") : t("settings.saveRelay")}
275
+ </Button>
276
+ </div>
277
+ </form>
278
+ </Modal>
279
+ );
280
+ }
@@ -0,0 +1,146 @@
1
+ import { Button, Modal, Field, Input, Badge, Empty, Panel, confirmDialog, timeAgo, Table, THead, TBody, TR, TH, TD, FormError, useTranslation } from "@octarq/plugin-sdk";
2
+ import { useEffect, useState } from "react";
3
+ import { mailApi, MailSuppression } from "../api";
4
+ import { Plus, Trash2, ShieldAlert } from "lucide-react";
5
+
6
+ export function SuppressionList() {
7
+ const { t } = useTranslation();
8
+ const [items, setItems] = useState<MailSuppression[]>([]);
9
+ const [loading, setLoading] = useState(false);
10
+ const [showAdd, setShowAdd] = useState(false);
11
+ const [address, setAddress] = useState("");
12
+ const [err, setErr] = useState<string | { message?: string; status?: number; requestId?: string }>("");
13
+ const [saving, setSaving] = useState(false);
14
+
15
+ async function load() {
16
+ setLoading(true);
17
+ try {
18
+ setItems(await mailApi.suppressions());
19
+ } finally {
20
+ setLoading(false);
21
+ }
22
+ }
23
+
24
+ useEffect(() => {
25
+ load();
26
+ }, []);
27
+
28
+ async function handleAdd() {
29
+ setErr("");
30
+ if (!address.trim() || !address.includes("@")) {
31
+ setErr(t("mail.prefixDomainRequired"));
32
+ return;
33
+ }
34
+ setSaving(true);
35
+ try {
36
+ await mailApi.createSuppression(address.trim());
37
+ setShowAdd(false);
38
+ setAddress("");
39
+ load();
40
+ } catch (e: any) {
41
+ setErr(e);
42
+ } finally {
43
+ setSaving(false);
44
+ }
45
+ }
46
+
47
+ async function handleRemove(item: MailSuppression) {
48
+ if (await confirmDialog(t("mail.deleteSuppressionConfirm", { address: item.address }))) {
49
+ await mailApi.deleteSuppression(item.id);
50
+ load();
51
+ }
52
+ }
53
+
54
+ function renderReasonBadge(reason: string) {
55
+ switch (reason) {
56
+ case "hard_bounce":
57
+ return <Badge variant="danger">{t("mail.reasonHardBounce")}</Badge>;
58
+ case "complaint":
59
+ return <Badge variant="warning">{t("mail.reasonComplaint")}</Badge>;
60
+ case "manual":
61
+ default:
62
+ return <Badge variant="info">{t("mail.reasonManual")}</Badge>;
63
+ }
64
+ }
65
+
66
+ return (
67
+ <Panel
68
+ title={t("mail.suppressionList")}
69
+ description={t("mail.suppressionListDesc")}
70
+ action={
71
+ <Button variant="primary" onClick={() => setShowAdd(true)} className="gap-1.5 py-1 text-xs">
72
+ <Plus className="h-3.5 w-3.5" />
73
+ {t("mail.addSuppression")}
74
+ </Button>
75
+ }
76
+ >
77
+
78
+ {loading && items.length === 0 ? (
79
+ <div className="p-8 text-center text-xs text-muted-foreground">{t("mail.loading")}</div>
80
+ ) : items.length === 0 ? (
81
+ <Empty reason={t("mail.noSuppressions")}>
82
+ <ShieldAlert />
83
+ </Empty>
84
+ ) : (
85
+ <div className="overflow-x-auto border border-border rounded-lg">
86
+ <Table>
87
+ <THead>
88
+ <TR>
89
+ <TH>{t("mail.addressHeader")}</TH>
90
+ <TH>{t("mail.reasonHeader")}</TH>
91
+ <TH>{t("mail.countHeader")}</TH>
92
+ <TH>{t("mail.dateHeader")}</TH>
93
+ <TH className="text-right">{t("mail.actionsHeader")}</TH>
94
+ </TR>
95
+ </THead>
96
+ <TBody>
97
+ {items.map((item) => (
98
+ <TR key={item.id}>
99
+ <TD className="font-mono font-medium text-foreground">{item.address}</TD>
100
+ <TD>{renderReasonBadge(item.reason)}</TD>
101
+ <TD className="font-mono tnum text-muted-foreground">{item.count}</TD>
102
+ <TD className="font-mono tnum text-muted-foreground">{timeAgo(item.createdAt)}</TD>
103
+ <TD className="text-right">
104
+ <Button
105
+ variant="ghost"
106
+ onClick={() => handleRemove(item)}
107
+ title={t("mail.removeSuppression")}
108
+ className="p-1 text-muted-foreground hover:text-danger-fg"
109
+ >
110
+ <Trash2 className="h-3.5 w-3.5" />
111
+ </Button>
112
+ </TD>
113
+ </TR>
114
+ ))}
115
+ </TBody>
116
+ </Table>
117
+ </div>
118
+ )}
119
+
120
+ {showAdd && (
121
+ <Modal title={t("mail.addSuppressionTitle")} onClose={() => setShowAdd(false)}>
122
+ <div className="space-y-4">
123
+ <Field label={t("mail.enterAddress")}>
124
+ <Input
125
+ className="font-mono text-sm"
126
+ value={address}
127
+ onChange={(e) => setAddress(e.target.value)}
128
+ placeholder={t("mail.addressPlaceholder")}
129
+ autoFocus
130
+ />
131
+ </Field>
132
+ {err && <FormError err={err} />}
133
+ <div className="flex justify-end gap-2.5 pt-4 border-t border-border">
134
+ <Button variant="ghost" onClick={() => setShowAdd(false)}>
135
+ {t("mail.cancel")}
136
+ </Button>
137
+ <Button variant="primary" onClick={handleAdd} disabled={saving}>
138
+ {t("mail.saveConfiguration")}
139
+ </Button>
140
+ </div>
141
+ </div>
142
+ </Modal>
143
+ )}
144
+ </Panel>
145
+ );
146
+ }
@@ -0,0 +1,58 @@
1
+ // @vitest-environment happy-dom
2
+ import { describe, it, expect, vi, beforeEach } from "vitest";
3
+ import { render, screen, waitFor } from "@testing-library/react";
4
+ import { MemoryRouter } from "react-router-dom";
5
+ import { I18nProvider } from "@octarq/plugin-sdk";
6
+
7
+ // See links/pages/emptyState.test.tsx — same contract: the page's empty state
8
+ // must render through the shared Empty primitive (tagged with a testid here),
9
+ // never a handwritten copy.
10
+ vi.mock("@octarq/plugin-sdk", async (importOriginal) => {
11
+ const ui = await importOriginal<typeof import("@octarq/plugin-sdk")>();
12
+ return {
13
+ ...ui,
14
+ Empty: (props: { children?: React.ReactNode; reason?: React.ReactNode; detail?: React.ReactNode; action?: React.ReactNode }) => (
15
+ <div data-testid="shared-empty">
16
+ {props.children}
17
+ {props.reason}
18
+ {props.detail}
19
+ {props.action}
20
+ </div>
21
+ ),
22
+ };
23
+ });
24
+
25
+ vi.mock("../api", async (importOriginal) => {
26
+ const mailApi = await importOriginal<typeof import("../api")>();
27
+ return {
28
+ ...mailApi,
29
+ mailApi: {
30
+ ...mailApi.mailApi,
31
+ domains: vi.fn().mockResolvedValue([]),
32
+ mailboxes: vi.fn().mockResolvedValue([]),
33
+ emails: vi.fn().mockResolvedValue([]),
34
+ },
35
+ };
36
+ });
37
+
38
+ import MailPage from "./index";
39
+
40
+ beforeEach(() => {
41
+ vi.clearAllMocks();
42
+ });
43
+
44
+ describe("MailPage empty state", () => {
45
+ it("renders the shared Empty when there are no mailboxes (not a handwritten copy)", async () => {
46
+ render(
47
+ <MemoryRouter initialEntries={["/mail"]}>
48
+ <I18nProvider>
49
+ <MailPage />
50
+ </I18nProvider>
51
+ </MemoryRouter>
52
+ );
53
+
54
+ await waitFor(() => {
55
+ expect(screen.getAllByTestId("shared-empty").length).toBeGreaterThan(0);
56
+ });
57
+ });
58
+ });