diff --git a/web/src/components/NoteCard.test.tsx b/web/src/components/NoteCard.test.tsx index ac2744d..156c69c 100644 --- a/web/src/components/NoteCard.test.tsx +++ b/web/src/components/NoteCard.test.tsx @@ -44,9 +44,6 @@ describe('NoteCard', () => { expect(screen.getByText('Test Note')).toBeInTheDocument(); expect(screen.getByText('Faith')).toBeInTheDocument(); expect(screen.getByText('Prayer')).toBeInTheDocument(); - // Date formatting might depend on locale, but let's check basic presence - // 1/1/2023 or similar - // expect(screen.getByText(/2023/)).toBeInTheDocument(); }); it('navigates to note detail on card click', () => { @@ -62,7 +59,7 @@ describe('NoteCard', () => { expect(mockNavigate).toHaveBeenCalledWith('/notes/1'); }); - it('navigates on Enter key', () => { + it('navigates on Enter key and Space key', () => { render( @@ -70,9 +67,53 @@ describe('NoteCard', () => { ); const card = screen.getByRole('link'); - fireEvent.keyDown(card, { key: 'Enter', code: 'Enter' }); + fireEvent.keyDown(card, { key: 'Enter', code: 'Enter' }); expect(mockNavigate).toHaveBeenCalledWith('/notes/1'); + + fireEvent.keyDown(card, { key: ' ', code: 'Space' }); + expect(mockNavigate).toHaveBeenCalledTimes(2); + }); + + it('ignores other key presses', () => { + render( + + + + ); + + const card = screen.getByRole('link'); + fireEvent.keyDown(card, { key: 'A', code: 'KeyA' }); + + expect(mockNavigate).not.toHaveBeenCalled(); + }); + + it('renders untitled note if title is missing', () => { + render( + + + + ); + + expect(screen.getByText('Untitled Note')).toBeInTheDocument(); + }); + + it('renders correctly without tags', () => { + render( + + + + ); + expect(screen.queryByText('Faith')).not.toBeInTheDocument(); + }); + + it('renders empty tag list correctly', () => { + render( + + + + ); + expect(screen.queryByText('Faith')).not.toBeInTheDocument(); }); it('triggers actions without navigation', () => { @@ -88,7 +129,7 @@ describe('NoteCard', () => { fireEvent.click(deleteButton); expect(mockHandlers.onDelete).toHaveBeenCalledWith(mockNote); - expect(mockNavigate).not.toHaveBeenCalled(); // Should assume test isolation or clear mocks + expect(mockNavigate).not.toHaveBeenCalled(); fireEvent.click(shareButton); expect(mockHandlers.onShare).toHaveBeenCalledWith(mockNote); diff --git a/web/src/components/NoteCard.tsx b/web/src/components/NoteCard.tsx index 33ae409..547a054 100644 --- a/web/src/components/NoteCard.tsx +++ b/web/src/components/NoteCard.tsx @@ -60,6 +60,7 @@ export function NoteCard({ note, onDelete, onShare, onAskAI }: NoteCardProps) { onAskAI(note); }} title="Ask AI" + aria-label={`Ask AI about ${note.title || "Untitled Note"}`} > @@ -73,6 +74,7 @@ export function NoteCard({ note, onDelete, onShare, onAskAI }: NoteCardProps) { onShare(note); }} title="Share" + aria-label={`Share ${note.title || "Untitled Note"}`} > @@ -86,6 +88,7 @@ export function NoteCard({ note, onDelete, onShare, onAskAI }: NoteCardProps) { onDelete(note); }} title="Delete" + aria-label={`Delete ${note.title || "Untitled Note"}`} >