From abe8ab8668d6cc5f229a7118775e917b65edd2c9 Mon Sep 17 00:00:00 2001 From: Marcel Date: Thu, 7 May 2026 19:05:46 +0200 Subject: [PATCH] refactor(comment): remove dead findAnnotationIdsByIds; fix aria-label i18n; rename misleading test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove `findAnnotationIdsByIds` from CommentService — no production caller exists now that DashboardService uses `findDataByIds` directly; along with its test coverage - Fix aria-label construction in ChronikRow: pass actorName to i18n message function instead of manually prepending the actor, so all locales render correctly - Rename `findDataByIds_does_not_truncate_at_exactly_120_chars` → `findDataByIds_preserves_content_at_exactly_120_chars` for accurate description Co-Authored-By: Claude Sonnet 4.6 --- .../document/comment/CommentService.java | 7 --- .../document/comment/CommentServiceTest.java | 60 +------------------ frontend/src/lib/activity/ChronikRow.svelte | 2 +- 3 files changed, 2 insertions(+), 67 deletions(-) diff --git a/backend/src/main/java/org/raddatz/familienarchiv/document/comment/CommentService.java b/backend/src/main/java/org/raddatz/familienarchiv/document/comment/CommentService.java index 2fccb84a..0dc149af 100644 --- a/backend/src/main/java/org/raddatz/familienarchiv/document/comment/CommentService.java +++ b/backend/src/main/java/org/raddatz/familienarchiv/document/comment/CommentService.java @@ -24,7 +24,6 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.UUID; -import java.util.stream.Collectors; @Service @RequiredArgsConstructor @@ -49,12 +48,6 @@ public class CommentService { return result; } - public Map findAnnotationIdsByIds(Collection commentIds) { - return findDataByIds(commentIds).entrySet().stream() - .filter(e -> e.getValue().annotationId() != null) - .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().annotationId())); - } - private String stripAndTruncate(String html) { if (html == null || html.isBlank()) return ""; String text = Jsoup.parse(html).text().trim(); diff --git a/backend/src/test/java/org/raddatz/familienarchiv/document/comment/CommentServiceTest.java b/backend/src/test/java/org/raddatz/familienarchiv/document/comment/CommentServiceTest.java index 897b1e34..bd514b2e 100644 --- a/backend/src/test/java/org/raddatz/familienarchiv/document/comment/CommentServiceTest.java +++ b/backend/src/test/java/org/raddatz/familienarchiv/document/comment/CommentServiceTest.java @@ -676,7 +676,7 @@ class CommentServiceTest { } @Test - void findDataByIds_does_not_truncate_at_exactly_120_chars() { + void findDataByIds_preserves_content_at_exactly_120_chars() { UUID id = UUID.randomUUID(); String text120 = "a".repeat(120); when(commentRepository.findAllById(List.of(id))) @@ -740,64 +740,6 @@ class CommentServiceTest { assertThat(commentService.findDataByIds(List.of(id)).get(id).annotationId()).isNull(); } - // ─── findAnnotationIdsByIds ─────────────────────────────────────────────── - - @Test - void findAnnotationIdsByIds_returnsMap_forKnownIds() { - UUID commentA = UUID.randomUUID(); - UUID annotationA = UUID.randomUUID(); - UUID commentB = UUID.randomUUID(); - UUID annotationB = UUID.randomUUID(); - when(commentRepository.findAllById(List.of(commentA, commentB))) - .thenReturn(List.of( - DocumentComment.builder().id(commentA).annotationId(annotationA).build(), - DocumentComment.builder().id(commentB).annotationId(annotationB).build() - )); - - assertThat(commentService.findAnnotationIdsByIds(List.of(commentA, commentB))) - .containsOnly( - java.util.Map.entry(commentA, annotationA), - java.util.Map.entry(commentB, annotationB) - ); - } - - @Test - void findAnnotationIdsByIds_returnsEmptyMap_forEmptyInput() { - assertThat(commentService.findAnnotationIdsByIds(List.of())).isEmpty(); - verify(commentRepository, never()).findAllById(anyList()); - } - - @Test - void findAnnotationIdsByIds_omitsUnknownIds() { - UUID known = UUID.randomUUID(); - UUID knownAnnotation = UUID.randomUUID(); - UUID missing = UUID.randomUUID(); - when(commentRepository.findAllById(List.of(known, missing))) - .thenReturn(List.of( - DocumentComment.builder().id(known).annotationId(knownAnnotation).build() - )); - - assertThat(commentService.findAnnotationIdsByIds(List.of(known, missing))) - .containsOnly(java.util.Map.entry(known, knownAnnotation)) - .doesNotContainKey(missing); - } - - @Test - void findAnnotationIdsByIds_omitsCommentsWithNullAnnotationId() { - UUID legacy = UUID.randomUUID(); - UUID block = UUID.randomUUID(); - UUID annotation = UUID.randomUUID(); - when(commentRepository.findAllById(List.of(legacy, block))) - .thenReturn(List.of( - DocumentComment.builder().id(legacy).annotationId(null).build(), - DocumentComment.builder().id(block).annotationId(annotation).build() - )); - - assertThat(commentService.findAnnotationIdsByIds(List.of(legacy, block))) - .containsOnly(java.util.Map.entry(block, annotation)) - .doesNotContainKey(legacy); - } - private void stubBlock(UUID docId, UUID blockId) { when(transcriptionService.getBlock(docId, blockId)) .thenReturn(TranscriptionBlock.builder() diff --git a/frontend/src/lib/activity/ChronikRow.svelte b/frontend/src/lib/activity/ChronikRow.svelte index 2b2cb904..22e47d13 100644 --- a/frontend/src/lib/activity/ChronikRow.svelte +++ b/frontend/src/lib/activity/ChronikRow.svelte @@ -109,7 +109,7 @@ const rowHref: string = $derived( href={rowHref} data-variant={variant} aria-label={variant === 'comment' && item.commentPreview - ? `${actorName} ${m.chronik_comment_added({ actor: '', doc: docTitle }).trim()} — ${item.commentPreview}` + ? `${m.chronik_comment_added({ actor: actorName, doc: docTitle })} — ${item.commentPreview}` : undefined} class="group flex items-start gap-3 p-3 transition-colors hover:bg-muted/50 focus-visible:ring-2 focus-visible:ring-focus-ring focus-visible:outline-none {variant === 'for-you' ? 'border-l-[3px] border-accent bg-accent-bg/10' : ''}"