49 lines
2.5 KiB
TypeScript
49 lines
2.5 KiB
TypeScript
function assert(condition: unknown, message = "assertion failed"): void {
|
|
if (!condition) throw new Error(message);
|
|
}
|
|
|
|
function assertEqual<T>(actual: T, expected: T, message = "values should be equal"): void {
|
|
if (actual !== expected) throw new Error(`${message}: expected ${String(expected)}, got ${String(actual)}`);
|
|
}
|
|
|
|
function assertDeepEqual(actual: unknown, expected: unknown, message = "values should be deeply equal"): void {
|
|
const actualJson = JSON.stringify(actual);
|
|
const expectedJson = JSON.stringify(expected);
|
|
if (actualJson !== expectedJson) throw new Error(`${message}: expected ${expectedJson}, got ${actualJson}`);
|
|
}
|
|
|
|
import {
|
|
mailProfileChildDescriptors,
|
|
mailProfileEditTargetInitialSection,
|
|
mailProfileEditTargetPanelMode,
|
|
mailProfileEditTargetShowsProfileFields,
|
|
mailProfileEditTargetShowsSettingsPanel,
|
|
mailProfileEditTargetVisibleSections
|
|
} from "../src/features/mail/mailProfileEditorModel";
|
|
|
|
const smtpOnlyChildren = mailProfileChildDescriptors({ id: "profile-1", imap: null });
|
|
assertDeepEqual(
|
|
smtpOnlyChildren.map((child) => `${child.kind}:${child.protocol}`),
|
|
["server:smtp", "credential:smtp", "server:imap"],
|
|
"SMTP-only profiles expose SMTP server/credentials and an addable IMAP server"
|
|
);
|
|
assert(!smtpOnlyChildren.some((child) => child.kind === "credential" && child.protocol === "imap"), "IMAP credentials are hidden until an IMAP server exists");
|
|
|
|
const fullChildren = mailProfileChildDescriptors({ id: "profile-1", imap: { host: "imap.example.org" } });
|
|
assertDeepEqual(
|
|
fullChildren.map((child) => `${child.kind}:${child.protocol}`),
|
|
["server:smtp", "credential:smtp", "server:imap", "credential:imap"],
|
|
"profiles with IMAP expose focused rows for both transports and credentials"
|
|
);
|
|
|
|
assertEqual(mailProfileEditTargetInitialSection({ kind: "server", protocol: "imap" }), "imap");
|
|
assertEqual(mailProfileEditTargetPanelMode({ kind: "server", protocol: "smtp" }), "server");
|
|
assertEqual(mailProfileEditTargetPanelMode({ kind: "credentials", protocol: "imap" }), "credentials");
|
|
assertEqual(mailProfileEditTargetPanelMode({ kind: "profile" }), null);
|
|
assertDeepEqual(mailProfileEditTargetVisibleSections({ kind: "credentials", protocol: "imap" }), ["imap"]);
|
|
assertEqual(mailProfileEditTargetShowsProfileFields({ kind: "profile" }), true);
|
|
assertEqual(mailProfileEditTargetShowsProfileFields({ kind: "server", protocol: "smtp" }), false);
|
|
assertEqual(mailProfileEditTargetShowsSettingsPanel({ kind: "profile" }), false);
|
|
assertEqual(mailProfileEditTargetShowsSettingsPanel({ kind: "create" }), true);
|
|
|