Skip to content

Commit 356db00

Browse files
committed
Add failing test for reassigning TDG source.
Columns are initialized sized incorrectly.
1 parent bf60ccc commit 356db00

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

tests/Avalonia.Controls.TreeDataGrid.Tests/TreeDataGridTests_Flat.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,46 @@ public void Does_Not_Realize_Columns_Outside_Viewport()
312312
Assert.True(double.IsNaN(columns[3].ActualWidth));
313313
}
314314

315+
[AvaloniaFact(Timeout = 10000)]
316+
public void Columns_Are_Correctly_Sized_After_Changing_Source()
317+
{
318+
// Create the initial target with 2 columns and make sure our preconditions are correct.
319+
var (target, items) = CreateTarget(columns: new IColumn<Model>[]
320+
{
321+
new TextColumn<Model, int>("ID", x => x.Id, width: new GridLength(1, GridUnitType.Star)),
322+
new TextColumn<Model, string?>("Title1", x => x.Title, options: MinWidth(50)),
323+
});
324+
325+
AssertColumnIndexes(target, 0, 2);
326+
327+
// Create a new source and assign it to the TreeDataGrid.
328+
var newSource = new FlatTreeDataGridSource<Model>(items)
329+
{
330+
Columns =
331+
{
332+
new TextColumn<Model, int>("ID", x => x.Id, width: new GridLength(1, GridUnitType.Star)),
333+
new TextColumn<Model, string?>("Title1", x => x.Title, options: MinWidth(20)),
334+
new TextColumn<Model, string?>("Title2", x => x.Title, options: MinWidth(20)),
335+
}
336+
};
337+
338+
target.Source = newSource;
339+
340+
// The columns should not have an ActualWidth yet.
341+
Assert.True(double.IsNaN(newSource.Columns[0].ActualWidth));
342+
Assert.True(double.IsNaN(newSource.Columns[1].ActualWidth));
343+
Assert.True(double.IsNaN(newSource.Columns[2].ActualWidth));
344+
345+
// Do a layout pass and check that the columns have been correctly sized.
346+
target.UpdateLayout();
347+
AssertColumnIndexes(target, 0, 3);
348+
349+
var columns = (ColumnList<Model>)target.Columns!;
350+
Assert.Equal(60, columns[0].ActualWidth);
351+
Assert.Equal(20, columns[1].ActualWidth);
352+
Assert.Equal(20, columns[2].ActualWidth);
353+
}
354+
315355
public class RemoveItems
316356
{
317357
[AvaloniaFact(Timeout = 10000)]

0 commit comments

Comments
 (0)