import assert from 'node:assert/strict'; import fs from 'node:fs'; import path from 'node:path'; import test from 'node:test'; import { fileURLToPath } from 'node:url'; const currentDirectory = path.dirname(fileURLToPath(import.meta.url)); const webRoot = path.resolve(currentDirectory, '../..'); function readSource(relativePath) { return fs.readFileSync(path.join(webRoot, relativePath), 'utf8'); } const homeLayoutSource = readSource('src/app/home/layout.tsx'); const homeSidebarSource = readSource( 'src/app/home/components/home-sidebar/HomeSidebar.tsx', ); const workspaceSettingsPanelSource = readSource( 'src/app/home/components/workspace-settings/WorkspaceSettingsPanel.tsx', ); const workspaceSwitcherSource = readSource( 'src/app/home/components/workspace-settings/WorkspaceSwitcher.tsx', ); test('renders WorkspaceSwitcher only from HomeSidebar', () => { assert.doesNotMatch(homeLayoutSource, / { const headerEnd = homeSidebarSource.indexOf(''); const switcher = homeSidebarSource.indexOf('{t('sidebar.home')}", ); assert.notEqual(headerEnd, -1); assert.notEqual(switcher, -1); assert.notEqual(contentStart, -1); assert.notEqual(homeGroup, -1); assert.ok( headerEnd < switcher, 'WorkspaceSwitcher must follow SidebarHeader', ); assert.ok( switcher < contentStart && switcher < homeGroup, 'WorkspaceSwitcher must precede SidebarContent and the Home group', ); }); test('hides WorkspaceSwitcher for the singleton local OSS workspace and keeps it for Cloud or multiple workspaces', () => { assert.match( workspaceSwitcherSource, /if \(!currentWorkspace\) return null;/, ); assert.match( homeSidebarSource, /const workspaces = useWorkspaceBootstrap\(\);/, ); assert.match( homeSidebarSource, /const showWorkspaceSwitcher\s*=\s*workspaces\.length\s*>\s*1\s*\|\|\s*currentWorkspace\?\.workspace\.source\s*===\s*'cloud_projection'/, ); assert.match( homeSidebarSource, /\{showWorkspaceSwitcher\s*&&\s*\(\s*
{ assert.match(workspaceSettingsPanelSource, /workspace\.upgradePlan/); assert.match(workspaceSettingsPanelSource, /cloudPortalURL/); assert.match(workspaceSettingsPanelSource, /step=plan/); assert.match(workspaceSettingsPanelSource, /systemInfo\.cloud_service_url/); }); test('aligns the workspace trigger with navigation entries on both sides and truncates long names', () => { assert.match( homeSidebarSource, /
]*truncate/); }); test('uses an infrastructure-level Box health endpoint in monitoring', () => { const statusCardSource = readSource( 'src/app/home/monitoring/components/overview-cards/SystemStatusCards.tsx', ); const backendClientSource = readSource('src/app/infra/http/BackendClient.ts'); assert.match(backendClientSource, /getBoxRuntimeStatus/); assert.match(statusCardSource, /getBoxRuntimeStatus/); });