we went to mocks - now going to unit-setup.ts - centralized
Some checks failed
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Has been cancelled
Some checks failed
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Has been cancelled
This commit is contained in:
@@ -95,7 +95,7 @@ jobs:
|
|||||||
|
|
||||||
# --- Increase Node.js memory limit to prevent heap out of memory errors ---
|
# --- Increase Node.js memory limit to prevent heap out of memory errors ---
|
||||||
# This is crucial for memory-intensive tasks like running tests and coverage.
|
# This is crucial for memory-intensive tasks like running tests and coverage.
|
||||||
NODE_OPTIONS: "--max-old-space-size=4096"
|
NODE_OPTIONS: "--max-old-space-size=8192"
|
||||||
|
|
||||||
run: |
|
run: |
|
||||||
# Fail-fast check to ensure secrets are configured in Gitea for testing.
|
# Fail-fast check to ensure secrets are configured in Gitea for testing.
|
||||||
|
|||||||
@@ -112,16 +112,18 @@ describe('WatchedItemsList (in shopping feature)', () => {
|
|||||||
|
|
||||||
const itemsAsc = screen.getAllByRole('listitem');
|
const itemsAsc = screen.getAllByRole('listitem');
|
||||||
expect(itemsAsc[0]).toHaveTextContent('Apples');
|
expect(itemsAsc[0]).toHaveTextContent('Apples');
|
||||||
expect(itemsAsc[1]).toHaveTextContent('Bread');
|
expect(itemsAsc[1]).toHaveTextContent('Bread'); // This was a duplicate, fixed.
|
||||||
expect(itemsAsc[2]).toHaveTextContent('Milk');
|
expect(itemsAsc[2]).toHaveTextContent('Eggs');
|
||||||
|
expect(itemsAsc[3]).toHaveTextContent('Milk');
|
||||||
|
|
||||||
// Click to sort descending
|
// Click to sort descending
|
||||||
fireEvent.click(sortButton);
|
fireEvent.click(sortButton);
|
||||||
|
|
||||||
const itemsDesc = screen.getAllByRole('listitem');
|
const itemsDesc = screen.getAllByRole('listitem');
|
||||||
expect(itemsDesc[0]).toHaveTextContent('Milk');
|
expect(itemsDesc[0]).toHaveTextContent('Milk');
|
||||||
expect(itemsDesc[1]).toHaveTextContent('Bread');
|
expect(itemsDesc[1]).toHaveTextContent('Eggs');
|
||||||
expect(itemsDesc[2]).toHaveTextContent('Apples');
|
expect(itemsDesc[2]).toHaveTextContent('Bread');
|
||||||
|
expect(itemsDesc[3]).toHaveTextContent('Apples');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call onAddItemToList when plus icon is clicked', () => {
|
it('should call onAddItemToList when plus icon is clicked', () => {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// src/components/ProfileManager.test.tsx
|
// src/components/ProfileManager.test.tsx
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
|
import { render, screen, fireEvent, waitFor, cleanup } from '@testing-library/react';
|
||||||
import { describe, it, expect, vi, beforeEach, type Mock } from 'vitest';
|
import { describe, it, expect, vi, beforeEach, type Mock } from 'vitest';
|
||||||
import { ProfileManager } from './ProfileManager';
|
import { ProfileManager } from './ProfileManager';
|
||||||
import * as apiClient from '../../../services/apiClient';
|
import * as apiClient from '../../../services/apiClient';
|
||||||
@@ -364,7 +364,7 @@ const authenticatedProps = {
|
|||||||
|
|
||||||
describe('ProfileManager Authenticated User Features', () => {
|
describe('ProfileManager Authenticated User Features', () => {
|
||||||
// Restore all spies after each test to ensure isolation
|
// Restore all spies after each test to ensure isolation
|
||||||
afterEach(() => {
|
vi.afterEach(() => {
|
||||||
vi.restoreAllMocks();
|
vi.restoreAllMocks();
|
||||||
cleanup();
|
cleanup();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ describe('SystemCheck', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.clearAllMocks();
|
vi.clearAllMocks();
|
||||||
// Reset API client mocks to resolve successfully by default.
|
// Reset API client mocks to resolve successfully by default.
|
||||||
|
mockedApiClient.pingBackend.mockResolvedValue(new Response('pong'));
|
||||||
mockedApiClient.checkStorage.mockResolvedValue(new Response(JSON.stringify({ success: true, message: 'Storage OK' })));
|
mockedApiClient.checkStorage.mockResolvedValue(new Response(JSON.stringify({ success: true, message: 'Storage OK' })));
|
||||||
mockedApiClient.checkDbPoolHealth.mockResolvedValue(new Response(JSON.stringify({ success: true, message: 'DB Pool OK' })));
|
mockedApiClient.checkDbPoolHealth.mockResolvedValue(new Response(JSON.stringify({ success: true, message: 'DB Pool OK' })));
|
||||||
mockedApiClient.checkPm2Status.mockResolvedValue(new Response(JSON.stringify({ success: true, message: 'PM2 OK' })));
|
mockedApiClient.checkPm2Status.mockResolvedValue(new Response(JSON.stringify({ success: true, message: 'PM2 OK' })));
|
||||||
@@ -36,6 +37,11 @@ describe('SystemCheck', () => {
|
|||||||
import.meta.env.VITE_API_KEY = originalViteApiKey;
|
import.meta.env.VITE_API_KEY = originalViteApiKey;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Restore all mocks after each test to ensure test isolation.
|
||||||
|
afterEach(() => {
|
||||||
|
vi.restoreAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
// Helper to set VITE_API_KEY
|
// Helper to set VITE_API_KEY
|
||||||
const setViteApiKey = (value: string | undefined) => {
|
const setViteApiKey = (value: string | undefined) => {
|
||||||
import.meta.env.VITE_API_KEY = value;
|
import.meta.env.VITE_API_KEY = value;
|
||||||
@@ -68,19 +74,16 @@ describe('SystemCheck', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should show API key as failed if VITE_API_KEY is not set', async () => {
|
it('should show API key as failed if VITE_API_KEY is not set', async () => {
|
||||||
// The most reliable way to test this is to mock the implementation of the check itself.
|
// Set the API key to be undefined for this test.
|
||||||
// Directly modifying import.meta.env can be flaky in test environments.
|
setViteApiKey(undefined);
|
||||||
vi.spyOn(apiClient, 'pingBackend').mockImplementation(async () => {
|
|
||||||
// This check is synchronous in the component, but we can simulate its failure
|
|
||||||
// by throwing an error here, which prevents subsequent checks from running.
|
|
||||||
throw new Error('VITE_API_KEY is missing. Please add it to your .env file.');
|
|
||||||
});
|
|
||||||
|
|
||||||
render(<SystemCheck />);
|
render(<SystemCheck />);
|
||||||
|
|
||||||
// The component will catch the error and display it.
|
// The component should synchronously detect the missing key and display an error.
|
||||||
|
// Subsequent async checks will be skipped.
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(screen.getByText('VITE_API_KEY is missing. Please add it to your .env file.')).toBeInTheDocument();
|
expect(screen.getByText('VITE_API_KEY is missing. Please add it to your .env file.')).toBeInTheDocument();
|
||||||
|
// Verify that dependent checks are skipped.
|
||||||
|
expect(screen.getAllByText('Skipped: API key is not configured.').length).toBe(6);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user