From 9ef15d13d55549a68517a276d88f778f8a4acd1e Mon Sep 17 00:00:00 2001 From: Jakub Florkowski Date: Tue, 14 May 2024 01:05:02 +0200 Subject: [PATCH] Added a unit test (#22361) --- .../src/Core/IndicatorView/IndicatorView.cs | 2 +- .../Core.UnitTests/IndicatorViewLayoutTests.cs | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Controls/src/Core/IndicatorView/IndicatorView.cs b/src/Controls/src/Core/IndicatorView/IndicatorView.cs index 03b05229d539..5071ca48a1a7 100644 --- a/src/Controls/src/Core/IndicatorView/IndicatorView.cs +++ b/src/Controls/src/Core/IndicatorView/IndicatorView.cs @@ -152,7 +152,7 @@ static void UpdateIndicatorLayout(IndicatorView indicatorView, object newValue) { indicatorView.IndicatorLayout = new IndicatorStackLayout(indicatorView) { Spacing = DefaultPadding }; } - else if (indicatorView.IndicatorLayout != null) + else if (indicatorView.IndicatorLayout is not null) { (indicatorView.IndicatorLayout as IndicatorStackLayout)?.Remove(); indicatorView.IndicatorLayout = null; diff --git a/src/Controls/tests/Core.UnitTests/IndicatorViewLayoutTests.cs b/src/Controls/tests/Core.UnitTests/IndicatorViewLayoutTests.cs index e75d2b114be4..42e6135a3c96 100644 --- a/src/Controls/tests/Core.UnitTests/IndicatorViewLayoutTests.cs +++ b/src/Controls/tests/Core.UnitTests/IndicatorViewLayoutTests.cs @@ -50,5 +50,20 @@ public void IndicatorStackLayout_ResetIndicatorCount_ShouldBindChildren(int oldC // Assert Assert.Equal(expected, indicatorStackLayout.Children.Count); } + + [Fact] + public void IndicatorLayout_ShouldBeRemovedWhenIndicatorVTemplateIsNulled() + { + // Arrange + var indicatorView = new IndicatorView() { ItemsSource = new List { "item1", "item2" } }; + indicatorView.IndicatorTemplate = new DataTemplate(); + Assert.NotNull(indicatorView.IndicatorLayout); + + // Act + indicatorView.IndicatorTemplate = null; + + //Assert + Assert.Null(indicatorView.IndicatorLayout); + } } }