Addresses QA concern: boundary values (0, 4, 7, 9, 10) now have explicit tests covering description labels and aria-valuenow. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
75 lines
2.9 KiB
TypeScript
75 lines
2.9 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { render, screen } from '@testing-library/svelte';
|
|
import VarietyScoreHero from './VarietyScoreHero.svelte';
|
|
|
|
describe('VarietyScoreHero', () => {
|
|
it('renders the score number', () => {
|
|
render(VarietyScoreHero, { props: { score: 8.2 } });
|
|
expect(screen.getByTestId('score-value').textContent).toContain('8.2');
|
|
});
|
|
|
|
it('renders "out of 10" label', () => {
|
|
render(VarietyScoreHero, { props: { score: 8.2 } });
|
|
expect(screen.getByTestId('score-label').textContent).toContain('10');
|
|
});
|
|
|
|
it('renders a progressbar with correct aria attributes', () => {
|
|
render(VarietyScoreHero, { props: { score: 8.2 } });
|
|
const bar = screen.getByRole('progressbar');
|
|
expect(bar.getAttribute('aria-valuenow')).toBe('8.2');
|
|
expect(bar.getAttribute('aria-valuemin')).toBe('0');
|
|
expect(bar.getAttribute('aria-valuemax')).toBe('10');
|
|
});
|
|
|
|
it('shows "Excellent variety" description for score >= 9', () => {
|
|
render(VarietyScoreHero, { props: { score: 9.5 } });
|
|
expect(screen.getByTestId('score-description').textContent).toContain('Ausgezeichnet');
|
|
});
|
|
|
|
it('shows "Good variety" description for score 7-8.9', () => {
|
|
render(VarietyScoreHero, { props: { score: 7.5 } });
|
|
expect(screen.getByTestId('score-description').textContent).toContain('Gut');
|
|
});
|
|
|
|
it('shows "Getting there" description for score 4-6.9', () => {
|
|
render(VarietyScoreHero, { props: { score: 5.0 } });
|
|
expect(screen.getByTestId('score-description').textContent).toContain('Verbesserbar');
|
|
});
|
|
|
|
it('shows "Needs improvement" description for score < 4', () => {
|
|
render(VarietyScoreHero, { props: { score: 2.1 } });
|
|
expect(screen.getByTestId('score-description').textContent).toContain('Unzureichend');
|
|
});
|
|
|
|
it('shows "Unzureichend" for score = 0 (boundary)', () => {
|
|
render(VarietyScoreHero, { props: { score: 0 } });
|
|
expect(screen.getByTestId('score-description').textContent).toContain('Unzureichend');
|
|
});
|
|
|
|
it('renders score 0 in score-value for score = 0', () => {
|
|
render(VarietyScoreHero, { props: { score: 0 } });
|
|
expect(screen.getByTestId('score-value').textContent).toContain('0');
|
|
});
|
|
|
|
it('renders 0-width progress bar for score = 0', () => {
|
|
render(VarietyScoreHero, { props: { score: 0 } });
|
|
const bar = screen.getByRole('progressbar');
|
|
expect(bar.getAttribute('aria-valuenow')).toBe('0');
|
|
});
|
|
|
|
it('shows "Ausgezeichnet" for score = 10 (boundary)', () => {
|
|
render(VarietyScoreHero, { props: { score: 10 } });
|
|
expect(screen.getByTestId('score-description').textContent).toContain('Ausgezeichnet');
|
|
});
|
|
|
|
it('shows "Verbesserbar" for score = 4 (boundary)', () => {
|
|
render(VarietyScoreHero, { props: { score: 4 } });
|
|
expect(screen.getByTestId('score-description').textContent).toContain('Verbesserbar');
|
|
});
|
|
|
|
it('shows "Gut" for score = 7 (boundary)', () => {
|
|
render(VarietyScoreHero, { props: { score: 7 } });
|
|
expect(screen.getByTestId('score-description').textContent).toContain('Gut');
|
|
});
|
|
});
|