InputElement_Focus.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright (c) The Avalonia Project. All rights reserved.
  2. // Licensed under the MIT license. See licence.md file in the project root for full license information.
  3. using Avalonia.Controls;
  4. using Avalonia.UnitTests;
  5. using Xunit;
  6. namespace Avalonia.Input.UnitTests
  7. {
  8. public class InputElement_Focus
  9. {
  10. [Fact]
  11. public void Focus_Should_Set_FocusManager_Current()
  12. {
  13. Button target;
  14. using (UnitTestApplication.Start(TestServices.RealFocus))
  15. {
  16. var root = new TestRoot
  17. {
  18. Child = target = new Button()
  19. };
  20. target.Focus();
  21. Assert.Same(target, FocusManager.Instance.Current);
  22. }
  23. }
  24. [Fact]
  25. public void Focus_Should_Be_Cleared_When_Control_Is_Removed_From_VisualTree()
  26. {
  27. Button target;
  28. using (UnitTestApplication.Start(TestServices.RealFocus))
  29. {
  30. var root = new TestRoot
  31. {
  32. Child = target = new Button()
  33. };
  34. target.Focus();
  35. root.Child = null;
  36. Assert.Null(FocusManager.Instance.Current);
  37. }
  38. }
  39. }
  40. }