mirror of
https://github.com/J3vb/OwnCord.git
synced 2026-09-03 03:50:00 +03:00
Update 111 test files to match security hardening changes: - acceptInvalidCerts now conditional on allowSelfSigned - Credential store no longer returns passwords over IPC - File type validation uses strict MIME allowlist - Search rate limiter timing adjustments - Dispatcher cleanup mock additions - Audio elements screenshare mute preservation 2962 tests passing across 110 test files.
62 lines
1.7 KiB
TypeScript
62 lines
1.7 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
const { fetchMock } = vi.hoisted(() => ({
|
|
fetchMock: vi.fn<any>(),
|
|
}));
|
|
|
|
vi.mock("@tauri-apps/plugin-http", () => ({
|
|
fetch: fetchMock,
|
|
}));
|
|
|
|
vi.mock("@lib/logger", () => ({
|
|
createLogger: () => ({ debug: vi.fn(), info: vi.fn(), warn: vi.fn(), error: vi.fn() }),
|
|
}));
|
|
|
|
vi.mock("../../src/components/message-list/attachments", () => ({
|
|
isSafeUrl: () => true,
|
|
}));
|
|
|
|
vi.mock("../../src/components/message-list/embeds", () => ({
|
|
renderGenericLinkPreview: vi.fn(),
|
|
}));
|
|
|
|
import { clearMediaCaches, renderYouTubeEmbed } from "../../src/components/message-list/media";
|
|
|
|
function oembedResponse(title: string) {
|
|
return {
|
|
ok: true,
|
|
json: vi.fn().mockResolvedValue({ title }),
|
|
};
|
|
}
|
|
|
|
describe("media cache clearing", () => {
|
|
beforeEach(() => {
|
|
fetchMock.mockReset();
|
|
clearMediaCaches();
|
|
document.body.innerHTML = "";
|
|
});
|
|
|
|
it("replaces a stale loading title with a fallback when the cache is cleared mid-fetch", async () => {
|
|
let resolveFetch: ((value: ReturnType<typeof oembedResponse>) => void) | undefined;
|
|
fetchMock.mockImplementationOnce(
|
|
() =>
|
|
new Promise((resolve) => {
|
|
resolveFetch = resolve;
|
|
}),
|
|
);
|
|
|
|
const element = renderYouTubeEmbed("abc123", "https://www.youtube.com/watch?v=abc123");
|
|
document.body.appendChild(element);
|
|
|
|
const title = element.querySelector(".msg-embed-yt-title") as HTMLAnchorElement;
|
|
expect(title.textContent).toBe("Loading...");
|
|
|
|
clearMediaCaches();
|
|
resolveFetch?.(oembedResponse("Loaded title"));
|
|
|
|
await vi.waitFor(() => {
|
|
expect(title.textContent).toBe("YouTube Video");
|
|
});
|
|
});
|
|
});
|