Skip to content

Commit

Permalink
fix: Avoid nested UI classes in runtime tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Oct 6, 2023
1 parent 53a3508 commit e40221a
Show file tree
Hide file tree
Showing 8 changed files with 226 additions and 225 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1353,145 +1353,145 @@ private static VirtualizingLayout GetMonitoringLayout(Size desiredSize, List<Rec
ArrangeLayoutFunc = (finalSize, context) => finalSize
};
}
}

private partial class TestScrollingSurface : ContentControl, IRepeaterScrollingSurface
{
private bool _isHorizontallyScrollable;
private bool _isVerticallyScrollable;
private ConfigurationChangedEventHandler _configurationChangedTokenTable;
internal partial class TestScrollingSurface : ContentControl, IRepeaterScrollingSurface
{
private bool _isHorizontallyScrollable;
private bool _isVerticallyScrollable;
private ConfigurationChangedEventHandler _configurationChangedTokenTable;

public bool InMeasure { get; set; }
public bool InArrange { get; set; }
public bool InPostArrange { get; private set; }
public bool InMeasure { get; set; }
public bool InArrange { get; set; }
public bool InPostArrange { get; private set; }

public Action ConfigurationChangedAddFunc { get; set; }
public Action ConfigurationChangedRemoveFunc { get; set; }
public Action ConfigurationChangedAddFunc { get; set; }
public Action ConfigurationChangedRemoveFunc { get; set; }

public Action<UIElement> RegisterAnchorCandidateFunc { get; set; }
public Action<UIElement> UnregisterAnchorCandidateFunc { get; set; }
public Func<UIElement, Rect> GetRelativeViewportFunc { get; set; }
public Action<UIElement> RegisterAnchorCandidateFunc { get; set; }
public Action<UIElement> UnregisterAnchorCandidateFunc { get; set; }
public Func<UIElement, Rect> GetRelativeViewportFunc { get; set; }

public UIElement AnchorElement { get; set; }
public UIElement AnchorElement { get; set; }

public bool IsHorizontallyScrollable
public bool IsHorizontallyScrollable
{
get { return _isHorizontallyScrollable; }
set
{
get { return _isHorizontallyScrollable; }
set
{
_isHorizontallyScrollable = value;
RaiseConfigurationChanged();
InvalidateMeasure();
}
_isHorizontallyScrollable = value;
RaiseConfigurationChanged();
InvalidateMeasure();
}
}

public bool IsVerticallyScrollable
public bool IsVerticallyScrollable
{
get { return _isVerticallyScrollable; }
set
{
get { return _isVerticallyScrollable; }
set
{
_isVerticallyScrollable = value;
RaiseConfigurationChanged();
InvalidateMeasure();
}
_isVerticallyScrollable = value;
RaiseConfigurationChanged();
InvalidateMeasure();
}
}

public event ConfigurationChangedEventHandler ConfigurationChanged
public event ConfigurationChangedEventHandler ConfigurationChanged
{
add
{
add
if (ConfigurationChangedAddFunc != null)
{
if (ConfigurationChangedAddFunc != null)
{
ConfigurationChangedAddFunc();
}

_configurationChangedTokenTable += value;
ConfigurationChangedAddFunc();
}
remove
{
if (ConfigurationChangedRemoveFunc != null)
{
ConfigurationChangedRemoveFunc();
}

_configurationChangedTokenTable -= value;
}
_configurationChangedTokenTable += value;
}
public event PostArrangeEventHandler PostArrange;
#pragma warning disable CS0067
// Warning CS0067: The event 'ViewportTests.TestScrollingSurface.ViewportChanged' is never used.
public event ViewportChangedEventHandler ViewportChanged;
#pragma warning restore CS0067

public void RegisterAnchorCandidate(UIElement element)
remove
{
RegisterAnchorCandidateFunc(element);
}

public void UnregisterAnchorCandidate(UIElement element)
{
UnregisterAnchorCandidateFunc(element);
}
if (ConfigurationChangedRemoveFunc != null)
{
ConfigurationChangedRemoveFunc();
}

public Rect GetRelativeViewport(UIElement child)
{
return GetRelativeViewportFunc(child);
_configurationChangedTokenTable -= value;
}
}
public event PostArrangeEventHandler PostArrange;
#pragma warning disable CS0067
// Warning CS0067: The event 'ViewportTests.TestScrollingSurface.ViewportChanged' is never used.
public event ViewportChangedEventHandler ViewportChanged;
#pragma warning restore CS0067

protected override Size MeasureOverride(Size availableSize)
{
InMeasure = true;
var result = base.MeasureOverride(availableSize);
InMeasure = false;
return result;
}
public void RegisterAnchorCandidate(UIElement element)
{
RegisterAnchorCandidateFunc(element);
}

protected override Size ArrangeOverride(Size finalSize)
{
InArrange = true;
public void UnregisterAnchorCandidate(UIElement element)
{
UnregisterAnchorCandidateFunc(element);
}

var result = base.ArrangeOverride(finalSize);
public Rect GetRelativeViewport(UIElement child)
{
return GetRelativeViewportFunc(child);
}

InArrange = false;
InPostArrange = true;
protected override Size MeasureOverride(Size availableSize)
{
InMeasure = true;
var result = base.MeasureOverride(availableSize);
InMeasure = false;
return result;
}

if (PostArrange != null)
{
PostArrange(this);
}
protected override Size ArrangeOverride(Size finalSize)
{
InArrange = true;

InPostArrange = false;
var result = base.ArrangeOverride(finalSize);

return result;
}
InArrange = false;
InPostArrange = true;

private void RaiseConfigurationChanged()
if (PostArrange != null)
{
_configurationChangedTokenTable?.Invoke(this);
PostArrange(this);
}

InPostArrange = false;

return result;
}

private partial class TestStackLayout : StackLayout
private void RaiseConfigurationChanged()
{
public UIElement SuggestedAnchor { get; private set; }

protected internal override Size MeasureOverride(VirtualizingLayoutContext context, Size availableSize)
{
var anchorIndex = context.RecommendedAnchorIndex;
SuggestedAnchor = anchorIndex < 0 ? null : context.GetOrCreateElementAt(anchorIndex);
return base.MeasureOverride(context, availableSize);
}
_configurationChangedTokenTable?.Invoke(this);
}
}

internal partial class TestStackLayout : StackLayout
{
public UIElement SuggestedAnchor { get; private set; }

private partial class TestGridLayout : UniformGridLayout
protected internal override Size MeasureOverride(VirtualizingLayoutContext context, Size availableSize)
{
public UIElement SuggestedAnchor { get; private set; }
var anchorIndex = context.RecommendedAnchorIndex;
SuggestedAnchor = anchorIndex < 0 ? null : context.GetOrCreateElementAt(anchorIndex);
return base.MeasureOverride(context, availableSize);
}
}

protected internal override Size MeasureOverride(VirtualizingLayoutContext context, Size availableSize)
{
var anchorIndex = context.RecommendedAnchorIndex;
SuggestedAnchor = anchorIndex < 0 ? null : context.GetOrCreateElementAt(anchorIndex);
return base.MeasureOverride(context, availableSize);
}
internal partial class TestGridLayout : UniformGridLayout
{
public UIElement SuggestedAnchor { get; private set; }

protected internal override Size MeasureOverride(VirtualizingLayoutContext context, Size availableSize)
{
var anchorIndex = context.RecommendedAnchorIndex;
SuggestedAnchor = anchorIndex < 0 ? null : context.GetOrCreateElementAt(anchorIndex);
return base.MeasureOverride(context, availableSize);
}
}
}
20 changes: 10 additions & 10 deletions src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Given_Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,6 @@ namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml
[TestClass]
public partial class Given_Control
{
private partial class CustomControl : Control
{
public Size AvailableSizePassedToMeasureOverride { get; private set; }
protected override Size MeasureOverride(Size availableSize)
{
AvailableSizePassedToMeasureOverride = availableSize;
return new(2000, 2000);
}
}

[TestMethod]
[RunsOnUIThread]
public async Task When_Limited_By_Available_Size_Before_Margin_Application()
Expand Down Expand Up @@ -219,4 +209,14 @@ public async Task When_Padding_Set_In_SizeChanged()
Assert.AreEqual(0, ((UIElement)VisualTreeHelper.GetChild(SUT, 0)).ActualOffset.Y);
}
}

