fix: fix various nullable warning issues in test project.

This commit is contained in:
Dong Bin
2025-02-27 16:40:15 +08:00
parent 60046f4ef1
commit 50ac16ff23
3 changed files with 9 additions and 19 deletions

View File

@@ -7,7 +7,6 @@ using Avalonia.Input;
using Avalonia.Layout;
using Avalonia.LogicalTree;
using Avalonia.Threading;
using Avalonia.VisualTree;
using HeadlessTest.Ursa.TestHelpers;
using Ursa.Controls;
using DatePicker = Ursa.Controls.DatePicker;
@@ -176,7 +175,7 @@ public class DatePickerTests
window.MouseDown(new Point(10, 10), MouseButton.Left);
Dispatcher.UIThread.RunJobs();
var popup = picker.GetTemplateChildOfType<Popup>(DatePicker.PART_Popup);
var calendar = popup.GetLogicalDescendants().OfType<CalendarView>().FirstOrDefault();
var calendar = popup?.GetLogicalDescendants().OfType<CalendarView>().FirstOrDefault();
calendar?.RaiseEvent(new CalendarDayButtonEventArgs(new DateTime(2025, 2, 17))
{ RoutedEvent = CalendarView.DateSelectedEvent });
Dispatcher.UIThread.RunJobs();
@@ -203,7 +202,7 @@ public class DatePickerTests
window.MouseDown(new Point(10, 10), MouseButton.Left);
Dispatcher.UIThread.RunJobs();
var popup = picker.GetTemplateChildOfType<Popup>(DatePicker.PART_Popup);
var calendar = popup.GetLogicalDescendants().OfType<CalendarView>().FirstOrDefault();
var calendar = popup?.GetLogicalDescendants().OfType<CalendarView>().FirstOrDefault();
calendar?.RaiseEvent(new CalendarDayButtonEventArgs(new DateTime(2025, 2, 17))
{ RoutedEvent = CalendarView.DateSelectedEvent });
Dispatcher.UIThread.RunJobs();
@@ -270,13 +269,13 @@ public class DatePickerTests
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Top
};
var focustextBox = new TextBox();
var focusTextBox = new TextBox();
window.Content = new StackPanel()
{
Children =
{
picker,
focustextBox,
focusTextBox,
}
};
window.Show();
@@ -289,7 +288,7 @@ public class DatePickerTests
Dispatcher.UIThread.RunJobs();
Assert.Equal(new DateTime(2025, 2, 18), picker.SelectedDate);
textBox?.SetValue(TextBox.TextProperty, "2025-02-18-");
focustextBox.Focus();
focusTextBox.Focus();
Dispatcher.UIThread.RunJobs();
Assert.Null(picker.SelectedDate);
}
@@ -356,7 +355,6 @@ public class DatePickerTests
var position = nextButton.TranslatePoint(new Point(5, 5), window);
Assert.NotNull(position);
window.MouseDown(new Point(10, 10), MouseButton.Left);
var renderRoot = popup.GetVisualRoot();
Dispatcher.UIThread.RunJobs();
Assert.True(picker.IsDropdownOpen);

View File

@@ -1,11 +1,4 @@
using System;
using System.ComponentModel;
using System.IO;
using System.Runtime.CompilerServices;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using Avalonia.Controls;
using Ursa.Controls;
namespace HeadlessTest.Ursa.Controls;
@@ -19,7 +12,7 @@ public partial class DrawerCloseTestPopupControl : UserControl
}
private readonly string _hostid = Path.GetRandomFileName();
public DrawerCloseTestPopupControl Popup { get; set; }
public DrawerCloseTestPopupControl? Popup { get; set; }
public int LResult { get; set; }
public int RResult { get; set; }
@@ -32,7 +25,7 @@ public partial class DrawerCloseTestPopupControl : UserControl
public void ClosePopup()
{
(Popup.DataContext as DrawerCloseTestPopupControlVM)?.Close();
(Popup?.DataContext as DrawerCloseTestPopupControlVM)?.Close();
}

View File

@@ -29,7 +29,7 @@ public class DrawerMeasureTest
};
window.Show();
Dispatcher.UIThread.RunJobs();
Drawer.ShowModal(textBlock, "hello world", null,
_ = Drawer.ShowModal(textBlock, "hello world", null,
new DrawerOptions { Position = position, TopLevelHashCode = window.GetHashCode() });
await Task.Delay(TimeSpan.FromSeconds(0.1));
var dialogControl = window.GetVisualDescendants().OfType<DefaultDrawerControl>().SingleOrDefault();
@@ -57,7 +57,6 @@ public class DrawerMeasureTest
};
window.Show();
Dispatcher.UIThread.RunJobs();
var d = window.GetVisualDescendants().ToList();
Drawer.ShowCustom(textBlock, "hello world", null,
new DrawerOptions { Position = position, TopLevelHashCode = window.GetHashCode() });
await Task.Delay(TimeSpan.FromSeconds(0.1));