Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

fix(tests): address code review issues

oyi77b98d6984a184
diff --git a/tests/e2e/settings-toggles.spec.ts b/tests/e2e/settings-toggles.spec.ts
index 96ed7587d0..fbd4167488 100644
--- a/tests/e2e/settings-toggles.spec.ts
+++ b/tests/e2e/settings-toggles.spec.ts
@@ -1,62 +1,51 @@
import { test, expect } from "@playwright/test";
test.describe("Settings Toggles", () => {
- test.describe("Debug Mode Toggle", () => {
- test("should toggle debug mode on and off", async ({ page }) => {
- await page.goto("/dashboard/settings");
- await page.waitForLoadState("networkidle");
- await page.click("text=Advanced");
-
- const debugToggle = page.locator('[aria-label*="debug" i], [data-testid*="debug" i]').first();
-
- if (await debugToggle.isVisible({ timeout: 3000 }).catch(() => false)) {
- const initialState = await debugToggle.isChecked();
- await debugToggle.click();
- await page.waitForTimeout(500);
- const newState = await debugToggle.isChecked();
- expect(newState).not.toBe(initialState);
- }
- });
+ test("Debug mode toggle should work", async ({ page }) => {
+ await page.goto("/dashboard/settings");
+ await page.waitForLoadState("networkidle");
+ await page.click("text=Advanced");
+
+ const debugToggle = page.locator('[aria-label*="debug" i], [data-testid*="debug" i]').first();
+
+ await expect(debugToggle).toBeVisible({ timeout: 5000 });
+
+ const initialState = await debugToggle.isChecked();
+ await debugToggle.click();
+ await expect(debugToggle).not.toBeChecked({ timeout: 5000 });
});
- test.describe("Sidebar Visibility Toggle", () => {
- test("should toggle sidebar items visibility", async ({ page }) => {
- await page.goto("/dashboard/settings");
- await page.waitForLoadState("networkidle");
- await page.click("text=General");
-
- const sidebarToggle = page
- .locator('[aria-label*="sidebar" i], [data-testid*="sidebar" i]')
- .first();
-
- if (await sidebarToggle.isVisible({ timeout: 3000 }).catch(() => false)) {
- const initialState = await sidebarToggle.isChecked();
- await sidebarToggle.click();
- await page.waitForTimeout(500);
- const newState = await sidebarToggle.isChecked();
- expect(newState).not.toBe(initialState);
- }
- });
+ test("Sidebar visibility toggle should work", async ({ page }) => {
+ await page.goto("/dashboard/settings");
+ await page.waitForLoadState("networkidle");
+ await page.click("text=General");
+
+ const sidebarToggle = page
+ .locator('[aria-label*="sidebar" i], [data-testid*="sidebar" i]')
+ .first();
+
+ await expect(sidebarToggle).toBeVisible({ timeout: 5000 });
+
+ const initialState = await sidebarToggle.isChecked();
+ await sidebarToggle.click();
+ await expect(sidebarToggle).not.toBeChecked({ timeout: 5000 });
});
- test.describe("Settings Persistence", () => {
- test("should persist debug mode after page reload", async ({ page }) => {
- await page.goto("/dashboard/settings");
- await page.waitForLoadState("networkidle");
- await page.click("text=Advanced");
-
- const debugToggle = page.locator('[aria-label*="debug" i], [data-testid*="debug" i]').first();
-
- if (await debugToggle.isVisible({ timeout: 3000 }).catch(() => false)) {
- const wasChecked = await debugToggle.isChecked();
- await debugToggle.click();
- await page.waitForTimeout(500);
- await page.reload();
- await page.waitForLoadState("networkidle");
- await page.click("text=Advanced");
- const isChecked = await debugToggle.isChecked();
- expect(isChecked).not.toBe(wasChecked);
- }
- });
+ test("Debug mode should persist after page reload", async ({ page }) => {
+ await page.goto("/dashboard/settings");
+ await page.waitForLoadState("networkidle");
+ await page.click("text=Advanced");
+
+ const debugToggle = page.locator('[aria-label*="debug" i], [data-testid*="debug" i]').first();
+
+ await expect(debugToggle).toBeVisible({ timeout: 5000 });
+
+ const wasChecked = await debugToggle.isChecked();
+ await debugToggle.click();
+ await expect(debugToggle).not.toBeChecked({ timeout: 5000 });
+ await page.reload();
+ await page.waitForLoadState("networkidle");
+ await page.click("text=Advanced");
+ await expect(debugToggle).not.toBeChecked({ timeout: 5000 });
});
});
diff --git a/tests/unit/settings-api.test.mjs b/tests/unit/settings-api.test.mjs
index ff21acccdf..e3192e2c76 100644
--- a/tests/unit/settings-api.test.mjs
+++ b/tests/unit/settings-api.test.mjs
@@ -1,32 +1,32 @@
import { describe, test } from "node:test";
import assert from "node:assert/strict";
-import { getSettings, updateSettings } from "../../src/lib/localDb.ts";
+import { getSettings, updateSettings } from "../../src/lib/db/settings.ts";
describe("Settings API - debugMode and hiddenSidebarItems", () => {
describe("debugMode", () => {
- test("PATCH with debugMode=true succeeds", async () => {
+ test("updateSettings with debugMode=true succeeds", async () => {
const result = await updateSettings({ debugMode: true });
- assert.strictEqual(result.ok, true, "updateSettings should return ok: true");
+ assert.ok(result, "updateSettings should return truthy result");
- const settings = getSettings();
+ const settings = await getSettings();
assert.strictEqual(settings.debugMode, true, "debugMode should be true");
});
- test("PATCH with debugMode=false succeeds", async () => {
+ test("updateSettings with debugMode=false succeeds", async () => {
const result = await updateSettings({ debugMode: false });
- assert.strictEqual(result.ok, true, "updateSettings should return ok: true");
+ assert.ok(result, "updateSettings should return truthy result");
- const settings = getSettings();
+ const settings = await getSettings();
assert.strictEqual(settings.debugMode, false, "debugMode should be false");
});
});
describe("hiddenSidebarItems", () => {
- test("PATCH with hiddenSidebarItems=['translator'] succeeds", async () => {
+ test("updateSettings with hiddenSidebarItems=['translator'] succeeds", async () => {
const result = await updateSettings({ hiddenSidebarItems: ["translator"] });
- assert.strictEqual(result.ok, true, "updateSettings should return ok: true");
+ assert.ok(result, "updateSettings should return truthy result");
- const settings = getSettings();
+ const settings = await getSettings();
assert.deepStrictEqual(
settings.hiddenSidebarItems,
["translator"],
@@ -34,11 +34,11 @@ describe("Settings API - debugMode and hiddenSidebarItems", () => {
);
});
- test("PATCH with empty hiddenSidebarItems succeeds", async () => {
+ test("updateSettings with empty hiddenSidebarItems succeeds", async () => {
const result = await updateSettings({ hiddenSidebarItems: [] });
- assert.strictEqual(result.ok, true, "updateSettings should return ok: true");
+ assert.ok(result, "updateSettings should return truthy result");
- const settings = getSettings();
+ const settings = await getSettings();
assert.deepStrictEqual(
settings.hiddenSidebarItems,
[],
@@ -48,14 +48,14 @@ describe("Settings API - debugMode and hiddenSidebarItems", () => {
});
describe("combined updates", () => {
- test("PATCH with both debugMode and hiddenSidebarItems succeeds", async () => {
+ test("updateSettings with both debugMode and hiddenSidebarItems succeeds", async () => {
const result = await updateSettings({
debugMode: true,
hiddenSidebarItems: ["translator"],
});
- assert.strictEqual(result.ok, true, "updateSettings should return ok: true");
+ assert.ok(result, "updateSettings should return truthy result");
- const settings = getSettings();
+ const settings = await getSettings();
assert.strictEqual(settings.debugMode, true, "debugMode should be true");
assert.deepStrictEqual(
settings.hiddenSidebarItems,