import test from "node:test"; import assert from "node:assert/strict"; import { readFileSync } from "node:fs"; import { join } from "node:path"; const root = join(import.meta.dirname, "../.."); const llmChatCardPath = "src/app/(dashboard)/dashboard/media-providers/components/LlmChatCard.tsx"; const src = readFileSync(join(root, llmChatCardPath), "utf8"); const DISABLED_ON_LOADING = /disabled\s*=\s*\{\s*loading\s*\}/; const MODELS_LOADING_MARKER = /modelsLoading|Loading…|Loading\.\.\./; const ERROR_BRANCH = /error\s*&&/; const RETRY_ACTION = /onClick\s*=\s*\{[^}]*retry|retry[A-Za-z]*\s*\(\)|const\s+\[reload/i; const NO_MODELS_AFTER_EMPTY = /modelOptions\.length\s*===?\s*0|models\.length\s*===?\s*0/; test("LlmChatCard destructures loading and error from useProviderModels (#9626)", () => { const match = src.match(/const\s*\{\s*([^}]+)\s*\}\s*=\s*useProviderModels\(/); assert.ok(match, "Expected to find a destructuring of useProviderModels"); const destructured = match[1]; assert.ok( destructured.includes("loading"), "loading state must be destructured from useProviderModels" ); assert.ok(destructured.includes("error"), "error state must be destructured from useProviderModels"); }); test("LlmChatCard disables the model selector while models are loading (#9626)", () => { assert.ok( DISABLED_ON_LOADING.test(src), "The model