From 9b7921c38a81148a68a46bf9428ba829f80ea115 Mon Sep 17 00:00:00 2001 From: Nate Kelley Date: Tue, 5 Aug 2025 10:22:53 -0600 Subject: [PATCH] update unit tests --- apps/web/playwright.config.ts | 13 ++++++-- .../api/buster_rest/chats/requests.test.ts | 2 +- .../ui/report/ThemeWrapper/ThemeWrapper.tsx | 20 +++++++++++++ .../createSelectedFile.test.ts | 30 ++++++++++--------- .../useSelectedFile/useSelectedFile.test.tsx | 6 ++-- 5 files changed, 52 insertions(+), 19 deletions(-) diff --git a/apps/web/playwright.config.ts b/apps/web/playwright.config.ts index 5f7ef4278..281209cc4 100644 --- a/apps/web/playwright.config.ts +++ b/apps/web/playwright.config.ts @@ -1,5 +1,6 @@ import fs from 'node:fs'; import path from 'node:path'; +import { fileURLToPath } from 'node:url'; import { defineConfig, devices } from '@playwright/test'; /** @@ -38,8 +39,16 @@ export default defineConfig({ /* Run tests in headed mode (non-headless) */ headless: true, /* Use stored auth state only if it exists */ - storageState: fs.existsSync(path.join(__dirname, 'playwright-tests/auth-utils/auth.json')) - ? path.join(__dirname, 'playwright-tests/auth-utils/auth.json') + storageState: fs.existsSync( + path.join( + path.dirname(fileURLToPath(import.meta.url)), + 'playwright-tests/auth-utils/auth.json' + ) + ) + ? path.join( + path.dirname(fileURLToPath(import.meta.url)), + 'playwright-tests/auth-utils/auth.json' + ) : undefined }, diff --git a/apps/web/src/api/buster_rest/chats/requests.test.ts b/apps/web/src/api/buster_rest/chats/requests.test.ts index a7e4d785e..235b10d11 100644 --- a/apps/web/src/api/buster_rest/chats/requests.test.ts +++ b/apps/web/src/api/buster_rest/chats/requests.test.ts @@ -20,7 +20,7 @@ describe('Chat API Requests', () => { const mockChats: ChatListItem[] = [ { id: 'test-chat-1', - title: 'Test Chat 1', + name: 'Test Chat 1', created_at: '2024-03-20T00:00:00Z', updated_at: '2024-03-20T00:00:00Z', is_favorited: false, diff --git a/apps/web/src/components/ui/report/ThemeWrapper/ThemeWrapper.tsx b/apps/web/src/components/ui/report/ThemeWrapper/ThemeWrapper.tsx index 8292dfe82..90dd6dd78 100644 --- a/apps/web/src/components/ui/report/ThemeWrapper/ThemeWrapper.tsx +++ b/apps/web/src/components/ui/report/ThemeWrapper/ThemeWrapper.tsx @@ -8,6 +8,26 @@ interface ThemeWrapperProps extends React.ComponentProps<'div'> { defaultTheme?: string; } +/** + * Theme overrides for the report editor + * + * We need to override the default theme for the report editor because: + * + * 1. **Consistent Styling**: The report editor needs to maintain consistent + * appearance regardless of the parent application's theme (light/dark mode) + * + * 2. **Design System Isolation**: Reports should render with their own design + * system to ensure they look the same when shared, exported, or embedded + * + * 3. **Theme Reset**: We reset CSS variables and styles to prevent inheritance + * from parent components that might interfere with report rendering + * + * 4. **Cross-Environment Consistency**: Reports need to look identical whether + * viewed in the editor, shared via link, or exported as PDF/image + * + * The EDITOR_THEME combines light theme colors with reset styles to create + * a clean, controlled environment for report content. + */ const EDITOR_THEME = { ...THEME_RESET_COLORS.light, ...THEME_RESET_STYLE }; export function ThemeWrapper({ children, className, defaultTheme }: ThemeWrapperProps) { diff --git a/apps/web/src/layouts/ChatLayout/ChatLayoutContext/useSelectedFile/createSelectedFile.test.ts b/apps/web/src/layouts/ChatLayout/ChatLayoutContext/useSelectedFile/createSelectedFile.test.ts index 48f7e5104..d07db3d95 100644 --- a/apps/web/src/layouts/ChatLayout/ChatLayoutContext/useSelectedFile/createSelectedFile.test.ts +++ b/apps/web/src/layouts/ChatLayout/ChatLayoutContext/useSelectedFile/createSelectedFile.test.ts @@ -4,9 +4,11 @@ import type { ChatURLParsed } from './parsePathnameSegments'; describe('createSelectedFile', () => { it('returns a metric file when metricId is provided', () => { - const params: ChatURLParsed = { - metricId: 'metric-123' - }; + const params = { + metricId: 'metric-123', + collectionId: 'collection-123', + datasetId: 'dataset-123' + } as Parameters[0]; const result = createSelectedFile(params); @@ -17,9 +19,9 @@ describe('createSelectedFile', () => { }); it('returns a dashboard file when dashboardId is provided', () => { - const params: ChatURLParsed = { + const params = { dashboardId: 'dashboard-456' - }; + } as Parameters[0]; const result = createSelectedFile(params); @@ -30,9 +32,9 @@ describe('createSelectedFile', () => { }); it('returns a reasoning file when messageId is provided', () => { - const params: ChatURLParsed = { + const params = { messageId: 'message-789' - }; + } as Parameters[0]; const result = createSelectedFile(params); @@ -43,11 +45,11 @@ describe('createSelectedFile', () => { }); it('returns null when no relevant id is provided', () => { - const params: ChatURLParsed = { + const params = { chatId: 'chat-123', collectionId: 'collection-123', datasetId: 'dataset-123' - }; + } as Parameters[0]; const result = createSelectedFile(params); @@ -55,7 +57,7 @@ describe('createSelectedFile', () => { }); it('returns null when params object is empty', () => { - const params: ChatURLParsed = {}; + const params = {} as Parameters[0]; const result = createSelectedFile(params); @@ -63,11 +65,11 @@ describe('createSelectedFile', () => { }); it('prioritizes metricId over other ids', () => { - const params: ChatURLParsed = { + const params = { metricId: 'metric-123', dashboardId: 'dashboard-456', messageId: 'message-789' - }; + } as Parameters[0]; const result = createSelectedFile(params); @@ -78,10 +80,10 @@ describe('createSelectedFile', () => { }); it('prioritizes dashboardId over messageId when metricId is not provided', () => { - const params: ChatURLParsed = { + const params = { dashboardId: 'dashboard-456', messageId: 'message-789' - }; + } as Parameters[0]; const result = createSelectedFile(params); diff --git a/apps/web/src/layouts/ChatLayout/ChatLayoutContext/useSelectedFile/useSelectedFile.test.tsx b/apps/web/src/layouts/ChatLayout/ChatLayoutContext/useSelectedFile/useSelectedFile.test.tsx index d9d657640..446f641f8 100644 --- a/apps/web/src/layouts/ChatLayout/ChatLayoutContext/useSelectedFile/useSelectedFile.test.tsx +++ b/apps/web/src/layouts/ChatLayout/ChatLayoutContext/useSelectedFile/useSelectedFile.test.tsx @@ -41,8 +41,10 @@ describe('useSelectedFile', () => { currentRoute: BusterRoutes.APP_CHAT_ID, secondaryView: undefined as FileViewSecondary | undefined, metricVersionNumber: undefined, - dashboardVersionNumber: undefined - }; + dashboardVersionNumber: undefined, + reportId: undefined, + reportVersionNumber: undefined + } satisfies Parameters[0]['chatParams']; beforeEach(() => { vi.clearAllMocks();