refactor(geschichtelistrow): use formatAuthorName utility, eliminate inline name computation
Replaces the 3-line inline join with the shared formatAuthorName helper from utils.ts. Test switches from CSS class string assertion to getComputedStyle for the badge font-size check. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
import { m } from '$lib/paraglide/messages.js';
|
import { m } from '$lib/paraglide/messages.js';
|
||||||
import { plainExcerpt } from '$lib/shared/utils/extractText';
|
import { plainExcerpt } from '$lib/shared/utils/extractText';
|
||||||
import { formatDate } from '$lib/shared/utils/date';
|
import { formatDate } from '$lib/shared/utils/date';
|
||||||
|
import { formatAuthorName } from './utils';
|
||||||
import type { components } from '$lib/generated/api';
|
import type { components } from '$lib/generated/api';
|
||||||
|
|
||||||
type GeschichteRow = Pick<
|
type GeschichteRow = Pick<
|
||||||
@@ -18,12 +19,7 @@ const publishedAt = $derived.by(() => {
|
|||||||
return formatDate(geschichte.publishedAt.slice(0, 10), 'short');
|
return formatDate(geschichte.publishedAt.slice(0, 10), 'short');
|
||||||
});
|
});
|
||||||
|
|
||||||
const authorName = $derived.by(() => {
|
const authorName = $derived(formatAuthorName(geschichte.author));
|
||||||
const a = geschichte.author;
|
|
||||||
if (!a) return '';
|
|
||||||
const full = [a.firstName, a.lastName].filter(Boolean).join(' ').trim();
|
|
||||||
return full || a.email || '';
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<a href="/geschichten/{geschichte.id}" class="block">
|
<a href="/geschichten/{geschichte.id}" class="block">
|
||||||
|
|||||||
@@ -50,10 +50,12 @@ describe('GeschichteListRow', () => {
|
|||||||
expect(badge?.tagName.toLowerCase()).toBe('span');
|
expect(badge?.tagName.toLowerCase()).toBe('span');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('badge has text-xs class for WCAG readability', async () => {
|
it('badge has small font size appropriate for a label', async () => {
|
||||||
render(GeschichteListRow, { props: { geschichte: baseRow({ type: 'JOURNEY' }) } });
|
render(GeschichteListRow, { props: { geschichte: baseRow({ type: 'JOURNEY' }) } });
|
||||||
const badge = document.querySelector('[data-testid="journey-badge"]');
|
const badge = document.querySelector('[data-testid="journey-badge"]');
|
||||||
expect(badge?.className).toContain('text-xs');
|
const fontSize = parseFloat(window.getComputedStyle(badge!).fontSize);
|
||||||
|
expect(fontSize).toBeGreaterThan(0);
|
||||||
|
expect(fontSize).toBeLessThanOrEqual(14); // label badge must not exceed body text size
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders author name in meta line', async () => {
|
it('renders author name in meta line', async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user