Files
OwnCord/Client/tauri-client/tests/unit/delete-channel-modal.test.ts
T
J3vbandClaude Fable 5 b1fb56511d fix(client): batch of 15 client correctness fixes (#1366)
* fix(message-list): rebuild virtual window when scroll leaves the rendered range

Scroll-driven renderWindow calls previously never rebuilt the DOM, so
scrolling past the overscan showed only spacer blank space until an
unrelated data change forced a full re-render. The window now rebuilds
whenever the computed visible range is not fully contained in the
rendered one, keeping the no-op (and the existing rebuild rate limiter)
for ranges that are already rendered.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0188TWF92r4aNM7T6eiiD7sU

* fix(messages): refetch channel tail when revisiting a previously loaded channel

The server only delivers live message broadcasts for the focused channel,
so a channel's loaded window stops updating once the user switches away.
Switching channels now drops the left channel's loaded flag so the next
visit refetches the live tail, while keeping the old rows rendered until
the refetch merges in (pending/failed rows are preserved).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0188TWF92r4aNM7T6eiiD7sU

* fix(channel-sidebar): assign distinct slots when reordering channels with tied positions

Categories whose channels share a position value (the server does not
enforce uniqueness, and new channels default to position 0) previously
produced an empty or partial reorder on drop, leaving the final order
ambiguous. Tied slots are now nudged into a strictly increasing sequence
before being reassigned, while already-distinct groups keep their range.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0188TWF92r4aNM7T6eiiD7sU

* fix(embeds): keep the link-preview abort timer armed until the body is read

The link-preview fetch previously cleared its 5 s abort timer as soon as
response headers arrived, so reading the response body was unbounded in
time and size. The timer is now cleared in a finally after the body read,
so the timeout covers the whole request and the 50 KB parse cap applies
as documented.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0188TWF92r4aNM7T6eiiD7sU

* fix(message-list): anchor scroll-to-bottom and jump-to-present controls outside the scroller

The two floating controls were appended inside the overflow scroller, so
they were part of its scrollable overflow and translated away with the
content whenever the user scrolled up — precisely when they become
visible. They now anchor to a position:relative frame that wraps the
scroller, keeping them pinned to the viewport edge.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0188TWF92r4aNM7T6eiiD7sU

* fix(voice): reset the pinned input device before cycling the mic to default

Selecting the default microphone (or losing the selected one to a hot
unplug) only muted and unmuted the existing track, which kept capturing
from the previously pinned device. The shared cycle now resets the
capture device to the system default first so both paths actually reach
it.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0188TWF92r4aNM7T6eiiD7sU

* fix(voice): re-check supersession after camera publish before announcing camera on

A camera disable that completes while the enable's publishTrack call is
still in flight now causes the enable to unpublish and stop its track and
skip the enabled announcement, so the server's last word matches the local
state instead of reporting a stopped camera as on.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0188TWF92r4aNM7T6eiiD7sU

* fix(voice): re-check supersession across the screenshare publish loop

A screenshare disable that completes while a publish in the enable loop is
still in flight now stops the loop before the remaining tracks are
published; the enable attempt unpublishes and stops all of its tracks and
skips the enabled announcement, so tracks held only by that attempt are
released and the server's last word matches the local state.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0188TWF92r4aNM7T6eiiD7sU

* fix(sidebar): rethrow channel modal API failures so modals can recover

The create/edit/delete channel callbacks caught API errors and only
showed a toast, so the awaiting modal never saw the failure and left its
submit button disabled with the in-flight label. The callbacks now
rethrow after toasting, letting each modal re-enable its button and
render its inline error so the user can retry without losing the form.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0188TWF92r4aNM7T6eiiD7sU

* fix(messages): carry pending and failed rows across the prepend trim

When a scroll-up page pushed a channel past the per-channel cap,
prependMessages trimmed the tail wholesale, deleting pending/failed
optimistic rows that hold the only copy of the user's composed text.
The trim now carries those rows across, matching the other
window-replacing writers.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0188TWF92r4aNM7T6eiiD7sU

* fix(channel-sidebar): re-resolve the drop container when the sidebar re-renders mid-drag

A store-driven sidebar re-render while a drag is in flight rebuilds the
channel rows, detaching the container captured at mousedown; detached
rows report all-zero rects, so the drop and the hover indicator could
never resolve. The global handlers now re-target the live row, its
container, and the store's current group snapshot before hit-testing.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0188TWF92r4aNM7T6eiiD7sU

* fix(delete-channel-modal): re-arm the confirm button when a delete fails

The confirm button was only restored from the catch block, so a caller
that handled the failure itself and resolved left the button disabled on
'Deleting...' with no way to retry. Restoration now runs in a finally
block whenever the modal is still open, regardless of how the callback
settled.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0188TWF92r4aNM7T6eiiD7sU

* fix(dm-sidebar): keep the presence dot when an avatar image loads

The avatar swap cleared the whole circle before inserting the fetched
image, which also removed the online/idle/dnd/offline dot on 1:1 rows.
The initial now lives in its own node and only that node is replaced,
so the presence dot survives the image arriving.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0188TWF92r4aNM7T6eiiD7sU

* fix(formatting): compute the yesterday boundary from the calendar date

The relative-day fence post was derived by subtracting a fixed 24 hours
from local midnight, which lands inside the wrong calendar day when a
DST transition makes the local day 23 or 25 hours long. It is now built
from the calendar date directly, so hover and expanded message
timestamps keep the correct Yesterday label around transitions.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0188TWF92r4aNM7T6eiiD7sU

* fix(message-input): keep the empty-edit guard active while attachments are queued

Edits are text-only, so a queued attachment no longer bypasses the
empty-content guard while editing. Submitting an edit whose text was
cleared is now refused with edit mode intact, matching the behavior
when nothing is attached.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0188TWF92r4aNM7T6eiiD7sU

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-08-14 05:55:00 +02:00

240 lines
8.1 KiB
TypeScript

import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
import { createDeleteChannelModal } from "@components/DeleteChannelModal";
import type { DeleteChannelModalOptions } from "@components/DeleteChannelModal";
describe("DeleteChannelModal", () => {
let container: HTMLDivElement;
beforeEach(() => {
container = document.createElement("div");
document.body.appendChild(container);
});
afterEach(() => {
container.remove();
document.querySelectorAll("[data-testid='delete-channel-modal']").forEach((el) => el.remove());
});
function makeModal(overrides?: Partial<DeleteChannelModalOptions>) {
const options: DeleteChannelModalOptions = {
channelId: 1,
channelName: "general",
onConfirm: overrides?.onConfirm ?? vi.fn(async () => {}),
onClose: overrides?.onClose ?? vi.fn(),
};
const modal = createDeleteChannelModal(options);
modal.mount(container);
return { modal, options };
}
it("renders the modal overlay", () => {
const { modal } = makeModal();
expect(container.querySelector("[data-testid='delete-channel-modal']")).not.toBeNull();
modal.destroy?.();
});
it("displays channel name in warning message", () => {
const { modal } = makeModal();
const overlay = container.querySelector("[data-testid='delete-channel-modal']");
expect(overlay?.textContent).toContain("#general");
modal.destroy?.();
});
it("displays cannot be undone warning", () => {
const { modal } = makeModal();
const overlay = container.querySelector("[data-testid='delete-channel-modal']");
expect(overlay?.textContent).toContain("cannot be undone");
modal.destroy?.();
});
it("calls onConfirm when delete button is clicked", async () => {
const onConfirm = vi.fn(async () => {});
const { modal } = makeModal({ onConfirm });
const deleteBtn = container.querySelector(
"[data-testid='delete-channel-confirm']",
) as HTMLButtonElement;
deleteBtn.click();
await vi.waitFor(() => {
expect(onConfirm).toHaveBeenCalled();
});
modal.destroy?.();
});
it("calls onClose when close button is clicked", () => {
const onClose = vi.fn();
const { modal } = makeModal({ onClose });
const closeBtn = container.querySelector(".modal-close") as HTMLButtonElement;
closeBtn.click();
expect(onClose).toHaveBeenCalled();
modal.destroy?.();
});
it("calls onClose when cancel button is clicked", () => {
const onClose = vi.fn();
const { modal } = makeModal({ onClose });
const cancelBtn = container.querySelector(".btn-modal-cancel") as HTMLButtonElement;
cancelBtn.click();
expect(onClose).toHaveBeenCalled();
modal.destroy?.();
});
it("removes overlay on destroy", () => {
const { modal } = makeModal();
expect(container.querySelector("[data-testid='delete-channel-modal']")).not.toBeNull();
modal.destroy?.();
expect(container.querySelector("[data-testid='delete-channel-modal']")).toBeNull();
});
it("shows error and re-enables button when onConfirm rejects with Error", async () => {
const onConfirm = vi.fn().mockRejectedValue(new Error("Permission denied"));
const { modal } = makeModal({ onConfirm });
const deleteBtn = container.querySelector(
"[data-testid='delete-channel-confirm']",
) as HTMLButtonElement;
deleteBtn.click();
await vi.waitFor(() => {
const error = container.querySelector("[data-testid='delete-channel-error']");
expect(error?.textContent).toBe("Permission denied");
});
expect(deleteBtn.hasAttribute("disabled")).toBe(false);
expect(deleteBtn.textContent).toBe("Delete Channel");
modal.destroy?.();
});
it("shows generic error when onConfirm rejects with non-Error", async () => {
const onConfirm = vi.fn().mockRejectedValue(42);
const { modal } = makeModal({ onConfirm });
const deleteBtn = container.querySelector(
"[data-testid='delete-channel-confirm']",
) as HTMLButtonElement;
deleteBtn.click();
await vi.waitFor(() => {
const error = container.querySelector("[data-testid='delete-channel-error']");
expect(error?.textContent).toBe("Failed to delete channel");
});
modal.destroy?.();
});
it("re-arms the confirm button when onConfirm resolves without closing the modal", async () => {
// A caller may handle the failure itself (toast) and resolve instead of
// rejecting; the modal must not stay stuck disabled on "Deleting...".
const onConfirm = vi.fn(async () => {});
const { modal } = makeModal({ onConfirm });
const deleteBtn = container.querySelector(
"[data-testid='delete-channel-confirm']",
) as HTMLButtonElement;
deleteBtn.click();
await vi.waitFor(() => {
expect(deleteBtn.hasAttribute("disabled")).toBe(false);
});
expect(deleteBtn.textContent).toBe("Delete Channel");
// No rejection reached the modal, so no inline error either.
const error = container.querySelector("[data-testid='delete-channel-error']") as HTMLElement;
expect(error.style.display).toBe("none");
modal.destroy?.();
});
it("disables button and shows 'Deleting...' during delete", async () => {
let resolveDelete: (() => void) | undefined;
const onConfirm = vi.fn<any>(
() =>
new Promise<void>((resolve) => {
resolveDelete = resolve;
}),
);
const { modal } = makeModal({ onConfirm });
const deleteBtn = container.querySelector(
"[data-testid='delete-channel-confirm']",
) as HTMLButtonElement;
deleteBtn.click();
expect(deleteBtn.hasAttribute("disabled")).toBe(true);
expect(deleteBtn.textContent).toBe("Deleting...");
resolveDelete?.();
modal.destroy?.();
});
it("calls onClose on backdrop click", () => {
const onClose = vi.fn();
const { modal } = makeModal({ onClose });
const overlay = container.querySelector(
"[data-testid='delete-channel-modal']",
) as HTMLDivElement;
overlay.dispatchEvent(new MouseEvent("click", { bubbles: true }));
expect(onClose).toHaveBeenCalled();
modal.destroy?.();
});
// ── dialog accessibility contract (DC-13) ──────────────────────────────────
it("stamps dialog semantics named by the header title", () => {
const { modal } = makeModal();
const dialog = container.querySelector(".modal") as HTMLElement;
expect(dialog.getAttribute("role")).toBe("dialog");
expect(dialog.getAttribute("aria-modal")).toBe("true");
expect(dialog.getAttribute("aria-labelledby")).toBe("delete-channel-title");
expect(container.querySelector("#delete-channel-title")?.textContent).toBe("Delete Channel");
modal.destroy?.();
});
it("labels the icon-only close button", () => {
const { modal } = makeModal();
const closeBtn = container.querySelector(".modal-close") as HTMLButtonElement;
expect(closeBtn.getAttribute("aria-label")).toBe("Close");
modal.destroy?.();
});
it("Escape cancels without confirming the delete", () => {
const onConfirm = vi.fn(async () => {});
const onClose = vi.fn();
const { modal } = makeModal({ onConfirm, onClose });
document.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape" }));
expect(onClose).toHaveBeenCalledTimes(1);
expect(onConfirm).not.toHaveBeenCalled();
modal.destroy?.();
});
it("ignores Escape after destroy", () => {
const onClose = vi.fn();
const { modal } = makeModal({ onClose });
modal.destroy?.();
document.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape" }));
expect(onClose).not.toHaveBeenCalled();
});
it("moves focus into the dialog on open and restores it on destroy", () => {
const trigger = document.createElement("button");
container.appendChild(trigger);
trigger.focus();
const { modal } = makeModal();
// First focusable is the header's close button — safely away from the
// destructive confirm.
const closeBtn = container.querySelector(".modal-close") as HTMLButtonElement;
expect(document.activeElement).toBe(closeBtn);
modal.destroy?.();
expect(document.activeElement).toBe(trigger);
});
});