mirror of
https://github.com/AtomUI/AtomUI.git
synced 2026-10-24 02:09:37 +08:00
89 lines
2.4 KiB
C#
89 lines
2.4 KiB
C#
using System;
|
|
using System.Linq;
|
|
using AtomUI.Theme.Styling;
|
|
using Avalonia;
|
|
using Avalonia.Controls;
|
|
using Avalonia.Media;
|
|
using Avalonia.Threading;
|
|
using Avalonia.VisualTree;
|
|
using Shouldly;
|
|
using Xunit;
|
|
using AtomUITextBox = AtomUI.Desktop.Controls.TextBox;
|
|
using AtomUIScrollViewer = AtomUI.Desktop.Controls.ScrollViewer;
|
|
using AvaloniaWindow = Avalonia.Controls.Window;
|
|
|
|
namespace AtomUI.Desktop.Controls.Tests.Input;
|
|
|
|
public class TextBoxVisualStateTests
|
|
{
|
|
static TextBoxVisualStateTests()
|
|
{
|
|
AvaloniaTestApp.EnsureInitialized();
|
|
}
|
|
|
|
[Fact]
|
|
public void Disabled_TextBox_Uses_Disabled_Text_Foreground()
|
|
{
|
|
var textBox = new AtomUITextBox
|
|
{
|
|
Width = 160,
|
|
Text = "3",
|
|
IsEnabled = false,
|
|
IsMotionEnabled = false
|
|
};
|
|
|
|
ShowInWindow(textBox, () =>
|
|
{
|
|
var scrollViewer = textBox.GetVisualDescendants()
|
|
.OfType<AtomUIScrollViewer>()
|
|
.Single(item => item.Name == "ScrollViewer");
|
|
|
|
BrushShouldHaveSameColor(
|
|
scrollViewer.Foreground,
|
|
GetThemeResource<IBrush>(SharedTokenKind.ColorTextDisabled));
|
|
});
|
|
}
|
|
|
|
private static T GetThemeResource<T>(object key)
|
|
{
|
|
var application = Application.Current;
|
|
application.ShouldNotBeNull();
|
|
application!.TryGetResource(key, application.ActualThemeVariant, out var value).ShouldBeTrue();
|
|
value.ShouldBeAssignableTo<T>();
|
|
return (T)value!;
|
|
}
|
|
|
|
private static void BrushShouldHaveSameColor(IBrush? actual, IBrush? expected)
|
|
{
|
|
GetSolidBrushColor(actual).ShouldBe(GetSolidBrushColor(expected));
|
|
}
|
|
|
|
private static Color GetSolidBrushColor(IBrush? brush)
|
|
{
|
|
brush.ShouldNotBeNull();
|
|
brush.ShouldBeAssignableTo<ISolidColorBrush>();
|
|
return ((ISolidColorBrush)brush!).Color;
|
|
}
|
|
|
|
private static void ShowInWindow(Control content, Action assertion)
|
|
{
|
|
var window = new AvaloniaWindow
|
|
{
|
|
Width = 240,
|
|
Height = 120,
|
|
Content = content
|
|
};
|
|
|
|
try
|
|
{
|
|
window.Show();
|
|
Dispatcher.UIThread.RunJobs();
|
|
assertion();
|
|
}
|
|
finally
|
|
{
|
|
window.Close();
|
|
}
|
|
}
|
|
}
|