From c53035a4aa25ed47f1fbb3f1d470f4b87628955a Mon Sep 17 00:00:00 2001 From: jevb Date: Wed, 1 Apr 2026 11:51:07 +0200 Subject: [PATCH] fix: resolve TypeScript strict mode type errors Fix 5 typecheck errors caught by tsc strict mode: - Remove soundboard_play reference from types.test.ts - Use optional chaining on MountableComponent.destroy - Add string fallback for ROLE_COLORS lookup - Add missing Channel fields in screen-share test mock - Add non-null assertion on mock.calls index --- Client/tauri-client/src/components/UserBar.ts | 2 +- .../tauri-client/src/components/UserProfilePopup.ts | 2 +- .../tests/unit/screen-share-button.test.ts | 13 ++++++++++++- .../tests/unit/status-picker-userbar.test.ts | 2 +- Client/tauri-client/tests/unit/types.test.ts | 6 +----- .../tests/unit/user-profile-popup.test.ts | 6 +++--- 6 files changed, 19 insertions(+), 12 deletions(-) diff --git a/Client/tauri-client/src/components/UserBar.ts b/Client/tauri-client/src/components/UserBar.ts index 5db9feee..647cc8de 100644 --- a/Client/tauri-client/src/components/UserBar.ts +++ b/Client/tauri-client/src/components/UserBar.ts @@ -150,7 +150,7 @@ export function createUserBar(options?: UserBarOptions): MountableComponent { } function destroy(): void { - statusPicker?.destroy(); + statusPicker?.destroy?.(); statusPicker = null; disposable.destroy(); if (root !== null) { diff --git a/Client/tauri-client/src/components/UserProfilePopup.ts b/Client/tauri-client/src/components/UserProfilePopup.ts index bd93a637..7c9944d0 100644 --- a/Client/tauri-client/src/components/UserProfilePopup.ts +++ b/Client/tauri-client/src/components/UserProfilePopup.ts @@ -209,7 +209,7 @@ export function createUserProfilePopup( // Role badge const roleBadge = createElement("span", { class: "upp-role-badge" }); const roleDot = createElement("span", { class: "upp-role-dot" }); - roleDot.style.background = ROLE_COLORS[user.role] ?? ROLE_COLORS.member; + roleDot.style.background = ROLE_COLORS[user.role] ?? ROLE_COLORS.member ?? ""; const roleLabel = createElement( "span", {}, diff --git a/Client/tauri-client/tests/unit/screen-share-button.test.ts b/Client/tauri-client/tests/unit/screen-share-button.test.ts index ec711d7c..11e2f300 100644 --- a/Client/tauri-client/tests/unit/screen-share-button.test.ts +++ b/Client/tauri-client/tests/unit/screen-share-button.test.ts @@ -64,7 +64,18 @@ function setVoiceConnected(screenshare = false): void { channelsStore.setState((prev) => ({ ...prev, channels: new Map([ - [1, { id: 1, name: "Voice", type: "voice" as const, category: null, position: 0 }], + [ + 1, + { + id: 1, + name: "Voice", + type: "voice" as const, + category: null, + position: 0, + unreadCount: 0, + lastMessageId: null, + }, + ], ]), })); voiceStore.setState((prev) => ({ diff --git a/Client/tauri-client/tests/unit/status-picker-userbar.test.ts b/Client/tauri-client/tests/unit/status-picker-userbar.test.ts index ab5b1276..e95a09e8 100644 --- a/Client/tauri-client/tests/unit/status-picker-userbar.test.ts +++ b/Client/tauri-client/tests/unit/status-picker-userbar.test.ts @@ -95,7 +95,7 @@ describe("StatusPicker wired to UserBar", () => { (options[1] as HTMLElement).click(); // "Idle" expect(ws.send).toHaveBeenCalledOnce(); - const sentMsg = (ws.send as ReturnType).mock.calls[0][0]; + const sentMsg = (ws.send as ReturnType).mock.calls[0]![0]; expect(sentMsg.type).toBe("presence_update"); expect(sentMsg.payload.status).toBe("idle"); }); diff --git a/Client/tauri-client/tests/unit/types.test.ts b/Client/tauri-client/tests/unit/types.test.ts index 29d9b5e4..22c1ac20 100644 --- a/Client/tauri-client/tests/unit/types.test.ts +++ b/Client/tauri-client/tests/unit/types.test.ts @@ -214,11 +214,7 @@ describe("ClientMessage types", () => { }; expect(reactionAdd.type).toBe("reaction_add"); - const soundboard: ClientMessage = { - type: "soundboard_play", - payload: { sound_id: "uuid-123" }, - }; - expect(soundboard.type).toBe("soundboard_play"); + // soundboard_play type removed — see TODOS.md }); it("includes voice mute type", () => { diff --git a/Client/tauri-client/tests/unit/user-profile-popup.test.ts b/Client/tauri-client/tests/unit/user-profile-popup.test.ts index 661b3f70..6930623a 100644 --- a/Client/tauri-client/tests/unit/user-profile-popup.test.ts +++ b/Client/tauri-client/tests/unit/user-profile-popup.test.ts @@ -55,7 +55,7 @@ describe("UserProfilePopup", () => { expect(popupEl?.getAttribute("role")).toBe("dialog"); expect(popupEl?.getAttribute("aria-label")).toBe("User profile"); - popup.destroy(); + popup.destroy?.(); }); it("displays content correctly including status and join date", () => { @@ -89,7 +89,7 @@ describe("UserProfilePopup", () => { const callBtn = container.querySelector('[data-testid="upp-call-btn"]'); expect(callBtn).not.toBeNull(); - popup.destroy(); + popup.destroy?.(); }); it("outside click closes the popup", () => { @@ -138,7 +138,7 @@ describe("UserProfilePopup", () => { const avatar = container.querySelector(".upp-avatar") as HTMLElement; expect(avatar.style.background).toBe("rgb(78, 80, 88)"); // #4e5058 - popup.destroy(); + popup.destroy?.(); }); it("Escape key closes the popup", () => {