public async Task DrawerHost_CancelingClosingEvent_DrawerStaysOpen()
    {
        await using var recorder = new TestRecorder(App);

        IVisualElement <DrawerHost> drawerHost = (await LoadUserControl <CancellingDrawerHost>()).As <DrawerHost>();
        var showButton = await drawerHost.GetElement <Button>("ShowButton");

        var closeButton = await drawerHost.GetElement <Button>("CloseButton");

        var closeButtonDp = await drawerHost.GetElement <Button>("CloseButtonDp");

        var openedEvent = await drawerHost.RegisterForEvent(nameof(DrawerHost.DrawerOpened));

        await showButton.LeftClick();

        //Allow open animation to finish
        await Task.Delay(300);

        await Wait.For(async() => (await openedEvent.GetInvocations()).Count == 1);

        var closingEvent = await drawerHost.RegisterForEvent(nameof(DrawerHost.DrawerClosing));

        //Attempt closing with routed command
        await closeButton.LeftClick();

        await Task.Delay(100);

        await Wait.For(async() => (await closingEvent.GetInvocations()).Count == 1);

        Assert.True(await drawerHost.GetIsLeftDrawerOpen());

        //Attempt closing with click away
        await drawerHost.LeftClick();

        await Task.Delay(100);

        await Wait.For(async() => (await closingEvent.GetInvocations()).Count == 2);

        Assert.True(await drawerHost.GetIsLeftDrawerOpen());

        //Attempt closing with DP property toggle
        await closeButtonDp.LeftClick();

        await Task.Delay(100);

        await Wait.For(async() => (await closingEvent.GetInvocations()).Count == 3);

        Assert.True(await drawerHost.GetIsLeftDrawerOpen());


        recorder.Success();
    }
Example #2
0
        public async Task ScrollBarAssist_ButtonsVisibility_HidesButtonsOnMinimalistStyle()
        {
            await using var recorder = new TestRecorder(App);

            string xaml = @"<ListBox Height=""300"" Width=""300""
materialDesign:ScrollBarAssist.ButtonsVisibility=""Collapsed"" 
ScrollViewer.HorizontalScrollBarVisibility=""Visible"" 
ScrollViewer.VerticalScrollBarVisibility=""Visible"">
<ListBox.Resources>
    <Style BasedOn=""{StaticResource MaterialDesignScrollBarMinimal}"" TargetType=""{x:Type ScrollBar}"" />
</ListBox.Resources>
";

            for (int i = 0; i < 50; i++)
            {
                xaml += $"    <ListBoxItem>This is a pretty long meaningless text just to make horizontal scrollbar visibile</ListBoxItem>{Environment.NewLine}";
            }
            xaml += "</ListBox>";

            IVisualElement listBox = await LoadXaml(xaml);

            IVisualElement verticalScrollBar = await listBox.GetElement("PART_VerticalScrollBar");

            IVisualElement horizontalScrollBar = await listBox.GetElement("PART_HorizontalScrollBar");

            Assert.Equal(17, await verticalScrollBar.GetActualWidth());
            var verticalThumb = await verticalScrollBar.GetElement("/Thumb~border");

            Assert.Equal(10, await verticalThumb.GetActualWidth());
            var upButton = await verticalScrollBar.GetElement("PART_LineUpButton");

            Assert.False(await upButton.GetIsVisible());
            var downButton = await verticalScrollBar.GetElement("PART_LineDownButton");

            Assert.False(await downButton.GetIsVisible());

            Assert.Equal(17, await horizontalScrollBar.GetActualHeight());
            var horizontalThumb = await horizontalScrollBar.GetElement("/Thumb~border");

            Assert.Equal(10, await horizontalThumb.GetActualHeight());
            var leftButton = await horizontalScrollBar.GetElement("PART_LineLeftButton");

            Assert.False(await upButton.GetIsVisible());
            var rightButton = await horizontalScrollBar.GetElement("PART_LineRightButton");

            Assert.False(await downButton.GetIsVisible());

            recorder.Success();
        }
