20 lines
1.2 KiB
TypeScript
20 lines
1.2 KiB
TypeScript
import { fireEvent, render, screen } from '@testing-library/react';
|
|
import { afterEach, expect, it, vi } from 'vitest';
|
|
import { GameAudioFiles } from '../../src/pages/Chat/GameAudioFiles';
|
|
const mocks = vi.hoisted(() => ({ read: vi.fn() }));
|
|
vi.mock('@/lib/host-api', () => ({ hostApiFetch: mocks.read }));
|
|
afterEach(() => vi.unstubAllGlobals());
|
|
it('loads only saved local audio on explicit preview; never auto-plays or asks to save again', async () => {
|
|
const executionId = '00000000-0000-4000-8000-000000000601';
|
|
const relative = 'assets/generated/game-audio/00000000-0000-4000-8000-000000000601/sound-1.mp3';
|
|
mocks.read.mockResolvedValue({ path: relative, dataUrl: 'data:audio/mpeg;base64,SUQz' });
|
|
const { unmount } = render(<GameAudioFiles data={{ executionId, files: [{ index: 0, path: relative, bytes: 3 }] }} />);
|
|
expect(mocks.read).not.toHaveBeenCalled();
|
|
fireEvent.click(screen.getByRole('button', { name: '试听 sound-1.mp3' }));
|
|
const player = await screen.findByLabelText('试听 sound-1.mp3', { selector: 'audio' });
|
|
expect(player).toHaveAttribute('controls');
|
|
expect(player).not.toHaveAttribute('autoplay');
|
|
expect(mocks.read).toHaveBeenCalledWith('/api/coding/game-audio/' + executionId + '/outputs/0');
|
|
unmount();
|
|
});
|