|
10 | 10 | using Xunit;
|
11 | 11 | using Xunit.Abstractions;
|
12 | 12 |
|
| 13 | +using static MaterialDesignThemes.UITests.MaterialDesignSpec; |
| 14 | + |
13 | 15 | namespace MaterialDesignThemes.UITests.WPF.DialogHosts
|
14 | 16 | {
|
15 | 17 | public class DialogHostTests : TestBase
|
16 |
| - { |
| 18 | + { |
17 | 19 | public DialogHostTests(ITestOutputHelper output) : base(output)
|
18 | 20 | {
|
19 | 21 | }
|
@@ -101,7 +103,7 @@ public async Task FontSettingsSholdInheritIntoDialog()
|
101 | 103 | </Grid>");
|
102 | 104 | var showButton1 = await grid.GetElement<Button>("ShowButton1");
|
103 | 105 | var showButton2 = await grid.GetElement<Button>("ShowButton2");
|
104 |
| - |
| 106 | + |
105 | 107 | await showButton1.LeftClick();
|
106 | 108 | await showButton2.LeftClick();
|
107 | 109 | await Task.Delay(300);
|
@@ -163,5 +165,83 @@ await Wait.For(async () =>
|
163 | 165 | Assert.Equal(Colors.Red, await card2.GetBackgroundColor());
|
164 | 166 | });
|
165 | 167 | }
|
| 168 | + |
| 169 | + [Theory] |
| 170 | + [InlineData(BaseTheme.Inherit)] |
| 171 | + [InlineData(BaseTheme.Dark)] |
| 172 | + [InlineData(BaseTheme.Light)] |
| 173 | + public async Task DialogBackgroundShouldInheritThemeBackground(BaseTheme dialogTheme) |
| 174 | + { |
| 175 | + await using var recorder = new TestRecorder(App); |
| 176 | + |
| 177 | + IVisualElement grid = await LoadXaml<Grid>($@" |
| 178 | +<Grid> |
| 179 | + <Grid.ColumnDefinitions> |
| 180 | + <ColumnDefinition /> |
| 181 | + <ColumnDefinition /> |
| 182 | + </Grid.ColumnDefinitions> |
| 183 | +
|
| 184 | + <materialDesign:DialogHost DialogTheme=""{dialogTheme}"" x:Name=""DialogHost1""> |
| 185 | + <materialDesign:DialogHost.DialogContent> |
| 186 | + <TextBlock Text=""Some Text"" x:Name=""TextBlock1"" Margin=""50"" /> |
| 187 | + </materialDesign:DialogHost.DialogContent> |
| 188 | + <Button Content=""Show Dialog"" x:Name=""ShowButton1"" Command=""{{x:Static materialDesign:DialogHost.OpenDialogCommand}}"" /> |
| 189 | + </materialDesign:DialogHost> |
| 190 | +
|
| 191 | + <materialDesign:DialogHost Style=""{{StaticResource MaterialDesignEmbeddedDialogHost}}"" DialogTheme=""{dialogTheme}"" x:Name=""DialogHost2"" Grid.Column=""1""> |
| 192 | + <materialDesign:DialogHost.DialogContent> |
| 193 | + <TextBlock Text=""Some Text"" x:Name=""TextBlock2"" Margin=""50"" /> |
| 194 | + </materialDesign:DialogHost.DialogContent> |
| 195 | + <Button Content=""Show Dialog"" x:Name=""ShowButton2"" Command=""{{x:Static materialDesign:DialogHost.OpenDialogCommand}}"" /> |
| 196 | + </materialDesign:DialogHost> |
| 197 | +
|
| 198 | +</Grid>"); |
| 199 | + var showButton1 = await grid.GetElement<Button>("ShowButton1"); |
| 200 | + var showButton2 = await grid.GetElement<Button>("ShowButton2"); |
| 201 | + |
| 202 | + await showButton1.LeftClick(); |
| 203 | + await showButton2.LeftClick(); |
| 204 | + |
| 205 | + var dialogHost1 = await grid.GetElement<DialogHost>("DialogHost1"); |
| 206 | + var dialogHost2 = await grid.GetElement<DialogHost>("DialogHost2"); |
| 207 | + |
| 208 | + var card1 = await Wait.For(async () => await dialogHost1.GetElement<Card>("PART_PopupContentElement")); |
| 209 | + var card2 = await Wait.For(async () => await dialogHost2.GetElement<Card>("PART_PopupContentElement")); |
| 210 | + |
| 211 | + IResource paperResource1 = await card1.GetResource("MaterialDesignPaper"); |
| 212 | + var paperBrush1 = paperResource1.GetAs<SolidColorBrush>(); |
| 213 | + Assert.NotNull(paperBrush1); |
| 214 | + paperBrush1!.Freeze(); |
| 215 | + IResource paperResource2 = await card1.GetResource("MaterialDesignPaper"); |
| 216 | + var paperBrush2 = paperResource2.GetAs<SolidColorBrush>(); |
| 217 | + Assert.NotNull(paperBrush2); |
| 218 | + paperBrush2!.Freeze(); |
| 219 | + |
| 220 | + Assert.Equal(paperBrush1.Color, await card1.GetBackgroundColor()); |
| 221 | + Assert.Equal(paperBrush2.Color, await card2.GetBackgroundColor()); |
| 222 | + |
| 223 | + var textBlock1 = await dialogHost1.GetElement<TextBlock>("TextBlock1"); |
| 224 | + var textBlock2 = await dialogHost2.GetElement<TextBlock>("TextBlock2"); |
| 225 | + |
| 226 | + await Wait.For(async () => |
| 227 | + { |
| 228 | + Color? foreground1 = await textBlock1.GetForegroundColor(); |
| 229 | + Assert.NotNull(foreground1); |
| 230 | + AssertContrastRatio( |
| 231 | + foreground1.Value, |
| 232 | + await textBlock1.GetEffectiveBackground(), |
| 233 | + MinimumContrastSmallText); |
| 234 | + }); |
| 235 | + |
| 236 | + await Wait.For(async () => |
| 237 | + { |
| 238 | + Color? foreground2 = await textBlock2.GetForegroundColor(); |
| 239 | + Assert.NotNull(foreground2); |
| 240 | + AssertContrastRatio( |
| 241 | + foreground2.Value, |
| 242 | + await textBlock2.GetEffectiveBackground(), |
| 243 | + MinimumContrastSmallText); |
| 244 | + }); |
| 245 | + } |
166 | 246 | }
|
167 | 247 | }
|
0 commit comments