Example #3
0
        public async Task OutlinedButton_BorderCanBeOverridden()
        {
            await using var recorder = new TestRecorder(App);

            //Arrange
            IVisualElement button = await LoadXaml(
                @"<Button Content=""Button""
                          Style=""{StaticResource MaterialDesignOutlinedButton}""
                          BorderThickness=""5""
                          BorderBrush=""Red""
                    />");

            Color midColor = await GetThemeColor("PrimaryHueMidBrush");

            IVisualElement?internalBorder = await button.GetElement("border");

            //Act
            Thickness borderThickness = await internalBorder.GetProperty <Thickness>(nameof(Border.BorderThickness));

            SolidColorBrush borderBrush = await internalBorder.GetProperty <SolidColorBrush>(nameof(Border.BorderBrush));

            //Assert
            Assert.Equal(new Thickness(5), borderThickness);
            Assert.Equal(Colors.Red, borderBrush.Color);

            recorder.Success();
        }
Example #4
0
        public async Task OutlinedButton_OnMouseOver_UsesThemeBrush()
        {
            await using var recorder = new TestRecorder(App);

            //Arrange
            IVisualElement button = await LoadXaml(
                @"<Button Content=""Button"" Style=""{StaticResource MaterialDesignOutlinedButton}""/>");

            Color midColor = await GetThemeColor("PrimaryHueMidBrush");

            IVisualElement?internalBorder = await button.GetElement("border");

            //Act
            await button.MoveCursorToElement(Position.Center);

            await Wait.For(async() =>
            {
                SolidColorBrush internalBorderBackground = await internalBorder.GetProperty <SolidColorBrush>(nameof(Border.Background));

                //Assert
                Assert.Equal(midColor, internalBorderBackground.Color);
            });

            recorder.Success();
        }
Example #5
0
        public async Task OnGetElement_ItRetrieveElementFromAdornerLayer()
        {
            IWindow window = await App.CreateWindowWithUserControl <TextBox_ValidationError>();

            IVisualElement textBox = await window.GetElement("/TextBox");

            IVisualElement validationMessage = await textBox.GetElement("ErrorMessageText");

            Assert.IsTrue(await validationMessage.GetIsVisible());
        }
Example #6
0
        public async Task ClosingDialogWithIsOpenProperty_ShouldRaiseDialogClosingEvent()
        {
            await using var recorder = new TestRecorder(App);

            IVisualElement dialogHost = await LoadUserControl <ClosingEventCounter>();

            IVisualElement showButton = await dialogHost.GetElement("ShowDialogButton");

            IVisualElement closeButton = await dialogHost.GetElement("CloseButton");

            IVisualElement resultTextBlock = await dialogHost.GetElement("ResultTextBlock");


            await showButton.Click();

            await Wait.For(async() => await closeButton.GetIsVisible());

            await closeButton.Click();

            await Wait.For(async() => Assert.Equal("1", await resultTextBlock.GetText()));
        }
Example #7
0
        public async Task OnOpenDialog_OverlayCoversContent()
        {
            await using var recorder = new TestRecorder(App);

            IVisualElement dialogHost = await LoadUserControl <WithCounter>();

            IVisualElement resultTextBlock = await dialogHost.GetElement("ResultTextBlock");

            await Wait.For(async() => await resultTextBlock.GetText() == "Clicks: 0");

            IVisualElement testOverlayButton = await dialogHost.GetElement("TestOverlayButton");

            await testOverlayButton.Click();

            await Wait.For(async() => await resultTextBlock.GetText() == "Clicks: 1");

            IVisualElement showDialogButton = await dialogHost.GetElement("ShowDialogButton");

            await showDialogButton.Click();

            IVisualElement closeDialogButton = await dialogHost.GetElement("CloseDialogButton");

            await Wait.For(async() => await closeDialogButton.GetIsVisible() == true);

            await testOverlayButton.Click();

            await Wait.For(async() => await resultTextBlock.GetText() == "Clicks: 1");

            await closeDialogButton.Click();


            await Wait.For(async() =>
            {
                Output.WriteLine("Input");
                await testOverlayButton.Click();
                Assert.Equal("Clicks: 2", await resultTextBlock.GetText());
                Output.WriteLine("Output");
            });
        }
        public async Task OnOpenDialog_OverlayCoversContent()
        {
            await using var recorder = new TestRecorder(App);

            IVisualElement dialogHost = await LoadUserControl <WithCounter>();

            IVisualElement overlay = await dialogHost.GetElement("PART_ContentCoverGrid");

            IVisualElement resultTextBlock = await dialogHost.GetElement("ResultTextBlock");

            await Wait.For(async() => await resultTextBlock.GetText() == "Clicks: 0");

            IVisualElement testOverlayButton = await dialogHost.GetElement("TestOverlayButton");

            await testOverlayButton.Click();

            await Wait.For(async() => await resultTextBlock.GetText() == "Clicks: 1");

            IVisualElement showDialogButton = await dialogHost.GetElement("ShowDialogButton");

            await showDialogButton.Click();

            IVisualElement closeDialogButton = await dialogHost.GetElement("CloseDialogButton");

            await Wait.For(async() => await closeDialogButton.GetIsVisible() == true);

            await testOverlayButton.Click();

            await Wait.For(async() => await resultTextBlock.GetText() == "Clicks: 1");

            await closeDialogButton.Click();

            await Wait.For(async() => await overlay.GetVisibility() != Visibility.Visible);

            await testOverlayButton.Click();

            await Wait.For(async() => Assert.Equal("Clicks: 2", await resultTextBlock.GetText()));
        }
Example #9
0
    public async Task OnLoad_ThemeBrushesSet()
    {
        await using var recorder = new TestRecorder(App);

        //Arrange
        IVisualElement <TabControl> tabControl = await LoadXaml <TabControl>(@"
<TabControl 
        materialDesign:ColorZoneAssist.Mode=""PrimaryMid""
        Style=""{StaticResource MaterialDesignFilledTabControl}"">
    <TabItem Header=""TAB 1"">
        <TextBlock Margin=""8"" Text=""PrimaryMid Tab 1"" />
    </TabItem>
    <TabItem Header=""TAB 2"">
        <TextBlock Margin=""8"" Text=""PrimaryMid Tab 2"" />
    </TabItem>
</TabControl>");

        IVisualElement <TextBlock> textBlock = await tabControl.GetElement <TextBlock>(@"/TabItem[0]/TextBlock[0]");

        IVisualElement <Border> selectedTabBorder = await tabControl.GetElement <Border>(@"/TabItem[0]~SelectionHighlightBorder");

        //Act
        Color?foreground = await textBlock.GetForegroundColor();

        Color?background = await textBlock.GetEffectiveBackground();

        Color?selectedTabUnderline = await selectedTabBorder.GetBorderBrushColor();

        //Assert
        Assert.NotNull(foreground);
        Assert.NotNull(background);

        MaterialDesignSpec.AssertContrastRatio(foreground.Value, background.Value, MaterialDesignSpec.MinimumContrastSmallText);

        Assert.Equal(foreground, selectedTabUnderline);

        recorder.Success();
    }
Example #10
0
        public async Task OnMouseOver_BackgroundIsSet()
        {
            await using var recorder = new TestRecorder(App);

            IVisualElement listBox = await LoadXaml(@"
<ListBox MinWidth=""200"">
    <ListBoxItem Content=""Item1"" />
    <ListBoxItem Content=""Item2"" />
    <ListBoxItem Content=""Item3"" />
    <ListBoxItem Content=""Item4"" />
</ListBox>
");

            IVisualElement listBoxItem = await listBox.GetElement("/ListBoxItem[2]");

            Assert.Equal("Item3", await listBoxItem.GetProperty <string>("Content"));
            IVisualElement mouseOverBorder = await listBoxItem.GetElement("MouseOverBorder");

            await listBox.MoveCursorToElement(Position.TopLeft);

            await Wait.For(async() => Assert.Equal(0.0, await mouseOverBorder.GetOpacity()));

            await mouseOverBorder.MoveCursorToElement();

            await Wait.For(async() =>
            {
                double opacity = await mouseOverBorder.GetOpacity();
                Output.WriteLine($"Got opacity {opacity}");
                Assert.Equal(0.1, opacity);
            });

            Color effectiveBackground = await mouseOverBorder.GetEffectiveBackground();

            Color foreground = await listBoxItem.GetForegroundColor();

            foreground = foreground.FlattenOnto(effectiveBackground);

            float contrastRatio = foreground.ContrastRatio(effectiveBackground);

            Assert.True(contrastRatio >= MaterialDesignSpec.MinimumContrastSmallText);

            recorder.Success();
        }
Example #11
0
        public async Task CharacterCount_WithMaxLengthSetAndCharacterCounterVisibilityCollapsed_IsNotDisplayed()
        {
            await using var recorder = new TestRecorder(App);

            IVisualElement grid = await LoadXaml(@"
<Grid Margin=""30"">
    <TextBox
        MaxLength=""10""
        materialDesign:TextFieldAssist.CharacterCounterVisibility=""Collapsed""
    />
</Grid>");

            IVisualElement textBox = await grid.GetElement("/TextBox");

            IVisualElement characterCounter = await textBox.GetElement("CharacterCounterTextBlock");

            Assert.False(await characterCounter.GetIsVisible());

            recorder.Success();
        }
        public async Task OnDatePickerHelperTextFontSize_ChangesHelperTextFontSize()
        {
            await using var recorder = new TestRecorder(App);

            var stackPanel = await LoadXaml(@"
<StackPanel>
    <DatePicker materialDesign:HintAssist.HelperTextFontSize=""20""/>
</StackPanel>");

            var timePicker = await stackPanel.GetElement("/DatePicker");

            IVisualElement datePickerTextBox = await timePicker.GetElement("PART_TextBox");

            IVisualElement helpTextBlock = await datePickerTextBox.GetElement("/Grid/Canvas/TextBlock");

            double fontSize = await helpTextBlock.GetProperty <double>(TextBlock.FontSizeProperty.Name);

            Assert.Equal(20, fontSize);
            recorder.Success();
        }
Example #13
0
        public async Task OnClickChoiceChipListBox_ChangesSelectedItem(string listBoxStyle)
        {
            await using var recorder = new TestRecorder(App);

            IVisualElement listBox = await LoadXaml($@"
<ListBox x:Name=""ChipsListBox"" Style=""{{StaticResource {listBoxStyle}}}"">
    <ListBoxItem>Mercury</ListBoxItem>
    <ListBoxItem>Venus</ListBoxItem>
    <ListBoxItem>Earth</ListBoxItem>
    <ListBoxItem>Pluto</ListBoxItem>
</ListBox>
");

            IVisualElement earth = await listBox.GetElement("/ListBoxItem[2]");

            await earth.Click();

            await Wait.For(async() => Assert.Equal(2, await listBox.GetProperty <int>(nameof(Selector.SelectedIndex))));

            recorder.Success();
        }
Example #14
0
        public async Task OutlinedButton_UsesThemeColorForBorder()
        {
            await using var recorder = new TestRecorder(App);

            //Arrange
            IVisualElement button = await LoadXaml(
                @"<Button Content=""Button"" Style=""{StaticResource MaterialDesignOutlinedButton}""/>");

            Color midColor = await GetThemeColor("PrimaryHueMidBrush");

            IVisualElement?internalBorder = await button.GetElement("border");

            //Act
            Color?borderColor = await button.GetProperty <Color?>(nameof(WpfButton.BorderBrush));

            Color?internalBorderColor = await internalBorder.GetProperty <Color?>(nameof(Border.BorderBrush));

            //Assert
            Assert.Equal(midColor, borderColor);
            Assert.Equal(midColor, internalBorderColor);

            recorder.Success();
        }
Example #15
0
        public async Task HelperText_CanSetFontColorWithAttachedStyle()
        {
            await using var recorder = new TestRecorder(App);

            IVisualElement grid = await LoadXaml(@"
<Grid Margin=""30"">
    <TextBox
        materialDesign:HintAssist.HelperText=""Test"">
        <materialDesign:HintAssist.HelperTextStyle>
            <Style TargetType=""TextBlock"" BasedOn=""{StaticResource MaterialDesignHelperTextBlock}"">
                <Setter Property=""Foreground"" Value=""Red"" />
            </Style>
        </materialDesign:HintAssist.HelperTextStyle>
    </TextBox>
</Grid>");

            IVisualElement textBox = await grid.GetElement("/TextBox");

            IVisualElement helperText = await textBox.GetElement("HelperTextTextBlock");

            Assert.Equal(Colors.Red, await helperText.GetForegroundColor());

            recorder.Success();
        }