Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

3.9 KB
Raw Blame
import { describe, it, expect } from 'vitest';
import { render } from '@testing-library/react';
import ChordDiagram from './ChordDiagram.jsx';

describe('ChordDiagram', () => {
  it('renders a 6-string fretbox for guitar with muted/open markers and dots', () => {
    const { container } = render(<ChordDiagram name="Am" instrument="guitar" />);
    const svg = container.querySelector('svg');
    expect(svg).toBeTruthy();
    // Am = x02210 → 1 muted marker (×), 2 open circles, 3 finger dots.
    expect(container.textContent).toContain('×');
    const dots = svg.querySelectorAll('g circle');
    expect(dots.length).toBe(3);
    // First position — no window label.
    expect(svg.textContent).not.toMatch(/fr/);
  });

  it('provides an accessible fret description for guitar voicings', () => {
    const { container } = render(<ChordDiagram name="Am" instrument="guitar" />);
    const description = container.querySelector('.sr-only');
    expect(description).toHaveTextContent(
      'guitar chord voicing. string 6: muted, string 5: open, string 4: fret 2, string 3: fret 2, string 2: fret 1, string 1: open.',
    );
  });

  it('labels the fret window for shapes above the nut', () => {
    // C#m7 = A-form barre at fret 4.
    const { container } = render(<ChordDiagram name="C#m7" instrument="guitar" />);
    expect(container.textContent).toContain('4fr');
  });

  it('renders a 4-string fretbox for ukulele', () => {
    // G7 = 0212 → 4 strings, 3 dots, 1 open marker.
    const { container } = render(<ChordDiagram name="G7" instrument="ukulele" />);
    const svg = container.querySelector('svg');
    expect(svg).toBeTruthy();
    expect(svg.querySelectorAll('g circle').length).toBe(3);
    expect(container.textContent).not.toContain('×');
  });

  it('provides an accessible fret description for ukulele voicings', () => {
    const { container } = render(<ChordDiagram name="G7" instrument="ukulele" />);
    expect(container.querySelector('.sr-only')).toHaveTextContent(
      'ukulele chord voicing. string 4: open, string 3: fret 2, string 2: fret 1, string 1: fret 2.',
    );
  });

  it('renders piano voicings as note chips, prepending the slash bass', () => {
    const { container } = render(<ChordDiagram name="Am/G" instrument="piano" />);
    expect(container.querySelector('svg')).toBeNull();
    expect(container.textContent).toContain('A');
    expect(container.textContent).toContain('C');
    expect(container.textContent).toContain('E');
    expect(container.textContent).toContain('G');
    expect(container.textContent).toContain('bass');
    // Bass chip comes first.
    expect(container.textContent.indexOf('G')).toBeLessThan(container.textContent.indexOf('A'));
  });

  it('shows the slash-bass hint under string-instrument diagrams', () => {
    const { container } = render(<ChordDiagram name="G/B" instrument="guitar" />);
    expect(container.textContent).toContain('/B bass');
  });

  it('degrades to a muted fallback for unknown chords — no crash', () => {
    const { container } = render(<ChordDiagram name="Zq7" instrument="guitar" />);
    expect(container.querySelector('svg')).toBeNull();
    expect(container.textContent).toContain('no diagram');
  });

  it('renders one labeled voicing per segment for dash-joined chords (Am-Am7)', () => {
    const { container } = render(<ChordDiagram name="Am-Am7" instrument="guitar" />);
    expect(container.querySelectorAll('svg')).toHaveLength(2);
    expect(container.textContent).toContain('Am');
    expect(container.textContent).toContain('Am7');
    expect(container.textContent).not.toContain('no diagram');
  });

  it('dash-joined chords render piano chip rows per segment too', () => {
    const { container } = render(<ChordDiagram name="E-Em7" instrument="piano" />);
    // E → E G# B; Em7 → E G B D — both segments produce note chips.
    expect(container.textContent).toContain('G#');
    expect(container.textContent).toContain('D');
  });
});