diff --git a/tests/Spice86.Tests/UI/BreakpointUiTestBase.cs b/tests/Spice86.Tests/UI/BreakpointUiTestBase.cs
index 6c5cd434ba..b48b669c52 100644
--- a/tests/Spice86.Tests/UI/BreakpointUiTestBase.cs
+++ b/tests/Spice86.Tests/UI/BreakpointUiTestBase.cs
@@ -135,6 +135,15 @@ protected static void ShowWindowAndWait(Window window) {
ProcessUiEvents();
}
+ ///
+ /// Closes a window and processes any deferred UI events triggered by the close
+ /// (e.g., window state saving) before the test context is torn down.
+ ///
+ protected static void CloseWindowAndWait(Window window) {
+ window.Close();
+ ProcessUiEvents();
+ }
+
///
/// Selects a breakpoint type tab by name and processes UI events.
///
diff --git a/tests/Spice86.Tests/UI/BreakpointsViewUiTests.cs b/tests/Spice86.Tests/UI/BreakpointsViewUiTests.cs
index 5803c9d0b2..d1ef803ac0 100644
--- a/tests/Spice86.Tests/UI/BreakpointsViewUiTests.cs
+++ b/tests/Spice86.Tests/UI/BreakpointsViewUiTests.cs
@@ -44,7 +44,7 @@ public void BreakpointsView_CanCreateExecutionBreakpoint() {
viewModel.IsExecutionBreakpointSelected.Should().BeTrue();
// Cleanup
- window.Close();
+ CloseWindowAndWait(window);
}
///
@@ -75,7 +75,7 @@ public void BreakpointsView_CanCreateExecutionBreakpointWithCondition() {
viewModel.CreatingBreakpoint.Should().BeFalse();
// Cleanup
- window.Close();
+ CloseWindowAndWait(window);
}
///
@@ -104,7 +104,7 @@ public void BreakpointsView_InvalidConditionExpression_ShowsError() {
}
// Cleanup
- window.Close();
+ CloseWindowAndWait(window);
}
///
@@ -130,7 +130,7 @@ public void BreakpointsView_CancelCreation_ClearsCreatingState() {
viewModel.CreatingBreakpoint.Should().BeFalse();
// Cleanup
- window.Close();
+ CloseWindowAndWait(window);
}
///
@@ -147,7 +147,7 @@ public void BreakpointsView_ShowsBreakpointTypeTabs() {
viewModel.BreakpointTabs.Should().NotBeEmpty();
// Cleanup
- window.Close();
+ CloseWindowAndWait(window);
}
///
@@ -180,7 +180,7 @@ public void BreakpointsView_AcceptsComparisonOperatorConditions() {
}
// Cleanup
- window.Close();
+ CloseWindowAndWait(window);
}
///
@@ -213,7 +213,7 @@ public void BreakpointsView_AcceptsLogicalOperatorConditions() {
}
// Cleanup
- window.Close();
+ CloseWindowAndWait(window);
}
///
@@ -241,7 +241,7 @@ public void BreakpointsView_CanCreateMemoryBreakpoint() {
}
// Cleanup
- window.Close();
+ CloseWindowAndWait(window);
}
///
@@ -276,7 +276,7 @@ public void BreakpointsView_CanCreateCyclesBreakpoint() {
}
// Cleanup
- window.Close();
+ CloseWindowAndWait(window);
}
///
@@ -311,7 +311,7 @@ public void BreakpointsView_CanCreateInterruptBreakpoint() {
}
// Cleanup
- window.Close();
+ CloseWindowAndWait(window);
}
///
@@ -346,7 +346,7 @@ public void BreakpointsView_CanCreateIoPortBreakpoint() {
}
// Cleanup
- window.Close();
+ CloseWindowAndWait(window);
}
///
@@ -379,7 +379,7 @@ public void BreakpointsView_AcceptsBitwiseOperatorConditions() {
}
// Cleanup
- window.Close();
+ CloseWindowAndWait(window);
}
///
@@ -412,7 +412,7 @@ public void BreakpointsView_AcceptsArithmeticOperatorConditions() {
}
// Cleanup
- window.Close();
+ CloseWindowAndWait(window);
}
///
@@ -436,7 +436,7 @@ public void BreakpointsView_CanCreateInterruptBreakpointWithCondition() {
viewModel.Breakpoints.Should().ContainSingle(bp =>
bp.Type == BreakPointType.CPU_INTERRUPT && bp.ConditionExpression == "ah == 0x09");
- window.Close();
+ CloseWindowAndWait(window);
}
///
@@ -461,7 +461,7 @@ public void BreakpointsView_InterruptBreakpoint_InvalidCondition_KeepsDialogOpen
viewModel.Breakpoints.Count.Should().Be(initialCount);
viewModel.CreatingBreakpoint.Should().BeTrue();
- window.Close();
+ CloseWindowAndWait(window);
}
///
@@ -485,7 +485,7 @@ public void BreakpointsView_CanCreateIoPortBreakpointWithCondition() {
viewModel.Breakpoints.Should().ContainSingle(bp =>
bp.Type == BreakPointType.IO_ACCESS && bp.ConditionExpression == "al == 0x01");
- window.Close();
+ CloseWindowAndWait(window);
}
///
@@ -508,7 +508,7 @@ public void BreakpointsView_InterruptBreakpoint_OutOfRange_BlocksConfirmation()
ProcessUiEvents();
viewModel.ConfirmBreakpointCreationCommand.CanExecute(null).Should().BeTrue();
- window.Close();
+ CloseWindowAndWait(window);
}
///
@@ -531,7 +531,7 @@ public void BreakpointsView_IoPortBreakpoint_OutOfRange_BlocksConfirmation() {
ProcessUiEvents();
viewModel.ConfirmBreakpointCreationCommand.CanExecute(null).Should().BeTrue();
- window.Close();
+ CloseWindowAndWait(window);
}
///
@@ -565,7 +565,7 @@ public void BreakpointsView_InterruptBreakpoint_Wildcard_CreatesAndRoundTrips()
// Assert: edit restores "*" instead of casting -1 to 0xFFFFFFFF
viewModel.InterruptNumber.Should().Be("*");
- window.Close();
+ CloseWindowAndWait(window);
}
///
@@ -597,7 +597,7 @@ public void BreakpointsView_IoPortBreakpoint_Wildcard_CreatesAndRoundTrips() {
// Assert: edit restores "*" instead of casting -1 to 0xFFFFFFFF
viewModel.IoPortNumber.Should().Be("*");
- window.Close();
+ CloseWindowAndWait(window);
}
///
@@ -619,6 +619,6 @@ public void BreakpointsView_BeginCreateBreakpoint_ClearsInterruptAndIoConditions
viewModel.InterruptConditionExpression.Should().BeNull();
viewModel.IoPortConditionExpression.Should().BeNull();
- window.Close();
+ CloseWindowAndWait(window);
}
}
diff --git a/tests/Spice86.Tests/UI/HeadlessInfrastructureTests.cs b/tests/Spice86.Tests/UI/HeadlessInfrastructureTests.cs
index e845807337..6d5edcb60c 100644
--- a/tests/Spice86.Tests/UI/HeadlessInfrastructureTests.cs
+++ b/tests/Spice86.Tests/UI/HeadlessInfrastructureTests.cs
@@ -37,6 +37,7 @@ public void TestHeadlessWindowCanBeShown() {
// Cleanup
window.Close();
+ Avalonia.Threading.Dispatcher.UIThread.RunJobs();
}
///
diff --git a/tests/Spice86.Tests/UI/MemoryViewUiTests.cs b/tests/Spice86.Tests/UI/MemoryViewUiTests.cs
index 0f8fea84c7..c65f8429f7 100644
--- a/tests/Spice86.Tests/UI/MemoryViewUiTests.cs
+++ b/tests/Spice86.Tests/UI/MemoryViewUiTests.cs
@@ -43,7 +43,7 @@ public async Task FirstOccurrence_Reinvoked_ReappliesSelectionOnFoundAddress() {
harness.HexEditor.Selection.Range.Start.ByteIndex.Should().Be(expectedByteIndex);
// Cleanup
- harness.Window.Close();
+ CloseWindowAndWait(harness.Window);
}
[AvaloniaFact]
@@ -71,6 +71,6 @@ public async Task FirstOccurrence_WhenFoundAddressIsOutsideCurrentWindow_Reframe
harness.HexEditor.Selection.Range.Start.ByteIndex.Should().Be(0UL);
// Cleanup
- harness.Window.Close();
+ CloseWindowAndWait(harness.Window);
}
}