From cb6a65048139ebe68612af451d4775803a53f898 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 7 May 2026 16:26:36 +0000 Subject: [PATCH 1/2] Stabilize bUnit waits in flaky tests Agent-Logs-Url: https://github.com/danielchalmers/JournalApp/sessions/a94b06ad-ecec-4243-8546-0a5397c67402 Co-authored-by: danielchalmers <7112040+danielchalmers@users.noreply.github.com> --- JournalApp.Tests/IndexTests.razor | 8 ++++---- JournalApp.Tests/JaTestContext.cs | 2 ++ JournalApp.Tests/ManageCategoriesTests.razor | 11 +++++++---- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/JournalApp.Tests/IndexTests.razor b/JournalApp.Tests/IndexTests.razor index ed17048..5ef8cdf 100644 --- a/JournalApp.Tests/IndexTests.razor +++ b/JournalApp.Tests/IndexTests.razor @@ -83,8 +83,8 @@ // Go back to trigger save of current day state. layout.Find(".day-switcher-back").Click(); - layout.WaitForAssertion(() => selectedDayNumber().Should().Be(originalDayNumber - 1)); - layout.WaitForAssertion(() => weightInput().GetAttribute("value").Should().NotBe("-1")); + layout.WaitForAssertion(() => selectedDayNumber().Should().Be(originalDayNumber - 1), DefaultUiWaitTimeout); + layout.WaitForAssertion(() => weightInput().GetAttribute("value").Should().NotBe("-1"), DefaultUiWaitTimeout); // Validate persistence in a fresh db context, not just the currently tracked entity. using (var db = dbf.CreateDbContext()) @@ -96,10 +96,10 @@ // Return to original day and ensure UI reflects saved value. layout.Find(".day-switcher-forward").Click(); - layout.WaitForAssertion(() => selectedDayNumber().Should().Be(originalDayNumber)); + layout.WaitForAssertion(() => selectedDayNumber().Should().Be(originalDayNumber), DefaultUiWaitTimeout); // Assert that the weight is back to it's changed value from the original day. - layout.WaitForAssertion(() => weightInput().GetAttribute("value").Should().Be("-1")); + layout.WaitForAssertion(() => weightInput().GetAttribute("value").Should().Be("-1"), DefaultUiWaitTimeout); } [Theory] diff --git a/JournalApp.Tests/JaTestContext.cs b/JournalApp.Tests/JaTestContext.cs index b69b391..5700d64 100644 --- a/JournalApp.Tests/JaTestContext.cs +++ b/JournalApp.Tests/JaTestContext.cs @@ -6,10 +6,12 @@ namespace JournalApp.Tests; public abstract class JaTestContext : BunitContext, IAsyncLifetime { + protected static readonly TimeSpan DefaultUiWaitTimeout = TimeSpan.FromSeconds(10); private SqliteConnection _dbConnection; public virtual Task InitializeAsync() { + DefaultWaitTimeout = DefaultUiWaitTimeout; Services.AddLogging(); Services.AddCommonJournalAppServices(); Services.AddSingleton(); diff --git a/JournalApp.Tests/ManageCategoriesTests.razor b/JournalApp.Tests/ManageCategoriesTests.razor index d190f19..d152abc 100644 --- a/JournalApp.Tests/ManageCategoriesTests.razor +++ b/JournalApp.Tests/ManageCategoriesTests.razor @@ -106,7 +106,8 @@ // Submit changes and confirm they have changed on the main list. layout.Find(".category-dialog .submit-button").Click(); - layout.Find($"#manage-category-{guid} > .manage-category-edit-button").TextContent.Should().Be("New name"); + layout.WaitForAssertion(() => + layout.Find($"#manage-category-{guid} > .manage-category-edit-button").TextContent.Should().Be("New name")); } [Fact] @@ -175,7 +176,8 @@ // Submit changes and confirm there is a new category in the list. layout.Find(".category-dialog .submit-button").Click(); - layout.FindAll(".manage-category-edit-button").Count.Should().Be(initialCount + 1); + layout.WaitForAssertion(() => layout.HasComponent().Should().BeFalse()); + layout.WaitForAssertion(() => layout.FindAll(".manage-category-edit-button").Count.Should().Be(initialCount + 1)); } [Fact] @@ -200,7 +202,8 @@ // Submit changes and confirm there is a new category in the list. layout.Find(".category-dialog .submit-button").Click(); - layout.FindAll(".manage-category-edit-button").Count.Should().Be(initialCount + 1); + layout.WaitForAssertion(() => layout.HasComponent().Should().BeFalse()); + layout.WaitForAssertion(() => layout.FindAll(".manage-category-edit-button").Count.Should().Be(initialCount + 1)); } [Fact] @@ -251,7 +254,7 @@ for (int i = 6; i > 1; i--) { cut.Find($"#manage-category-{guid} > .manage-category-up-button").Click(); - Category().Index.Should().Be(i - 1); + cut.WaitForAssertion(() => Category().Index.Should().Be(i - 1)); } cut.Find($"#manage-category-{guid} > .manage-category-up-button").HasAttribute("disabled").Should().BeTrue(); From 1c12e8511c41ddebf78b66fe68dfb0f1bad21b48 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 7 May 2026 16:54:30 +0000 Subject: [PATCH 2/2] Remove custom bUnit wait timeout Agent-Logs-Url: https://github.com/danielchalmers/JournalApp/sessions/b4b132f8-62be-47f3-bf39-6f8d490d7273 Co-authored-by: danielchalmers <7112040+danielchalmers@users.noreply.github.com> --- JournalApp.Tests/IndexTests.razor | 8 ++++---- JournalApp.Tests/JaTestContext.cs | 2 -- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/JournalApp.Tests/IndexTests.razor b/JournalApp.Tests/IndexTests.razor index 5ef8cdf..ed17048 100644 --- a/JournalApp.Tests/IndexTests.razor +++ b/JournalApp.Tests/IndexTests.razor @@ -83,8 +83,8 @@ // Go back to trigger save of current day state. layout.Find(".day-switcher-back").Click(); - layout.WaitForAssertion(() => selectedDayNumber().Should().Be(originalDayNumber - 1), DefaultUiWaitTimeout); - layout.WaitForAssertion(() => weightInput().GetAttribute("value").Should().NotBe("-1"), DefaultUiWaitTimeout); + layout.WaitForAssertion(() => selectedDayNumber().Should().Be(originalDayNumber - 1)); + layout.WaitForAssertion(() => weightInput().GetAttribute("value").Should().NotBe("-1")); // Validate persistence in a fresh db context, not just the currently tracked entity. using (var db = dbf.CreateDbContext()) @@ -96,10 +96,10 @@ // Return to original day and ensure UI reflects saved value. layout.Find(".day-switcher-forward").Click(); - layout.WaitForAssertion(() => selectedDayNumber().Should().Be(originalDayNumber), DefaultUiWaitTimeout); + layout.WaitForAssertion(() => selectedDayNumber().Should().Be(originalDayNumber)); // Assert that the weight is back to it's changed value from the original day. - layout.WaitForAssertion(() => weightInput().GetAttribute("value").Should().Be("-1"), DefaultUiWaitTimeout); + layout.WaitForAssertion(() => weightInput().GetAttribute("value").Should().Be("-1")); } [Theory] diff --git a/JournalApp.Tests/JaTestContext.cs b/JournalApp.Tests/JaTestContext.cs index 5700d64..b69b391 100644 --- a/JournalApp.Tests/JaTestContext.cs +++ b/JournalApp.Tests/JaTestContext.cs @@ -6,12 +6,10 @@ namespace JournalApp.Tests; public abstract class JaTestContext : BunitContext, IAsyncLifetime { - protected static readonly TimeSpan DefaultUiWaitTimeout = TimeSpan.FromSeconds(10); private SqliteConnection _dbConnection; public virtual Task InitializeAsync() { - DefaultWaitTimeout = DefaultUiWaitTimeout; Services.AddLogging(); Services.AddCommonJournalAppServices(); Services.AddSingleton();