feat(web): TrackMenuItem primitive for M7 #372
Single-entry button used by TrackMenu. Supports aria-disabled (kept visible to preserve menu height when admin-only or pre-#352 entries are non-functional) and a `danger` flag for the oxblood-tinted "Remove from library" entry.
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import { describe, test, expect, vi } from 'vitest';
|
||||
import { render, fireEvent, screen } from '@testing-library/svelte';
|
||||
import { Music2 } from 'lucide-svelte';
|
||||
import TrackMenuItem from './TrackMenuItem.svelte';
|
||||
|
||||
describe('TrackMenuItem', () => {
|
||||
test('renders icon, label, and fires onclick', async () => {
|
||||
const onclick = vi.fn();
|
||||
render(TrackMenuItem, { props: { icon: Music2, label: 'Play next', onclick } });
|
||||
const btn = screen.getByRole('menuitem', { name: /play next/i });
|
||||
await fireEvent.click(btn);
|
||||
expect(onclick).toHaveBeenCalledOnce();
|
||||
expect(btn.getAttribute('aria-disabled')).toBe('false');
|
||||
});
|
||||
|
||||
test('aria-disabled blocks onclick and reflects in DOM', async () => {
|
||||
const onclick = vi.fn();
|
||||
render(TrackMenuItem, {
|
||||
props: { icon: Music2, label: 'Add to playlist…', onclick, disabled: true, title: 'Coming with playlists' },
|
||||
});
|
||||
const btn = screen.getByRole('menuitem', { name: /add to playlist/i });
|
||||
expect(btn.getAttribute('aria-disabled')).toBe('true');
|
||||
expect(btn.getAttribute('title')).toBe('Coming with playlists');
|
||||
await fireEvent.click(btn);
|
||||
expect(onclick).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user