Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new Uno.UI runtime test intended to prevent regressions related to #2136, focusing on ItemsStackPanel stretching behavior in a ListView.
Changes:
- Introduces a new
Given_ItemsStackPanel_Stretchtest class with a regression test asserting full-width stretching forItemsPanelRootand the firstListViewItemcontainer.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Get the items panel root - it should be an ItemsStackPanel | ||
| var panel = sut.ItemsPanelRoot; | ||
| Assert.IsNotNull(panel, "ItemsPanelRoot should not be null."); | ||
|
|
There was a problem hiding this comment.
The test comment says the ItemsPanelRoot “should be an ItemsStackPanel”, but the code never verifies that (nor does it explicitly set ListView.ItemsPanel). If the default panel changes in the future, this test could still pass while no longer covering the intended regression; consider asserting the panel type (ItemsStackPanel) and/or setting an explicit ItemsPanelTemplate using ItemsStackPanel for the SUT.
|
|
||
| // Get the items panel root - it should be an ItemsStackPanel | ||
| var panel = sut.ItemsPanelRoot; | ||
| Assert.IsNotNull(panel, "ItemsPanelRoot should not be null."); | ||
|
|
||
| // The panel itself should be as wide as the container | ||
| Assert.AreEqual(ContainerWidth, panel.ActualWidth, 2d, | ||
| $"Expected ItemsPanelRoot to have ActualWidth={ContainerWidth}, but got {panel.ActualWidth}."); | ||
|
|
||
| // Check that the first visible container is stretched to the full width | ||
| await UITestHelper.WaitFor(() => sut.ContainerFromIndex(0) != null, timeoutMS: 3000); | ||
| var container = sut.ContainerFromIndex(0) as ListViewItem; | ||
| Assert.IsNotNull(container, "Expected container for index 0."); | ||
|
|
||
| Assert.AreEqual(ContainerWidth, container.ActualWidth, 2d, | ||
| $"Expected ListViewItem to be stretched to {ContainerWidth}px width, but got {container.ActualWidth}. " + | ||
| $"On WASM with ItemsStackPanel, items are not being stretched to fill the available width."); |
There was a problem hiding this comment.
The width assertions use the constant 300px as the expected available width. Depending on default ListView template padding/border/scrollbar behavior, the ItemsPanelRoot and item containers may correctly stretch to the available width while still being slightly less than the control Width. To avoid false failures and improve cross-platform stability, derive the expected width from the actual arranged width (e.g., sut.ActualWidth / items presenter width) and wait until the element is measured (ActualWidth > 0) before asserting.
| // Get the items panel root - it should be an ItemsStackPanel | |
| var panel = sut.ItemsPanelRoot; | |
| Assert.IsNotNull(panel, "ItemsPanelRoot should not be null."); | |
| // The panel itself should be as wide as the container | |
| Assert.AreEqual(ContainerWidth, panel.ActualWidth, 2d, | |
| $"Expected ItemsPanelRoot to have ActualWidth={ContainerWidth}, but got {panel.ActualWidth}."); | |
| // Check that the first visible container is stretched to the full width | |
| await UITestHelper.WaitFor(() => sut.ContainerFromIndex(0) != null, timeoutMS: 3000); | |
| var container = sut.ContainerFromIndex(0) as ListViewItem; | |
| Assert.IsNotNull(container, "Expected container for index 0."); | |
| Assert.AreEqual(ContainerWidth, container.ActualWidth, 2d, | |
| $"Expected ListViewItem to be stretched to {ContainerWidth}px width, but got {container.ActualWidth}. " + | |
| $"On WASM with ItemsStackPanel, items are not being stretched to fill the available width."); | |
| await UITestHelper.WaitFor(() => sut.ActualWidth > 0, timeoutMS: 3000); | |
| await UITestHelper.WaitFor(() => sut.ItemsPanelRoot?.ActualWidth > 0, timeoutMS: 3000); | |
| // Get the items panel root - it should be an ItemsStackPanel | |
| var panel = sut.ItemsPanelRoot; | |
| Assert.IsNotNull(panel, "ItemsPanelRoot should not be null."); | |
| var availableWidth = panel.ActualWidth; | |
| Assert.IsTrue(availableWidth > 0, | |
| $"Expected ItemsPanelRoot to be measured with a positive ActualWidth, but got {availableWidth}."); | |
| // Check that the first visible container is stretched to the full available panel width | |
| await UITestHelper.WaitFor(() => sut.ContainerFromIndex(0) is ListViewItem, timeoutMS: 3000); | |
| var container = sut.ContainerFromIndex(0) as ListViewItem; | |
| Assert.IsNotNull(container, "Expected container for index 0."); | |
| await UITestHelper.WaitFor(() => container.ActualWidth > 0, timeoutMS: 3000); | |
| Assert.AreEqual(availableWidth, container.ActualWidth, 2d, | |
| $"Expected ListViewItem to be stretched to the available panel width ({availableWidth}px), but got {container.ActualWidth}. " + | |
| $"ListView ActualWidth={sut.ActualWidth}, requested Width={ContainerWidth}, panel ActualWidth={panel.ActualWidth}."); |
| // Repro tests for https://github.com/unoplatform/uno/issues/2136 | ||
| [TestClass] | ||
| [RunsOnUIThread] | ||
| public class Given_ItemsStackPanel_Stretch | ||
| { | ||
| [TestMethod] | ||
| [GitHubWorkItem("https://github.com/unoplatform/uno/issues/2136")] | ||
| [PlatformCondition(ConditionMode.Exclude, RuntimeTestPlatforms.NativeWinUI)] | ||
| public async Task When_ListView_ItemsStackPanel_Children_Are_Stretched_To_Full_Width() |
There was a problem hiding this comment.
On APPLE_UIKIT, this file currently disables the existing Given_ListViewBase tests via a class-level [Ignore] (issue #17101). The new top-level test class is not covered by that ignore, so it will start running on iOS even though ListView tests are intentionally disabled there; consider adding the same iOS Ignore/PlatformCondition exclusion here to avoid reintroducing the crash/failure mode.
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-22990/wasm-skia-net9/index.html |
|
|
Summary
Adds regression test for #2136.
The reported issue appears to be potentially fixed — the test(s) pass on current master (Skia target).
Test(s) added
src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_ListViewBase.cs→When_ListView_ItemsStackPanel_Children_Are_Stretched_To_Full_WidthNotes
The issue was reported on WebAssembly. Runtime tests run on Skia only — the fix should be verified on native targets as well.
The test verifies that items inside a vertical
ItemsStackPanelwithin aListViewstretch to fill the available width (300px container), checking both the panel root and individualListViewItemcontainers.Relates to #2136