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

            IVisualElement grid = await LoadXaml(@"
<Grid Background=""Red"">
    <TextBox
        Style=""{StaticResource MaterialDesignOutlinedTextBox}""
        VerticalAlignment=""Top""
        Height=""100""
        Text=""Some content to force hint to float""
        IsEnabled=""false""
        Margin=""30""
        materialDesign:HintAssist.Hint=""This is a text area""/>
</Grid>");

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

            //textFieldGrid is the element just inside of the border
            IVisualElement textFieldGrid = await textBox.GetElement("textFieldGrid");

            IVisualElement hintBackground = await textBox.GetElement("HintBackgroundBorder");

            Color background = await hintBackground.GetEffectiveBackground(textFieldGrid);

            Assert.Equal(255, background.A);
            recorder.Success();
        }
Example #2
0
        public async Task OnGetEffectiveBackground_ReturnsFirstOpaqueColor()
        {
            await Window.SetXamlContent(@"<Border x:Name=""MyBorder"" />");

            await Window.SetBackgroundColor(Colors.Red);

            IVisualElement element = await Window.GetElement("MyBorder");

            Color background = await element.GetEffectiveBackground();

            Assert.AreEqual(Colors.Red, background);
        }
Example #3
0
        public async Task OnGetEffectiveBackground_ReturnsFirstOpaqueColor()
        {
            IWindow window = await App.CreateWindowWithContent(
                @"<Border x:Name=""MyBorder"" />",
                background : "Red");

            IVisualElement element = await window.GetElement("MyBorder");

            Color background = await element.GetEffectiveBackground();

            Assert.AreEqual(Colors.Red, background);
        }
Example #4
0
        public async Task OnGetEffectiveBackground_ReturnsOpaquePanelColor()
        {
            IWindow window = await App.CreateWindowWithContent(@"
<Grid Background=""Red"">
    <TextBlock />
</Grid>
",
                                                               background : "Blue");

            IVisualElement element = await window.GetElement("/TextBlock");

            Color background = await element.GetEffectiveBackground();

            Assert.AreEqual(Colors.Red, background);
        }
