Esempio n. 1
0
        public async Task Mode_SetsThemeColors(ColorZoneMode mode, string backgroundBrush, string foregroundBrush)
        {
            await using var recorder = new TestRecorder(App);

            IVisualElement <ColorZone> colorZone = await LoadXaml <ColorZone>(@$ "
<materialDesign:ColorZone Mode=" "{mode}" "/>
");

            Color background = await GetThemeColor(backgroundBrush);

            Color foreground = await GetThemeColor(foregroundBrush);

            Assert.Equal(background, await colorZone.GetBackgroundColor());
            Assert.Equal(foreground, await colorZone.GetForegroundColor());

            recorder.Success();
        }
Esempio n. 2
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}");
            }
        }
Esempio n. 3
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();
        }
Esempio n. 4
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();
    }
Esempio n. 5
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();
        }