Files
ReadMeABook/tests/components/audiobooks/AudiobookGrid.test.tsx
T
kikootwo 2c9097f6b0 Update README quick-start and adjust tests
Add a Quick Start docker-compose snippet and simplify the Manual Setup instruction in README; also replace three screenshot assets. Update multiple audiobook component tests to match recent UI changes: adjust expected button/notification text (e.g. 'Sign in to Request', 'Request created!'), change selectors for close/interactive controls, add PreferencesContext mock, reflect processing overlay and pending/denied status behavior, and update skeleton loader count (8 -> 10). These edits keep tests aligned with the current UI and improve getting-started docs.
2026-02-05 12:22:26 -05:00

56 lines
1.7 KiB
TypeScript

/**
* Component: Audiobook Grid Tests
* Documentation: documentation/frontend/components.md
*/
// @vitest-environment jsdom
import React from 'react';
import path from 'path';
import { render, screen } from '@testing-library/react';
import { beforeEach, describe, expect, it, vi } from 'vitest';
const mockAudiobookCard = () => {
vi.doMock(path.resolve('src/components/audiobooks/AudiobookCard.tsx'), () => ({
AudiobookCard: ({ audiobook }: { audiobook: any }) => (
<div data-testid="audiobook-card">{audiobook.asin}</div>
),
}));
};
describe('AudiobookGrid', () => {
beforeEach(() => {
vi.resetModules();
mockAudiobookCard();
});
it('renders skeleton cards when loading', async () => {
const { AudiobookGrid } = await import('@/components/audiobooks/AudiobookGrid');
const { container } = render(<AudiobookGrid audiobooks={[]} isLoading={true} />);
expect(container.querySelectorAll('.animate-pulse')).toHaveLength(10);
});
it('shows the empty message when there are no results', async () => {
const { AudiobookGrid } = await import('@/components/audiobooks/AudiobookGrid');
render(<AudiobookGrid audiobooks={[]} isLoading={false} emptyMessage="Nothing found" />);
expect(screen.getByText('Nothing found')).toBeInTheDocument();
});
it('applies grid classes based on card size', async () => {
const { AudiobookGrid } = await import('@/components/audiobooks/AudiobookGrid');
const { container } = render(
<AudiobookGrid
audiobooks={[{ asin: 'a1', title: 'Book', author: 'Author' }]}
cardSize={9}
/>
);
expect(container.querySelector('div')?.className).toContain('grid-cols-1');
});
});