import test from "node:test";
import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";

test("settings keeps its source screen registered until the user goes back", async () => {
  const [app, contextBar] = await Promise.all([
    readFile(new URL("../App.jsx", import.meta.url), "utf8"),
    readFile(new URL("../features/context/ContextBar.jsx", import.meta.url), "utf8")
  ]);

  assert.match(app, /app\.openSettings\(\)/);
  assert.match(app, /app\.closeSettings/);
  assert.doesNotMatch(app, /settingsReturnTabRef/);
  assert.match(app, /useExitTransition\(app\.closeSettings\)/);
  assert.match(app, /useBackLayer\(app\.tab === "settings", settingsMotion\.startExit, "settings"\)/);
  assert.match(app, /const screenLayerActive = \(app\.tab !== "threads" && app\.tab !== "settings"\)\s*\|\| \(app\.tab === "settings" && app\.settingsReturnTab !== "threads"\);/);
  assert.match(app, /const closeScreen = useBackLayer\(screenLayerActive,/);
  assert.match(app, /<ChatsPanel active=\{!app\.newChatOpen && \(app\.tab === "threads" \|\| splitLayoutActive\)\}/);
  assert.match(contextBar, /function openSettings\(\) \{\s*closeAccountMenu\(\(\) => onSettingsOpen\?\.\(\)\);\s*\}/);
});
