Emdash source with visual editor image upload fix

Fixes:
1. media.ts: wrap placeholder generation in try-catch
2. toolbar.ts: check r.ok, display error message in popover
This commit is contained in:
2026-05-03 10:44:54 +07:00
parent 78f81bebb6
commit 2d1be52177
2352 changed files with 662964 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
import { describe, it, expect, afterEach } from "vitest";
import {
isPasskeyEnvironmentUsable,
isPublicKeyCredentialConstructorAvailable,
isWebAuthnSecureContext,
} from "../../src/lib/webauthn-environment";
describe("webauthn-environment", () => {
const origPk = globalThis.window.PublicKeyCredential;
const desc = Object.getOwnPropertyDescriptor(globalThis.window, "isSecureContext");
afterEach(() => {
if (origPk === undefined) {
delete (globalThis.window as { PublicKeyCredential?: unknown }).PublicKeyCredential;
} else {
Object.defineProperty(globalThis.window, "PublicKeyCredential", {
value: origPk,
configurable: true,
writable: true,
});
}
if (desc) Object.defineProperty(globalThis.window, "isSecureContext", desc);
});
it("is usable only when secure context and PublicKeyCredential constructor exist", () => {
Object.defineProperty(globalThis.window, "isSecureContext", {
value: true,
configurable: true,
});
Object.defineProperty(globalThis.window, "PublicKeyCredential", {
value: function PublicKeyCredential() {},
configurable: true,
writable: true,
});
expect(isWebAuthnSecureContext()).toBe(true);
expect(isPublicKeyCredentialConstructorAvailable()).toBe(true);
expect(isPasskeyEnvironmentUsable()).toBe(true);
});
it("is not usable in an insecure context even if PublicKeyCredential is defined", () => {
Object.defineProperty(globalThis.window, "isSecureContext", {
value: false,
configurable: true,
});
Object.defineProperty(globalThis.window, "PublicKeyCredential", {
value: function PublicKeyCredential() {},
configurable: true,
writable: true,
});
expect(isWebAuthnSecureContext()).toBe(false);
expect(isPasskeyEnvironmentUsable()).toBe(false);
});
});