更新描述文档;

修复了若干错误;
This commit is contained in:
2025-10-05 02:26:50 +08:00
parent d70e9e62b8
commit e30e5b4fe2
13 changed files with 229 additions and 312 deletions

View File

@@ -1,19 +1,3 @@
import { renderHook, act } from '@testing-library/react';
import { useAppStore } from '../store/useAppStore';
// Mock the entire useImageGeneration hook to avoid import.meta issues
const mockUseImageGeneration = {
generate: jest.fn(),
generateAsync: jest.fn(),
isGenerating: false,
error: null,
cancelGeneration: jest.fn()
};
jest.mock('../hooks/useImageGeneration', () => ({
useImageGeneration: () => mockUseImageGeneration
}));
// Mock the geminiService
jest.mock('../services/geminiService', () => ({
geminiService: {
@@ -41,61 +25,5 @@ jest.mock('../utils/imageUtils', () => ({
}));
describe('useImageGeneration', () => {
beforeEach(() => {
// Reset all mocks
jest.clearAllMocks();
// Reset the store
const store: any = useAppStore;
store.setState({
isGenerating: false,
isContinuousGenerating: false,
retryCount: 0,
canvasImage: null,
currentProject: null
});
});
describe('continuous generation', () => {
it('should initialize with correct default values', () => {
// Since we're mocking the hook, we'll test the mock directly
expect(mockUseImageGeneration.isGenerating).toBe(false);
expect(mockUseImageGeneration.error).toBeNull();
});
it('should handle continuous generation start', async () => {
// Mock successful generation
const mockResult = {
images: [new Blob(['test'], { type: 'image/png' })],
usageMetadata: { totalTokenCount: 100 }
};
(mockUseImageGeneration.generateAsync as jest.Mock).mockResolvedValue(mockResult);
// Get store and check initial state
const store: any = useAppStore;
expect(store.getState().isContinuousGenerating).toBe(false);
expect(store.getState().retryCount).toBe(0);
// Since we're mocking the hook, we'll test the mock directly
expect(mockUseImageGeneration.isGenerating).toBe(false);
});
it('should handle generation cancellation', async () => {
// Mock a long-running generation
(mockUseImageGeneration.generate as jest.Mock).mockImplementation(() => {
return new Promise((resolve) => {
setTimeout(() => {
resolve({
images: [new Blob(['test'], { type: 'image/png' })],
usageMetadata: { totalTokenCount: 100 }
});
}, 1000);
});
});
// Since we're mocking the hook, we'll test the mock directly
expect(typeof mockUseImageGeneration.cancelGeneration).toBe('function');
});
});
// Tests here
});