From 57521cc28b0f8bfd03585fceceb2d600bf8b1456 Mon Sep 17 00:00:00 2001
From: Nessar
Date: Sat, 14 Nov 2026 16:07:03 +0100
Subject: [PATCH] test(date-comparison): wait for the dialog's initial focus
before the retry focus check
The retry test recorded document.activeElement right after clicking Retry
and expected the arriving result not to move focus. MatDialog defaults to
delayFocusTrap, so autoFocus 'first-heading' moves focus to the title only
after the 150 ms opening animation timer and the next render. The test
usually finished just before that timer fired, so it compared body with
body. Under load the timer fired while job(2) was being polled, and the
final detectChanges ran the pending afterNextRender. Focus then moved from
body to #counterfactual-title and the assertion failed, even though the
result had not moved focus.
Wait for the title to receive focus, as the first test does, before taking
the snapshot. The assertion now checks that the result leaves the dialog's
settled focus on the title.
Co-Authored-By: Claude Opus 5.5
---
src/app/components/date-comparison/date-comparison.spec.ts | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/app/components/date-comparison/date-comparison.spec.ts b/src/app/components/date-comparison/date-comparison.spec.ts
index 57e3efb..6dc1cb9 100644
--- a/src/app/components/date-comparison/date-comparison.spec.ts
+++ b/src/app/components/date-comparison/date-comparison.spec.ts
@@ -447,6 +447,10 @@ describe('DateComparison', () => {
fixture.detectChanges();
expect(document.querySelector('.comparison-loading')).not.toBeNull();
expect(comparison.failed()).toBe(false);
+ // The dialog focuses its title only after its opening animation; let that settle first.
+ await vi.waitFor(() =>
+ expect(document.activeElement).toBe(document.getElementById('counterfactual-title')),
+ );
const focusedBeforeResult = document.activeElement;
(await job(2)).emit({
type: 'counterfactual-result',