diff --git a/src/features/flyer/AnalysisPanel.test.tsx b/src/features/flyer/AnalysisPanel.test.tsx index d19c1af3..778a7d88 100644 --- a/src/features/flyer/AnalysisPanel.test.tsx +++ b/src/features/flyer/AnalysisPanel.test.tsx @@ -27,7 +27,7 @@ describe('AnalysisPanel', () => { mockedAiApiClient.getQuickInsights.mockReset(); mockedAiApiClient.getDeepDiveAnalysis.mockReset(); mockedAiApiClient.searchWeb.mockReset(); - mockedAiApiClient.planTripWithMaps.mockReset(); +// mockedAiApiClient.planTripWithMaps.mockReset(); mockedAiApiClient.generateImageFromText.mockReset(); // Mock Geolocation API @@ -133,28 +133,28 @@ describe('AnalysisPanel', () => { }); }); - it('should display a specific error for geolocation permission denial', async () => { - // Provide explicit types for the success and error callbacks to satisfy TypeScript - (navigator.geolocation.getCurrentPosition as Mock).mockImplementation( - ( - success: (position: GeolocationPosition) => void, - error: (error: GeolocationPositionError) => void - ) => { - error({ code: 1, message: 'User denied Geolocation', PERMISSION_DENIED: 1, POSITION_UNAVAILABLE: 2, TIMEOUT: 3 }); - } - ); - render(); - fireEvent.click(screen.getByRole('tab', { name: /plan trip/i })); - fireEvent.click(screen.getByRole('button', { name: /generate plan trip/i })); + // it('should display a specific error for geolocation permission denial', async () => { + // // Provide explicit types for the success and error callbacks to satisfy TypeScript + // (navigator.geolocation.getCurrentPosition as Mock).mockImplementation( + // ( + // success: (position: GeolocationPosition) => void, + // error: (error: GeolocationPositionError) => void + // ) => { + // error({ code: 1, message: 'User denied Geolocation', PERMISSION_DENIED: 1, POSITION_UNAVAILABLE: 2, TIMEOUT: 3 }); + // } + // ); + // render(); + // fireEvent.click(screen.getByRole('tab', { name: /plan trip/i })); + // fireEvent.click(screen.getByRole('button', { name: /generate plan trip/i })); - // When geolocation fails, the component logs an error and sets the result to an empty string. - // It does not display a specific error message in the UI in this case. - // The test should verify that no result is displayed and no API call is made. - await waitFor(() => { - expect(mockedAiApiClient.planTripWithMaps).not.toHaveBeenCalled(); - expect(screen.queryByText(/Please allow location access/i)).not.toBeInTheDocument(); - }); - }); + // // When geolocation fails, the component logs an error and sets the result to an empty string. + // // It does not display a specific error message in the UI in this case. + // // The test should verify that no result is displayed and no API call is made. + // await waitFor(() => { + // expect(mockedAiApiClient.planTripWithMaps).not.toHaveBeenCalled(); + // expect(screen.queryByText(/Please allow location access/i)).not.toBeInTheDocument(); + // }); + // }); it('should show and call generateImageFromText for Deep Dive results', async () => { mockedAiApiClient.getDeepDiveAnalysis.mockResolvedValue(new Response(JSON.stringify('This is a meal plan.'))); diff --git a/src/features/flyer/AnalysisPanel.tsx b/src/features/flyer/AnalysisPanel.tsx index 8beda04f..9abf1660 100644 --- a/src/features/flyer/AnalysisPanel.tsx +++ b/src/features/flyer/AnalysisPanel.tsx @@ -2,7 +2,7 @@ import React, { useState, useCallback } from 'react'; import { AnalysisType, FlyerItem, Store } from '../../types'; import type { GroundingChunk } from '@google/genai'; -import { getQuickInsights, getDeepDiveAnalysis, searchWeb, planTripWithMaps, generateImageFromText } from '../../services/aiApiClient'; +import { getQuickInsights, getDeepDiveAnalysis, searchWeb, generateImageFromText } from '../../services/aiApiClient'; import { LoadingSpinner } from '../../components/LoadingSpinner'; import { LightbulbIcon } from '../../components/icons/LightbulbIcon'; import { BrainIcon } from '../../components/icons/BrainIcon'; @@ -78,16 +78,16 @@ export const AnalysisPanel: React.FC = ({ flyerItems, store })); responseText = text; newSources = mappedSources; - } else if (type === AnalysisType.PLAN_TRIP) { - const userLocation = await new Promise((resolve, reject) => { - navigator.geolocation.getCurrentPosition( - (position) => resolve(position.coords), - (err: GeolocationPositionError) => reject(err) // Type the error for better handling - ); - }); - const { text, sources } = await (await planTripWithMaps(flyerItems, store, userLocation)).json(); - responseText = text; - newSources = sources; + // } else if (type === AnalysisType.PLAN_TRIP) { + // const userLocation = await new Promise((resolve, reject) => { + // navigator.geolocation.getCurrentPosition( + // (position) => resolve(position.coords), + // (err: GeolocationPositionError) => reject(err) // Type the error for better handling + // ); + // }); + // const { text, sources } = await (await planTripWithMaps(flyerItems, store, userLocation)).json(); + // responseText = text; + // newSources = sources; } setResults(prev => ({ ...prev, [type]: responseText })); setSources(newSources); // Update sources once after all logic diff --git a/src/services/aiService.server.test.ts b/src/services/aiService.server.test.ts index b7ca1c3d..c6e7356d 100644 --- a/src/services/aiService.server.test.ts +++ b/src/services/aiService.server.test.ts @@ -147,35 +147,35 @@ describe('AI Service (Server)', () => { }); }); - describe('planTripWithMaps', () => { - it('should call generateContent and return the text and sources', async () => { - const { planTripWithMaps } = await import('./aiService.server'); - mockGenerateContent.mockResolvedValue({ - text: 'The nearest store is...', - candidates: [{ - groundingMetadata: { - groundingChunks: [ - { web: { uri: 'http://maps.google.com/1', title: 'Map to Store A' } }, - { web: { uri: 'http://maps.google.com/2', title: 'Map to Store B' } }, - ], - }, - }], - }); + // describe('planTripWithMaps', () => { + // it('should call generateContent and return the text and sources', async () => { + // const { planTripWithMaps } = await import('./aiService.server'); + // mockGenerateContent.mockResolvedValue({ + // text: 'The nearest store is...', + // candidates: [{ + // groundingMetadata: { + // groundingChunks: [ + // { web: { uri: 'http://maps.google.com/1', title: 'Map to Store A' } }, + // { web: { uri: 'http://maps.google.com/2', title: 'Map to Store B' } }, + // ], + // }, + // }], + // }); - const mockLocation = { latitude: 48.4284, longitude: -123.3656 } as GeolocationCoordinates; - const result = await planTripWithMaps([], undefined, mockLocation); + // const mockLocation = { latitude: 48.4284, longitude: -123.3656 } as GeolocationCoordinates; + // const result = await planTripWithMaps([], undefined, mockLocation); - expect(mockGenerateContent).toHaveBeenCalledTimes(1); - const calledWith = mockGenerateContent.mock.calls[0][0] as any; - expect(calledWith.contents).toContain('latitude 48.4284'); + // expect(mockGenerateContent).toHaveBeenCalledTimes(1); + // const calledWith = mockGenerateContent.mock.calls[0][0] as any; + // expect(calledWith.contents).toContain('latitude 48.4284'); - expect(result.text).toBe('The nearest store is...'); - expect(result.sources).toEqual([ - { uri: 'http://maps.google.com/1', title: 'Map to Store A' }, - { uri: 'http://maps.google.com/2', title: 'Map to Store B' }, - ]); - }); - }); + // expect(result.text).toBe('The nearest store is...'); + // expect(result.sources).toEqual([ + // { uri: 'http://maps.google.com/1', title: 'Map to Store A' }, + // { uri: 'http://maps.google.com/2', title: 'Map to Store B' }, + // ]); + // }); + // }); describe('extractTextFromImageArea', () => { it('should call sharp to crop the image and call the AI with the correct prompt', async () => { diff --git a/src/tests/integration/ai.integration.test.ts b/src/tests/integration/ai.integration.test.ts index f2db5780..7a9891c1 100644 --- a/src/tests/integration/ai.integration.test.ts +++ b/src/tests/integration/ai.integration.test.ts @@ -89,26 +89,26 @@ describe('AI API Routes Integration Tests', () => { expect(result).toEqual({ text: "The web says this is good.", sources: [] }); }); - it('POST /api/ai/plan-trip should return a stubbed trip plan', async () => { - // The GeolocationCoordinates type requires more than just lat/lng. - // We create a complete mock object to satisfy the type. - const mockLocation: TestGeolocationCoordinates = { - latitude: 48.4284, - longitude: -123.3656, - accuracy: 100, - altitude: null, - altitudeAccuracy: null, - heading: null, - speed: null, - toJSON: () => ({}), - }; - const response = await aiApiClient.planTripWithMaps([], undefined, mockLocation, authToken); - const result = await response.json(); - expect(result).toBeDefined(); - // Make the assertion less brittle. The AI might return "grocery store" (singular). - // Using a case-insensitive regex for "grocery store" is more robust. - expect(result.text).toMatch(/grocery store/i); - }); + // it('POST /api/ai/plan-trip should return a stubbed trip plan', async () => { + // // The GeolocationCoordinates type requires more than just lat/lng. + // // We create a complete mock object to satisfy the type. + // const mockLocation: TestGeolocationCoordinates = { + // latitude: 48.4284, + // longitude: -123.3656, + // accuracy: 100, + // altitude: null, + // altitudeAccuracy: null, + // heading: null, + // speed: null, + // toJSON: () => ({}), + // }; + // const response = await aiApiClient.planTripWithMaps([], undefined, mockLocation, authToken); + // const result = await response.json(); + // expect(result).toBeDefined(); + // // Make the assertion less brittle. The AI might return "grocery store" (singular). + // // Using a case-insensitive regex for "grocery store" is more robust. + // expect(result.text).toMatch(/grocery store/i); + // }); it('POST /api/ai/generate-image should reject because it is not implemented', async () => { // The backend for this is not stubbed and will throw an error. diff --git a/src/tests/setup/unit-setup.ts b/src/tests/setup/unit-setup.ts index 95be4782..692a5224 100644 --- a/src/tests/setup/unit-setup.ts +++ b/src/tests/setup/unit-setup.ts @@ -189,7 +189,7 @@ vi.mock('../../services/aiApiClient', () => ({ getQuickInsights: vi.fn(), getDeepDiveAnalysis: vi.fn(), searchWeb: vi.fn(), - planTripWithMaps: vi.fn(), +// planTripWithMaps: vi.fn(), generateImageFromText: vi.fn(), generateSpeechFromText: vi.fn(), startVoiceSession: vi.fn(),