refactor: chord guide system

This commit is contained in:
Xiaohan-Tian
2026-05-28 22:52:58 -07:00
parent ad17263b82
commit 72297cb731
16 changed files with 783 additions and 48 deletions
@@ -0,0 +1,59 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import ChordGuideSettings from './ChordGuideSettings';
const configState = new Map<string, unknown>([
['chord_guide.chord_definition', ''],
]);
const configManagerMock = {
getIsInitialized: vi.fn(() => true),
initialize: vi.fn().mockResolvedValue(undefined),
get: vi.fn((key: string) => configState.get(key)),
set: vi.fn(async (key: string, value: unknown) => {
configState.set(key, value);
}),
};
vi.mock('../../../core/config/ConfigManager', () => ({
ConfigManager: {
instance: () => configManagerMock,
},
}));
vi.mock('../../../util/scaleUtil', async () => {
const actual = await vi.importActual<typeof import('../../../util/scaleUtil')>('../../../util/scaleUtil');
return {
...actual,
validateFunctionalChordsJSON: vi.fn(() => ({ valid: true, errors: [] })),
};
});
vi.mock('../../../util/dialogUtil', () => ({
showAlert: vi.fn(),
}));
vi.mock('../../../core/KGCore', () => ({
KGCore: {
ORIGINAL_FUNCTIONAL_CHORDS_DATA: {},
FUNCTIONAL_CHORDS_DATA: {},
},
}));
describe('ChordGuideSettings', () => {
beforeEach(() => {
configState.set('chord_guide.chord_definition', '');
configManagerMock.get.mockClear();
configManagerMock.set.mockClear();
});
it('renders the legacy notice for chord guide definitions', async () => {
render(<ChordGuideSettings />);
expect(await screen.findByText('Legacy Chord Definition')).toBeTruthy();
expect(
screen.getByText(/no longer affects chord-guide suggestions in the piano roll/i)
).toBeTruthy();
});
});
@@ -113,7 +113,10 @@ const ChordGuideSettings: React.FC = () => {
<div className="settings-section-content">
<div className="settings-group">
<h4>Chord Definition</h4>
<h4>Legacy Chord Definition</h4>
<div className="settings-help" style={{ fontSize: '12px', color: '#888', marginBottom: '8px' }}>
This editor is kept for legacy mode and highlighting behavior. It no longer affects chord-guide suggestions in the piano roll.
</div>
<div className="settings-help-links">
<button
className="settings-help"
@@ -132,7 +135,7 @@ const ChordGuideSettings: React.FC = () => {
<div className="settings-item">
<textarea
className="settings-textarea"
placeholder="Please input your chord definitions"
placeholder="Please input your legacy chord definitions"
rows={8}
value={chordDefinition}
onChange={(e) => handleChordDefinitionChange(e.target.value)}