import { expect, test } from "@playwright/test";

import { invalidNewChatUrl } from "./support/chat-helpers";

const LOCAL_SETTINGS_KEY = "deerflow.local-settings";

test.describe("本地设置清理", () => {
  test("禁用持久化后会在进入工作台时清除历史 localStorage 设置", async ({
    page,
  }) => {
    await page.addInitScript(
      ({ key, value }: { key: string; value: string }) => {
        window.localStorage.setItem(key, value);
      },
      {
        key: LOCAL_SETTINGS_KEY,
        value: JSON.stringify({
          context: {
            model_name: "gpt-5",
            mode: "pro",
            reasoning_effort: "high",
          },
          layout: {
            sidebar_collapsed: true,
          },
          notification: {
            enabled: false,
          },
        }),
      },
    );

    await page.goto(invalidNewChatUrl());
    await expect(page.locator("textarea[name='message']")).toBeVisible();

    await expect
      .poll(
        () => page.evaluate((key) => window.localStorage.getItem(key), LOCAL_SETTINGS_KEY),
        { message: "expected deprecated local settings storage to be cleared" },
      )
      .toBeNull();
  });
});
