A try of overhauling the frontend tests, bailed after 24h+
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import SummaryCards from '../../../../src/components/stats/SummaryCards';
|
||||
|
||||
describe('SummaryCards', () => {
|
||||
const mockSummary = {
|
||||
total_sleeps: 10,
|
||||
avg_sleeps_per_day: 2.5,
|
||||
total_sleeps_all_time: 100,
|
||||
avg_sleeps_per_day_all_time: 2.5,
|
||||
};
|
||||
|
||||
it('renders null when no summary is provided', () => {
|
||||
const { container } = render(<SummaryCards summary={undefined} />);
|
||||
expect(container.firstChild).toBeNull();
|
||||
});
|
||||
|
||||
it('renders all summary data correctly', () => {
|
||||
render(<SummaryCards summary={mockSummary} />);
|
||||
|
||||
expect(screen.getByText('10')).toBeInTheDocument();
|
||||
const avgSleeps = screen.getAllByText('2.5');
|
||||
expect(avgSleeps).toHaveLength(2);
|
||||
expect(screen.getByText('100')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('displays correct labels', () => {
|
||||
render(<SummaryCards summary={mockSummary} />);
|
||||
|
||||
expect(screen.getByText(/Total sleeps in period/i)).toBeInTheDocument();
|
||||
expect(screen.getByText(/Avg sleeps per day in period/i)).toBeInTheDocument();
|
||||
expect(screen.getByText(/Total sleeps \(all time\)/i)).toBeInTheDocument();
|
||||
expect(screen.getByText(/Avg sleeps per day \(all time\)/i)).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user