Example #5
0
        public async Task OnGetEffectiveBackground_ReturnsOpaquePanelColor()
        {
            await Window.SetXamlContent(@"
<Grid Background=""Red"">
    <TextBlock />
</Grid>
");

            await Window.SetBackgroundColor(Colors.Blue);

            IVisualElement element = await Window.GetElement("/TextBlock");

            Color background = await element.GetEffectiveBackground();

            Assert.AreEqual(Colors.Red, background);
        }
Example #6
0
        public async Task OnGetEffectiveBackground_StopsProcessingAtDefinedParent()
        {
            IWindow window = await App.CreateWindowWithContent(@"
<Grid Background=""#DDFF0000"">
    <TextBlock />
</Grid>
",
                                                               background : "Blue");

            IVisualElement child = await window.GetElement("/TextBlock");

            IVisualElement parent = await window.GetElement("/Grid");

            Color background = await child.GetEffectiveBackground(parent);

            Assert.AreEqual(Color.FromArgb(0xDD, 0xFF, 0x00, 0x00), background);
        }
Example #7
0
        public async Task PrimaryColor_AdjustToTheme(PrimaryColor primary)
        {
            await using var recorder = new TestRecorder(App);

            await App.InitialzeWithMaterialDesign(BaseTheme.Light, primary, colorAdjustment : new ColorAdjustment());

            IWindow window = await App.CreateWindow <ColorAdjustWindow>();

            await recorder.SaveScreenshot();

            Color windowBackground = await window.GetBackgroundColor();

            IVisualElement themeToggle = await window.GetElement("/ToggleButton");

            IVisualElement largeText = await window.GetElement("/TextBlock[0]");

            IVisualElement smallText = await window.GetElement("/TextBlock[1]");

            await AssertContrastRatio();

            await themeToggle.Click();

            await Wait.For(async() => await window.GetBackgroundColor() != windowBackground);

            await AssertContrastRatio();

            recorder.Success();

            async Task AssertContrastRatio()
            {
                Color largeTextForeground = await largeText.GetForegroundColor();

                Color largeTextBackground = await largeText.GetEffectiveBackground();

                Color smallTextForeground = await smallText.GetForegroundColor();

                Color smallTextBackground = await smallText.GetEffectiveBackground();

                var largeContrastRatio = ColorAssist.ContrastRatio(largeTextForeground, largeTextBackground);

                Assert.True(largeContrastRatio >= MaterialDesignSpec.MinimumContrastLargeText, $"Large font contrast ratio '{largeContrastRatio}' does not meet material design spec {MaterialDesignSpec.MinimumContrastLargeText}");
                var smallContrastRatio = ColorAssist.ContrastRatio(smallTextForeground, smallTextBackground);

                Assert.True(smallContrastRatio >= MaterialDesignSpec.MinimumContrastSmallText, $"Small font contrast ratio '{smallContrastRatio}' does not meet material design spec {MaterialDesignSpec.MinimumContrastSmallText}");
            }
        }
Example #8
0
        public async Task OnGetEffectiveBackground_StopsProcessingAtDefinedParent()
        {
            await Window.SetXamlContent(@"
<Grid Background=""#DDFF0000"">
    <TextBlock />
</Grid>
");

            await Window.SetBackgroundColor(Colors.Blue);

            IVisualElement child = await Window.GetElement("/TextBlock");

            IVisualElement parent = await Window.GetElement("/Grid");

            Color background = await child.GetEffectiveBackground(parent);

            Assert.AreEqual(Color.FromArgb(0xDD, 0xFF, 0x00, 0x00), background);
        }
Example #9
0
        public async Task OnGetEffectiveBackground_ReturnsMergingOfTransparentColors()
        {
            var backgroundParent = Colors.Blue;
            var backgroundChild  = Color.FromArgb(0xDD, 0, 0, 0);
            await Window.SetXamlContent($@"
<Border Background=""{backgroundParent}"">
  <Border x:Name=""MyBorder"" Background=""{backgroundChild}"" />
</Border>");

            await Window.SetBackgroundColor(Colors.Red);

            IVisualElement element = await Window.GetElement("MyBorder");

            Color background = await element.GetEffectiveBackground();

            var expected = backgroundChild.FlattenOnto(backgroundParent);

            Assert.AreEqual(expected, background);
        }
Example #10
0
        public async Task OnGetEffectiveBackground_AppliesOpacityFromParents()
        {
            IWindow window = await App.CreateWindowWithContent(@"
<Grid Background=""Red"" Opacity=""0.5"" x:Name=""RedGrid"">
    <Grid Background=""Blue"" x:Name=""BlueGrid"">
        <TextBlock />
    </Grid>
</Grid>
",
                                                               background : "Lime");

            IVisualElement child = await window.GetElement("/TextBlock");

            IVisualElement parent = await window.GetElement("BlueGrid");

            Color background = await child.GetEffectiveBackground(parent);

            Assert.AreEqual(Color.FromArgb(127, 0x00, 0x00, 0xFF), background);
        }
Example #11
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 #12
0
        public async Task OnGetEffectiveBackground_AppliesOpacityFromParents()
        {
            await Window.SetXamlContent(@"
<Grid Background=""Red"" Opacity=""0.5"" x:Name=""RedGrid"">
    <Grid Background=""Blue"" x:Name=""BlueGrid"">
        <TextBlock />
    </Grid>
</Grid>
");

            await Window.SetBackgroundColor(Colors.Lime);

            IVisualElement child = await Window.GetElement("/TextBlock");

            IVisualElement parent = await Window.GetElement("BlueGrid");

            Color background = await child.GetEffectiveBackground(parent);

            Assert.AreEqual(Color.FromArgb(127, 0x00, 0x00, 0xFF), background);
        }
Example #13
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 #14
0
 public static async Task <Color> GetEffectiveBackground(this IVisualElement element)
 => await element.GetEffectiveBackground(null);