|  | 
|  | 1 | +// Licensed to the .NET Foundation under one or more agreements. | 
|  | 2 | +// The .NET Foundation licenses this file to you under the MIT license. | 
|  | 3 | +// See the LICENSE file in the project root for more information. | 
|  | 4 | + | 
|  | 5 | +using Microsoft.Windows.Apps.Test.Foundation; | 
|  | 6 | +using Microsoft.Windows.Apps.Test.Foundation.Controls; | 
|  | 7 | +using Windows.UI.Xaml.Tests.MUXControls.InteractionTests.Common; | 
|  | 8 | +using Windows.UI.Xaml.Tests.MUXControls.InteractionTests.Infra; | 
|  | 9 | +using System.Linq; | 
|  | 10 | +using System.Threading.Tasks; | 
|  | 11 | +using System.Collections.Generic; | 
|  | 12 | +using System.Dynamic; | 
|  | 13 | +using System; | 
|  | 14 | + | 
|  | 15 | +#if USING_TAEF | 
|  | 16 | +using WEX.Logging.Interop; | 
|  | 17 | +using WEX.TestExecution; | 
|  | 18 | +using WEX.TestExecution.Markup; | 
|  | 19 | +#else | 
|  | 20 | +using Microsoft.VisualStudio.TestTools.UnitTesting; | 
|  | 21 | +#endif | 
|  | 22 | + | 
|  | 23 | +namespace UITests.Tests | 
|  | 24 | +{ | 
|  | 25 | + | 
|  | 26 | +    [TestClass] | 
|  | 27 | +    public class GridSplitterTest : UITestBase | 
|  | 28 | +    { | 
|  | 29 | +        [ClassInitialize] | 
|  | 30 | +        [TestProperty("RunAs", "User")] | 
|  | 31 | +        [TestProperty("Classification", "ScenarioTestSuite")] | 
|  | 32 | +        [TestProperty("Platform", "Any")] | 
|  | 33 | +        public static void ClassInitialize(TestContext testContext) | 
|  | 34 | +        { | 
|  | 35 | +            TestEnvironment.Initialize(testContext, WinUICsUWPSampleApp); | 
|  | 36 | +        } | 
|  | 37 | + | 
|  | 38 | +        [TestMethod] | 
|  | 39 | +        [TestPage("GridSplitterTestPage")] | 
|  | 40 | +        public async Task TestGridSplitterDragHorizontalAsync() | 
|  | 41 | +        { | 
|  | 42 | +            var amount = 50; | 
|  | 43 | +            var tolerance = 10; | 
|  | 44 | + | 
|  | 45 | +            var grid = FindElement.ByName("GridSplitterRoot"); | 
|  | 46 | +            var gridSplitter = FindElement.ById("GridSplitterHorizontal"); | 
|  | 47 | +            var box = FindElement.ByName("TopLeftBox"); | 
|  | 48 | + | 
|  | 49 | +            Verify.IsNotNull(grid, "Can't find GridSplitterRoot"); | 
|  | 50 | +            Verify.IsNotNull(gridSplitter, "Can't find Horizontal GridSplitter"); | 
|  | 51 | +            Verify.IsNotNull(box, "Can't find box"); | 
|  | 52 | + | 
|  | 53 | +            var width = box.BoundingRectangle.Width; | 
|  | 54 | + | 
|  | 55 | +            ColumnDefinition columnDefinitionStart = (await VisualTreeHelper.FindElementPropertyAsync<List<ColumnDefinition>>("GridSplitterRoot", "ColumnDefinitions"))?.FirstOrDefault(); | 
|  | 56 | + | 
|  | 57 | +            Verify.IsNotNull(columnDefinitionStart, "Couldn't retrieve Column Definition"); | 
|  | 58 | + | 
|  | 59 | +            // Drag to the Left | 
|  | 60 | +            InputHelper.DragDistance(gridSplitter, amount, Direction.West, 1000); | 
|  | 61 | + | 
|  | 62 | +            Wait.ForMilliseconds(1050); | 
|  | 63 | +            Wait.ForIdle(); | 
|  | 64 | + | 
|  | 65 | +            ColumnDefinition columnDefinitionEnd = (await VisualTreeHelper.FindElementPropertyAsync<List<ColumnDefinition>>("GridSplitterRoot", "ColumnDefinitions"))?.FirstOrDefault(); | 
|  | 66 | + | 
|  | 67 | +            Wait.ForIdle(); | 
|  | 68 | + | 
|  | 69 | +            Verify.IsTrue(Math.Abs(columnDefinitionStart.ActualWidth - amount - columnDefinitionEnd.ActualWidth) <= tolerance, $"ColumnDefinition not in range expected {columnDefinitionStart.ActualWidth - amount} was {columnDefinitionEnd.ActualWidth}"); | 
|  | 70 | + | 
|  | 71 | +            Verify.IsTrue(Math.Abs(width - amount - box.BoundingRectangle.Width) <= tolerance, $"Bounding box not in range expected {width - amount} was {box.BoundingRectangle.Width}."); | 
|  | 72 | +        } | 
|  | 73 | + | 
|  | 74 | +        [TestMethod] | 
|  | 75 | +        [TestPage("GridSplitterTestPage")] | 
|  | 76 | +        public async Task TestGridSplitterDragHorizontalPastMinimumAsync() | 
|  | 77 | +        { | 
|  | 78 | +            var amount = 150; | 
|  | 79 | + | 
|  | 80 | +            var gridSplitter = FindElement.ById("GridSplitterHorizontal"); | 
|  | 81 | + | 
|  | 82 | +            Verify.IsNotNull(gridSplitter, "Can't find Horizontal GridSplitter"); | 
|  | 83 | + | 
|  | 84 | +            // Drag to the Left | 
|  | 85 | +            InputHelper.DragDistance(gridSplitter, amount, Direction.West, 1000); | 
|  | 86 | + | 
|  | 87 | +            Wait.ForMilliseconds(1050); | 
|  | 88 | +            Wait.ForIdle(); | 
|  | 89 | + | 
|  | 90 | +            ColumnDefinition columnDefinitionEnd = (await VisualTreeHelper.FindElementPropertyAsync<List<ColumnDefinition>>("GridSplitterRoot", "ColumnDefinitions"))?.FirstOrDefault(); | 
|  | 91 | + | 
|  | 92 | +            Wait.ForIdle(); | 
|  | 93 | + | 
|  | 94 | +            Verify.AreEqual(columnDefinitionEnd.MinWidth, columnDefinitionEnd.ActualWidth, "Column was not the minimum size expected."); | 
|  | 95 | +        } | 
|  | 96 | + | 
|  | 97 | +        private class ColumnDefinition | 
|  | 98 | +        { | 
|  | 99 | +            public GridLength Width { get; set; } | 
|  | 100 | + | 
|  | 101 | +            public double ActualWidth { get; set; } | 
|  | 102 | + | 
|  | 103 | +            public double MinWidth { get; set; } | 
|  | 104 | + | 
|  | 105 | +            public double MaxWidth { get; set; } | 
|  | 106 | +        } | 
|  | 107 | + | 
|  | 108 | +        private class GridLength | 
|  | 109 | +        { | 
|  | 110 | +            public int GridUnitType { get; set; } // 0 Auto, 1 Pixel, 2 Star | 
|  | 111 | + | 
|  | 112 | +            public double Value { get; set; } | 
|  | 113 | +        } | 
|  | 114 | +    } | 
|  | 115 | +} | 
0 commit comments