public partial class CustomControl : Control
{
public Size AvailableSizePassedToMeasureOverride { get; private set; }
protected override Size MeasureOverride(Size availableSize)
{
AvailableSizePassedToMeasureOverride = availableSize;
return new(2000, 2000);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -331,16 +331,6 @@ public Task When_Grid_Measure_And_Invalidate() =>
});
#endif

public partial class MyGrid : Grid
{
public Size AvailableSizeUsedForMeasure { get; private set; }
protected override Size MeasureOverride(Size availableSize)
{
AvailableSizeUsedForMeasure = availableSize;
return base.MeasureOverride(availableSize);
}
}

[TestMethod]
[RunsOnUIThread]
#if __MACOS__
Expand Down Expand Up @@ -775,6 +765,16 @@ public async Task When_Add_Element_While_Parent_Loaded_Then_Load_Raised()
#endif
}

public partial class MyGrid : Grid
{
public Size AvailableSizeUsedForMeasure { get; private set; }
protected override Size MeasureOverride(Size availableSize)
{
AvailableSizeUsedForMeasure = availableSize;
return base.MeasureOverride(availableSize);
}
}

public partial class MyControl01 : FrameworkElement
{
public List<Size> MeasureOverrides { get; } = new List<Size>();
Expand Down
Loading

0 comments on commit e40221a

Please sign in to comment.