fix: added missing i18n labels
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import React from 'react';
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { render } from '@testing-library/react';
|
||||
import { fireEvent, render, screen } from '@testing-library/react';
|
||||
import TrackInfoItem from './TrackInfoItem';
|
||||
import { KGAudioTrack } from '../../core/track/KGAudioTrack';
|
||||
import { showConfirm } from '../../util/dialogUtil';
|
||||
import { translate } from '../../i18n/translate';
|
||||
|
||||
const storeState = {
|
||||
selectedTrackId: null as string | null,
|
||||
@@ -24,8 +26,31 @@ vi.mock('../../stores/projectStore', () => ({
|
||||
),
|
||||
}));
|
||||
|
||||
vi.mock('../../i18n/useI18n', async () => {
|
||||
const { translate } = await import('../../i18n/translate');
|
||||
return {
|
||||
useI18n: () => ({
|
||||
t: (key: string, params?: Record<string, string | number>) => translate(key, params, 'zh_cn'),
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock('../common/KGDropdown', () => ({
|
||||
default: () => null,
|
||||
default: ({ options, isOpen, onChange }: { options: Array<string | { label: string; value: string }>; isOpen?: boolean; onChange: (value: string) => void }) => (
|
||||
isOpen ? (
|
||||
<div>
|
||||
{options.map((option) => {
|
||||
const value = typeof option === 'string' ? option : option.value;
|
||||
const label = typeof option === 'string' ? option : option.label;
|
||||
return (
|
||||
<button key={value} type="button" onClick={() => onChange(value)}>
|
||||
{label}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
) : null
|
||||
),
|
||||
}));
|
||||
|
||||
vi.mock('../common/FileImportModal', () => ({
|
||||
@@ -49,6 +74,7 @@ describe('TrackInfoItem audio import', () => {
|
||||
storeState.toggleInstrumentSelectionForTrack.mockReset();
|
||||
storeState.importAudioToTrack.mockReset();
|
||||
storeState.setTrackAutomationView.mockReset();
|
||||
vi.mocked(showConfirm).mockReset();
|
||||
});
|
||||
|
||||
it('advertises m4a support in the track audio import modal', () => {
|
||||
@@ -72,4 +98,33 @@ describe('TrackInfoItem audio import', () => {
|
||||
|
||||
expect(fileImportModalProps?.acceptedTypes).toEqual(['.wav', '.mp3', '.ogg', '.flac', '.aac', '.m4a']);
|
||||
});
|
||||
|
||||
it('uses the localized delete-track confirmation message', () => {
|
||||
const audioTrack = new KGAudioTrack('钢琴', 1);
|
||||
audioTrack.setTrackIndex(0);
|
||||
storeState.tracks = [audioTrack];
|
||||
|
||||
vi.mocked(showConfirm).mockResolvedValue(false);
|
||||
|
||||
render(
|
||||
<TrackInfoItem
|
||||
track={audioTrack}
|
||||
index={0}
|
||||
isDragging={false}
|
||||
isDragOver={false}
|
||||
onTrackNameEdit={vi.fn()}
|
||||
onDragStart={vi.fn()}
|
||||
onDragOver={vi.fn()}
|
||||
onDrop={vi.fn()}
|
||||
onDragEnd={vi.fn()}
|
||||
/>
|
||||
);
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: '更多操作' }));
|
||||
fireEvent.click(screen.getByRole('button', { name: '删除轨道' }));
|
||||
|
||||
expect(showConfirm).toHaveBeenCalledWith(
|
||||
translate('track.controls.settings.deleteTrackConfirm', { name: '钢琴' }, 'zh_cn')
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user