From bbfacb8040189b383fe57a647b47c584c20f6eba Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 18 Dec 2025 23:38:19 +0000 Subject: [PATCH 1/2] Initial plan From f0e9055c695893c7a055951feda3b1740e2f1b89 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 18 Dec 2025 23:49:21 +0000 Subject: [PATCH 2/2] Upgrade to bunit v2.3.4 and update test code Co-authored-by: danielchalmers <7112040+danielchalmers@users.noreply.github.com> --- JournalApp.Tests/CalendarTests.razor | 6 +++--- JournalApp.Tests/DataPointViewTests.razor | 10 +++++----- JournalApp.Tests/JaTestContext.cs | 6 ++++-- JournalApp.Tests/JournalApp.Tests.csproj | 2 +- JournalApp.Tests/ManageCategoriesTests.razor | 2 +- JournalApp.Tests/SafetyPlanTests.razor | 11 +++++++---- 6 files changed, 21 insertions(+), 16 deletions(-) diff --git a/JournalApp.Tests/CalendarTests.razor b/JournalApp.Tests/CalendarTests.razor index b73b9093..792803ad 100644 --- a/JournalApp.Tests/CalendarTests.razor +++ b/JournalApp.Tests/CalendarTests.razor @@ -20,7 +20,7 @@ [Fact] public void SwitchYear() { - var cut = RenderComponent(p => + var cut = Render(p => p.Add(x => x.OpenToDateString, "20000101") ); @@ -51,7 +51,7 @@ [Fact] public async Task CalendarViewMoodBlockCount() { - var cut = RenderComponent(p => + var cut = Render(p => p.Add(x => x.OpenToDateString, "20230101") ); cut.Instance.SelectedYear.Should().Be(2023); @@ -82,7 +82,7 @@ _culture.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Wednesday; Thread.CurrentThread.CurrentCulture = _culture; - var cut = RenderComponent(p => + var cut = Render(p => p.Add(x => x.OpenToDateString, "20230101") ); cut.Instance.SelectedYear.Should().Be(2023); diff --git a/JournalApp.Tests/DataPointViewTests.razor b/JournalApp.Tests/DataPointViewTests.razor index 61201ceb..e4ece1eb 100644 --- a/JournalApp.Tests/DataPointViewTests.razor +++ b/JournalApp.Tests/DataPointViewTests.razor @@ -87,7 +87,7 @@ var point = DataPoint.Create(day, category); point.SleepHours = 8.5m; - var cut = RenderComponent(p => + var cut = Render(p => p.Add(x => x.Point, point) ); @@ -122,7 +122,7 @@ var day = Day.Create(new(2024, 01, 01)); var point = DataPoint.Create(day, category); - var cut = RenderComponent(p => + var cut = Render(p => p.Add(x => x.Point, point) ); @@ -150,7 +150,7 @@ var day = Day.Create(new(2024, 01, 01)); var point = DataPoint.Create(day, category); - var cut = RenderComponent(p => + var cut = Render(p => p.Add(x => x.Point, point) ); @@ -187,7 +187,7 @@ var day = Day.Create(new(2024, 01, 01)); var point = DataPoint.Create(day, category); - var cut = RenderComponent(p => + var cut = Render(p => p.Add(x => x.Point, point) ); @@ -208,7 +208,7 @@ var day = Day.Create(new(2024, 01, 01)); var point = DataPoint.Create(day, category); - var cut = RenderComponent(p => + var cut = Render(p => p.Add(x => x.Point, point) ); diff --git a/JournalApp.Tests/JaTestContext.cs b/JournalApp.Tests/JaTestContext.cs index 4a683669..0f0bfa58 100644 --- a/JournalApp.Tests/JaTestContext.cs +++ b/JournalApp.Tests/JaTestContext.cs @@ -4,7 +4,7 @@ namespace JournalApp.Tests; -public abstract class JaTestContext : TestContext, IAsyncLifetime +public abstract class JaTestContext : BunitContext, IAsyncLifetime { private SqliteConnection _dbConnection; @@ -21,13 +21,15 @@ public virtual Task InitializeAsync() return Task.CompletedTask; } - public virtual async Task DisposeAsync() + public new virtual async Task DisposeAsync() { if (_dbConnection != null) { await _dbConnection.CloseAsync(); await _dbConnection.DisposeAsync(); } + + await base.DisposeAsync(); } public void AddDbContext() diff --git a/JournalApp.Tests/JournalApp.Tests.csproj b/JournalApp.Tests/JournalApp.Tests.csproj index 52e937f8..0aaeddad 100644 --- a/JournalApp.Tests/JournalApp.Tests.csproj +++ b/JournalApp.Tests/JournalApp.Tests.csproj @@ -14,7 +14,7 @@ - + diff --git a/JournalApp.Tests/ManageCategoriesTests.razor b/JournalApp.Tests/ManageCategoriesTests.razor index ef97b300..1f6f317e 100644 --- a/JournalApp.Tests/ManageCategoriesTests.razor +++ b/JournalApp.Tests/ManageCategoriesTests.razor @@ -207,7 +207,7 @@ return db.Categories.Single(c => c.Guid == new Guid(guid)); } - var cut = RenderComponent(); + var cut = Render(); for (int i = 6; i > 1; i--) { diff --git a/JournalApp.Tests/SafetyPlanTests.razor b/JournalApp.Tests/SafetyPlanTests.razor index 410edae7..04dc563a 100644 --- a/JournalApp.Tests/SafetyPlanTests.razor +++ b/JournalApp.Tests/SafetyPlanTests.razor @@ -13,7 +13,7 @@ Purpose = "My purpose is to finish these tests", }; - var cut = RenderComponent(); + var cut = Render(); // Assert state. cut.Instance.Plan.Purpose.Should().Be("My purpose is to finish these tests"); @@ -31,7 +31,7 @@ Purpose = "My purpose is to finish these tests", }; - var cut = RenderComponent(); + var cut = Render(); // Assert initial state. cut.Instance.Plan.Purpose.Should().Be("My purpose is to finish these tests"); @@ -40,10 +40,13 @@ // Change via textarea and property to test both. cut.Find(".safety-plan-item-purpose textarea").Input("Actually it's puppies"); cut.Instance.Plan.ProfessionalContacts = "988 (USA)"; + + // Manually save state (normally triggered by navigation or window deactivation) + preferenceService.SafetyPlan = cut.Instance.Plan; // Leave and come back. - DisposeComponents(); - cut = RenderComponent(); + cut.Dispose(); + cut = Render(); // Assert that all changes persisted. preferenceService.SafetyPlan.Purpose.Should().Be("Actually it's puppies");