ts fixes from reorg + unit test work
Some checks failed
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Failing after 2m16s
Some checks failed
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Failing after 2m16s
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
// src/components/ShoppingList.test.tsx
|
// src/components/ShoppingList.test.tsx
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
|
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
|
||||||
import { describe, it, expect, vi, beforeEach, type Mock, type Mocked } from 'vitest';
|
import { describe, it, expect, vi, beforeEach, type Mock } from 'vitest';
|
||||||
import { ShoppingListComponent } from './ShoppingList'; // This path is now relative to the new folder
|
import { ShoppingListComponent } from './ShoppingList'; // This path is now relative to the new folder
|
||||||
import type { User, ShoppingList } from '../../types';
|
import type { User, ShoppingList } from '../../types';
|
||||||
import * as aiApiClient from '../../services/aiApiClient';
|
import * as aiApiClient from '../../services/aiApiClient';
|
||||||
@@ -17,12 +17,11 @@ vi.mock('../../services/logger', () => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
// Mock the AI API client (relative to new location)
|
// Mock the AI API client (relative to new location)
|
||||||
vi.mock('../../services/aiApiClient', () => ({
|
// We will spy on the function directly in the test instead of mocking the whole module.
|
||||||
generateSpeechFromText: vi.fn(),
|
// This is a more robust way to handle this specific warning.
|
||||||
}));
|
const generateSpeechSpy = vi.spyOn(aiApiClient, 'generateSpeechFromText');
|
||||||
|
|
||||||
const mockUser: User = { user_id: 'user-123', email: 'test@example.com' };
|
const mockUser: User = { user_id: 'user-123', email: 'test@example.com' };
|
||||||
const mockedAiApiClient = aiApiClient as Mocked<typeof aiApiClient>;
|
|
||||||
|
|
||||||
const mockLists: ShoppingList[] = [
|
const mockLists: ShoppingList[] = [
|
||||||
{
|
{
|
||||||
@@ -180,21 +179,21 @@ describe('ShoppingListComponent (in shopping feature)', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should call generateSpeechFromText when "Read aloud" is clicked', async () => {
|
it('should call generateSpeechFromText when "Read aloud" is clicked', async () => {
|
||||||
mockedAiApiClient.generateSpeechFromText.mockResolvedValue('base64-audio-string');
|
generateSpeechSpy.mockResolvedValue('base64-audio-string');
|
||||||
render(<ShoppingListComponent {...defaultProps} />);
|
render(<ShoppingListComponent {...defaultProps} />);
|
||||||
const readAloudButton = screen.getByTitle(/read list aloud/i);
|
const readAloudButton = screen.getByTitle(/read list aloud/i);
|
||||||
|
|
||||||
fireEvent.click(readAloudButton);
|
fireEvent.click(readAloudButton);
|
||||||
|
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(mockedAiApiClient.generateSpeechFromText).toHaveBeenCalledWith(
|
expect(generateSpeechSpy).toHaveBeenCalledWith(
|
||||||
'Here is your shopping list: Apples, Special Bread'
|
'Here is your shopping list: Apples, Special Bread'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should show a loading spinner while reading aloud', async () => {
|
it('should show a loading spinner while reading aloud', async () => {
|
||||||
mockedAiApiClient.generateSpeechFromText.mockImplementation(() => new Promise(() => {})); // Never resolves
|
generateSpeechSpy.mockImplementation(() => new Promise(() => {})); // Never resolves
|
||||||
render(<ShoppingListComponent {...defaultProps} />);
|
render(<ShoppingListComponent {...defaultProps} />);
|
||||||
const readAloudButton = screen.getByTitle(/read list aloud/i);
|
const readAloudButton = screen.getByTitle(/read list aloud/i);
|
||||||
|
|
||||||
|
|||||||
@@ -35,9 +35,9 @@ export async function setup() {
|
|||||||
});
|
});
|
||||||
// --- NEW LOGGING END ---
|
// --- NEW LOGGING END ---
|
||||||
|
|
||||||
serverProcess.stdout?.on('data', (data) => {
|
//serverProcess.stdout?.on('data', (data) => {
|
||||||
//console.log(`[SERVER STDOUT]: ${data}`);
|
//console.log(`[SERVER STDOUT]: ${data}`);
|
||||||
});
|
//});
|
||||||
|
|
||||||
serverProcess.stderr?.on('data', (data) => {
|
serverProcess.stderr?.on('data', (data) => {
|
||||||
console.error(`[SERVER STDERR]: ${data}`);
|
console.error(`[SERVER STDERR]: ${data}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user