Browse Source

add unit test for specific scenario where datacontext changes tip before remvoed from visual tree.

pull/4407/head
Dan Walmsley 6 years ago
parent
commit
037e63d9ab
  1. 37
      tests/Avalonia.Controls.UnitTests/ToolTipTests.cs

37
tests/Avalonia.Controls.UnitTests/ToolTipTests.cs

@ -1,5 +1,6 @@
using System;
using System.Reactive.Disposables;
using Avalonia.Markup.Xaml;
using Avalonia.Platform;
using Avalonia.Threading;
using Avalonia.UnitTests;
@ -66,34 +67,33 @@ namespace Avalonia.Controls.UnitTests
}
[Fact]
public void Should_Close_When_Tip_Is_Changed()
public void Should_Close_When_Tip_Is_Opened_And_Detached_From_Visual_Tree()
{
using (UnitTestApplication.Start(TestServices.StyledWindow))
{
var window = new Window();
var panel = new Panel();
var target = new Decorator()
{
[ToolTip.TipProperty] = "Tip",
[ToolTip.ShowDelayProperty] = 0
};
var xaml = @"
<Window xmlns='https://github.com/avaloniaui'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<Panel x:Name='PART_panel'>
<Decorator x:Name='PART_target' ToolTip.Tip='{Binding Tip}' ToolTip.ShowDelay='0' />
</Panel>
</Window>";
var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml);
panel.Children.Add(target);
window.Content = panel;
window.DataContext = new ToolTipViewModel();
window.ApplyTemplate();
window.Presenter.ApplyTemplate();
var target = window.Find<Decorator>("PART_target");
var panel = window.Find<Panel>("PART_panel");
Assert.True((target as IVisual).IsAttachedToVisualTree);
_mouseHelper.Enter(target);
Assert.True(ToolTip.GetIsOpen(target));
ToolTip.SetTip(target, "");
panel.Children.Remove(target);
Assert.False(ToolTip.GetIsOpen(target));
}
@ -242,4 +242,9 @@ namespace Avalonia.Controls.UnitTests
}
}
}
internal class ToolTipViewModel
{
public string Tip => "Tip";
}
}

Loading…
Cancel
Save