Skip to content

Commit 6058630

Browse files
committed
Add default values and EnsureDefault() tests
1 parent 1bbedb2 commit 6058630

File tree

6 files changed

+38
-6
lines changed

6 files changed

+38
-6
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace CommunityToolkit.Maui.Core;
2+
static class DockLayoutDefaults
3+
{
4+
public const bool ShouldExpandLastChild = true;
5+
public const double HorizontalSpacing = 0.0d;
6+
public const double VerticalSpacing = 0.0d;
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace CommunityToolkit.Maui.Core;
2+
3+
static class UniformItemLayoutDefaults
4+
{
5+
public const int MaxRows = int.MaxValue;
6+
public const int MaxColumns = int.MaxValue;
7+
}

src/CommunityToolkit.Maui.UnitTests/Layouts/DockLayoutTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ public DockLayoutTests()
4141
DockLayout.SetDockPosition(childBottomView, DockPosition.Bottom);
4242
}
4343

44+
[Fact]
45+
public void EnsureDefaults()
46+
{
47+
var layout = new DockLayout();
48+
Assert.Equal(DockLayoutDefaults.ShouldExpandLastChild, layout.ShouldExpandLastChild);
49+
Assert.Equal(DockLayoutDefaults.HorizontalSpacing, layout.HorizontalSpacing);
50+
Assert.Equal(DockLayoutDefaults.VerticalSpacing, layout.VerticalSpacing);
51+
}
52+
4453
#region Measure
4554

4655
[Fact]

src/CommunityToolkit.Maui.UnitTests/Layouts/UniformItemsLayoutTests.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using CommunityToolkit.Maui.Layouts;
1+
using CommunityToolkit.Maui.Core;
2+
using CommunityToolkit.Maui.Layouts;
23
using FluentAssertions;
34
using Xunit;
45

@@ -109,6 +110,14 @@ public void ArrangeChildrenUniformItemsLayout()
109110
Assert.Equal(childSize * childCount, actualSize);
110111
}
111112

113+
[Fact]
114+
public void EnsureDefaults()
115+
{
116+
var layout = new UniformItemsLayout();
117+
Assert.Equal(UniformItemLayoutDefaults.MaxRows, layout.MaxRows);
118+
Assert.Equal(UniformItemLayoutDefaults.MaxColumns, layout.MaxColumns);
119+
}
120+
112121
class TestView : View
113122
{
114123
readonly Size size;

src/CommunityToolkit.Maui/Layouts/DockLayout.shared.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@ public partial class DockLayout : Layout, IDockLayout
2222
/// If true, the last child is expanded to fill the remaining space (default: true).
2323
/// </summary>
2424
[BindableProperty(PropertyChangedMethodName = nameof(OnShouldExpandLastChildPropertyChanged))]
25-
public partial bool ShouldExpandLastChild { get; set; } = true;
25+
public partial bool ShouldExpandLastChild { get; set; } = DockLayoutDefaults.ShouldExpandLastChild;
2626

2727
/// <summary>
2828
/// Gets or sets the horizontal spacing between child elements.
2929
/// </summary>
3030
[BindableProperty(PropertyChangedMethodName = nameof(OnHorizontalSpacingPropertyChanged))]
31-
public partial double HorizontalSpacing { get; set; } = 0.0d;
31+
public partial double HorizontalSpacing { get; set; } = DockLayoutDefaults.HorizontalSpacing;
3232

3333
/// <summary>
3434
/// Gets or sets the vertical spacing between elements.
3535
/// </summary>
3636

3737
[BindableProperty(PropertyChangedMethodName = nameof(OnVerticalSpacingPropertyChanged))]
38-
public partial double VerticalSpacing { get; set; } = 0.0d;
38+
public partial double VerticalSpacing { get; set; } = DockLayoutDefaults.VerticalSpacing;
3939

4040

4141
/// <summary>

src/CommunityToolkit.Maui/Layouts/UniformItemsLayout.shared.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public partial class UniformItemsLayout : Layout, IUniformItemsLayout
1515
/// Gets or sets the maximum number of rows to display or process.
1616
/// </summary>
1717
[BindableProperty(PropertyChangedMethodName = nameof(OnMaxRowsProperChanged))]
18-
public partial int MaxRows { get; set; } = int.MaxValue;
18+
public partial int MaxRows { get; set; } = UniformItemLayoutDefaults.MaxRows;
1919

2020
/// <summary>
2121
/// Gets or sets the maximum number of columns to display in the layout.
@@ -24,7 +24,7 @@ public partial class UniformItemsLayout : Layout, IUniformItemsLayout
2424
/// than or equal to 1. The default value is <see cref="int.MaxValue"/>, which allows an unlimited number of
2525
/// columns.</remarks>
2626
[BindableProperty(PropertyChangedMethodName = nameof(OnMaxColumnsProperChanged))]
27-
public partial int MaxColumns { get; set; } = int.MaxValue;
27+
public partial int MaxColumns { get; set; } = UniformItemLayoutDefaults.MaxColumns;
2828

2929
static void OnMaxRowsProperChanged(BindableObject bindable, object oldValue, object newValue)
3030
{

0 commit comments

Comments
 (0)