Skip to content

Commit

Permalink
test: add When_StateTriggers_Evaluated_Before_First_Layout
Browse files Browse the repository at this point in the history
  • Loading branch information
ramezgerges committed Feb 19, 2025
1 parent eb684d5 commit 7ab05d3
Showing 1 changed file with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Windows.Foundation;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Shapes;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MUXControlsTestApp.Utilities;
using SamplesApp.UITests;
using Uno.Extensions;
using Uno.UI.Extensions;
using Uno.UI.RuntimeTests.Helpers;
Expand Down Expand Up @@ -79,4 +82,65 @@ public async Task SelectorItem_SelectedState()
var states = VisualStateHelper.GetCurrentVisualStateName(container2).ToArray();
Assert.IsTrue(states.Contains("MultiSelectEnabled"), $"container2 is not in 'MultiSelectEnabled' state: states={states.JoinBy(",")}");
}

#if HAS_UNO
[TestMethod]
[UnoWorkItem("https://github.com/unoplatform/uno/issues/19364")]
public async Task When_StateTriggers_Evaluated_Before_First_Layout()
{
MyUserControl uc = new MyUserControl();
VisualStateManager.SetVisualStateGroups(uc, new List<VisualStateGroup>
{
new VisualStateGroup()
{
States =
{
new VisualState
{
Name = "MyVisualState1",
},
new VisualState
{
Name = "MyVisualState2",
StateTriggers =
{
new AdaptiveTrigger()
{
MinWindowWidth = 1
}
}
}
}
}
});

var contentControl = new ContentControl
{
Content = "0",
ContentTemplate = new DataTemplate(() =>
{
return uc;
})
};

await UITestHelper.Load(contentControl, control => control.IsLoaded);
Assert.AreEqual("MyVisualState2", uc.VisualStateOnFirstMeasure?.Name);
}

private partial class MyUserControl : UserControl
{
private bool _firstMeasure = true;
public VisualState VisualStateOnFirstMeasure { get; set; }

protected override Size MeasureOverride(Size availableSize)
{
if (_firstMeasure)
{
_firstMeasure = false;
VisualStateOnFirstMeasure = VisualStateManager.GetVisualStateGroups(this)[0].CurrentState;
}
return base.MeasureOverride(availableSize);
}
}
#endif
}

0 comments on commit 7ab05d3

Please sign in to comment.