-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Expand file tree
/
Copy pathDialogHostTests.cs
More file actions
578 lines (460 loc) · 24.1 KB
/
DialogHostTests.cs
File metadata and controls
578 lines (460 loc) · 24.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
using System.ComponentModel;
using System.Windows.Media;
using MaterialDesignThemes.UITests.Samples.DialogHost;
using static MaterialDesignThemes.UITests.MaterialDesignSpec;
namespace MaterialDesignThemes.UITests.WPF.DialogHosts;
public class DialogHostTests : TestBase
{
public DialogHostTests()
{
AttachedDebuggerToRemoteProcess = false;
}
[Test]
public async Task OnOpenDialog_OverlayCoversContent()
{
await using var recorder = new TestRecorder(App);
IVisualElement dialogHost = await LoadUserControl<WithCounter>();
var overlay = await dialogHost.GetElement<Grid>("PART_ContentCoverGrid");
var resultTextBlock = await dialogHost.GetElement<TextBlock>("ResultTextBlock");
await Wait.For(async () => await resultTextBlock.GetText() == "Clicks: 0");
var testOverlayButton = await dialogHost.GetElement<Button>("TestOverlayButton");
await testOverlayButton.LeftClick();
await Wait.For(async () => await resultTextBlock.GetText() == "Clicks: 1");
var showDialogButton = await dialogHost.GetElement<Button>("ShowDialogButton");
await showDialogButton.LeftClick();
var closeDialogButton = await dialogHost.GetElement<Button>("CloseDialogButton");
await Wait.For(async () => await closeDialogButton.GetIsVisible() == true);
await testOverlayButton.LeftClick();
await Wait.For(async () => await resultTextBlock.GetText() == "Clicks: 1");
await Task.Delay(200, TestContext.Current!.CancellationToken);
await closeDialogButton.LeftClick();
var retry = new Retry(5, TimeSpan.FromSeconds(5));
try
{
await Wait.For(async () => await overlay.GetVisibility() != Visibility.Visible, retry);
}
catch (TimeoutException)
{
await closeDialogButton.LeftClick();
await Wait.For(async () => await overlay.GetVisibility() != Visibility.Visible, retry);
}
await testOverlayButton.LeftClick();
await Wait.For(async () =>
{
await Assert.That((await resultTextBlock.GetText())!).IsEqualTo("Clicks: 2");
}, retry);
recorder.Success();
}
[Test]
[Description("Issue 2282")]
public async Task ClosingDialogWithIsOpenProperty_ShouldRaiseDialogClosingEvent()
{
await using var recorder = new TestRecorder(App);
IVisualElement dialogHost = await LoadUserControl<ClosingEventCounter>();
var showButton = await dialogHost.GetElement<Button>("ShowDialogButton");
var closeButton = await dialogHost.GetElement<Button>("CloseButton");
var resultTextBlock = await dialogHost.GetElement<TextBlock>("ResultTextBlock");
await showButton.LeftClick();
await Wait.For(async () => await closeButton.GetIsVisible());
await Task.Delay(300, TestContext.Current!.CancellationToken);
await closeButton.LeftClick();
await Wait.For(async () =>
{
await Assert.That(await resultTextBlock.GetText()).IsEqualTo("1");
});
recorder.Success();
}
[Test]
[Description("Issue 2398")]
public async Task FontSettingsShouldInheritIntoDialog()
{
await using var recorder = new TestRecorder(App);
IVisualElement grid = await LoadXaml<Grid>(@"
<Grid TextElement.FontSize=""42""
TextElement.FontFamily=""Times New Roman""
TextElement.FontWeight=""ExtraBold"">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<materialDesign:DialogHost>
<materialDesign:DialogHost.DialogContent>
<TextBlock Text=""Some Text"" x:Name=""TextBlock1"" />
</materialDesign:DialogHost.DialogContent>
<Button Content=""Show Dialog"" x:Name=""ShowButton1"" Command=""{x:Static materialDesign:DialogHost.OpenDialogCommand}"" />
</materialDesign:DialogHost>
<materialDesign:DialogHost Style=""{StaticResource MaterialDesignEmbeddedDialogHost}"" Grid.Column=""1"">
<materialDesign:DialogHost.DialogContent>
<TextBlock Text=""Some Text"" x:Name=""TextBlock2"" />
</materialDesign:DialogHost.DialogContent>
<Button Content=""Show Dialog"" x:Name=""ShowButton2"" Command=""{x:Static materialDesign:DialogHost.OpenDialogCommand}"" />
</materialDesign:DialogHost>
</Grid>");
var showButton1 = await grid.GetElement<Button>("ShowButton1");
var showButton2 = await grid.GetElement<Button>("ShowButton2");
await showButton1.LeftClick();
await showButton2.LeftClick();
await Task.Delay(300, TestContext.Current!.CancellationToken);
var text1 = await grid.GetElement<TextBlock>("TextBlock1");
var text2 = await grid.GetElement<TextBlock>("TextBlock2");
await Assert.That(await text1.GetFontSize()).IsEqualTo(42);
await Assert.That((await text1.GetFontFamily())?.FamilyNames.Values.Contains("Times New Roman")).IsTrue();
await Assert.That(await text1.GetFontWeight()).IsEqualTo(FontWeights.ExtraBold);
await Assert.That(await text2.GetFontSize()).IsEqualTo(42);
await Assert.That((await text2.GetFontFamily())?.FamilyNames.Values.Contains("Times New Roman")).IsTrue();
await Assert.That(await text2.GetFontWeight()).IsEqualTo(FontWeights.ExtraBold);
recorder.Success();
}
[Test]
[Description("PR 2236")]
public async Task ContentBackground_SetsDialogBackground()
{
await using var recorder = new TestRecorder(App);
IVisualElement grid = await LoadXaml<Grid>(@"
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<materialDesign:DialogHost DialogBackground=""Red"" x:Name=""DialogHost1"">
<materialDesign:DialogHost.DialogContent>
<TextBlock Text=""Some Text"" x:Name=""TextBlock1"" />
</materialDesign:DialogHost.DialogContent>
<Button Content=""Show Dialog"" x:Name=""ShowButton1"" Command=""{x:Static materialDesign:DialogHost.OpenDialogCommand}"" />
</materialDesign:DialogHost>
<materialDesign:DialogHost Style=""{StaticResource MaterialDesignEmbeddedDialogHost}"" DialogBackground=""Red"" x:Name=""DialogHost2"" Grid.Column=""1"">
<materialDesign:DialogHost.DialogContent>
<TextBlock Text=""Some Text"" x:Name=""TextBlock2"" />
</materialDesign:DialogHost.DialogContent>
<Button Content=""Show Dialog"" x:Name=""ShowButton2"" Command=""{x:Static materialDesign:DialogHost.OpenDialogCommand}"" />
</materialDesign:DialogHost>
</Grid>");
var showButton1 = await grid.GetElement<Button>("ShowButton1");
var showButton2 = await grid.GetElement<Button>("ShowButton2");
await showButton1.LeftClick();
await showButton2.LeftClick();
var dialogHost1 = await grid.GetElement<DialogHost>("DialogHost1");
var dialogHost2 = await grid.GetElement<DialogHost>("DialogHost2");
await Wait.For(async () =>
{
var card1 = await dialogHost1.GetElement<Card>("PART_PopupContentElement");
var card2 = await dialogHost2.GetElement<Card>("PART_PopupContentElement");
await Assert.That(await card1.GetBackgroundColor()).IsEqualTo(Colors.Red);
await Assert.That(await card2.GetBackgroundColor()).IsEqualTo(Colors.Red);
});
recorder.Success();
}
[Test]
[Arguments(BaseTheme.Inherit)]
[Arguments(BaseTheme.Dark)]
[Arguments(BaseTheme.Light)]
public async Task DialogBackgroundShouldInheritThemeBackground(BaseTheme dialogTheme)
{
await using var recorder = new TestRecorder(App);
IVisualElement grid = await LoadXaml<Grid>($@"
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<materialDesign:DialogHost DialogTheme=""{dialogTheme}"" x:Name=""DialogHost1"">
<materialDesign:DialogHost.DialogContent>
<TextBlock Text=""Some Text"" x:Name=""TextBlock1"" Margin=""50"" />
</materialDesign:DialogHost.DialogContent>
<Button Content=""Show Dialog"" x:Name=""ShowButton1"" Command=""{{x:Static materialDesign:DialogHost.OpenDialogCommand}}"" />
</materialDesign:DialogHost>
<materialDesign:DialogHost Style=""{{StaticResource MaterialDesignEmbeddedDialogHost}}"" DialogTheme=""{dialogTheme}"" x:Name=""DialogHost2"" Grid.Column=""1"">
<materialDesign:DialogHost.DialogContent>
<TextBlock Text=""Some Text"" x:Name=""TextBlock2"" Margin=""50"" />
</materialDesign:DialogHost.DialogContent>
<Button Content=""Show Dialog"" x:Name=""ShowButton2"" Command=""{{x:Static materialDesign:DialogHost.OpenDialogCommand}}"" />
</materialDesign:DialogHost>
</Grid>");
var showButton1 = await grid.GetElement<Button>("ShowButton1");
var showButton2 = await grid.GetElement<Button>("ShowButton2");
await showButton1.LeftClick();
await showButton2.LeftClick();
var dialogHost1 = await grid.GetElement<DialogHost>("DialogHost1");
var dialogHost2 = await grid.GetElement<DialogHost>("DialogHost2");
var card1 = await Wait.For(async () => await dialogHost1.GetElement<Card>("PART_PopupContentElement"));
var card2 = await Wait.For(async () => await dialogHost2.GetElement<Card>("PART_PopupContentElement"));
IResource paperResource1 = await card1.GetResource("MaterialDesign.Brush.Background");
var paperBrush1 = paperResource1.GetAs<SolidColorBrush>();
await Assert.That(paperBrush1).IsNotNull();
paperBrush1!.Freeze();
IResource paperResource2 = await card1.GetResource("MaterialDesign.Brush.Background");
var paperBrush2 = paperResource2.GetAs<SolidColorBrush>();
await Assert.That(paperBrush2).IsNotNull();
paperBrush2!.Freeze();
await Assert.That(await card1.GetBackgroundColor()).IsEqualTo(paperBrush1.Color);
await Assert.That(await card2.GetBackgroundColor()).IsEqualTo(paperBrush2.Color);
var textBlock1 = await dialogHost1.GetElement<TextBlock>("TextBlock1");
var textBlock2 = await dialogHost2.GetElement<TextBlock>("TextBlock2");
await Wait.For(async () =>
{
Color? foreground1 = await textBlock1.GetForegroundColor();
await Assert.That(foreground1).IsNotNull();
await AssertContrastRatio(
foreground1.Value,
await textBlock1.GetEffectiveBackground(),
MinimumContrastSmallText);
});
await Wait.For(async () =>
{
Color? foreground2 = await textBlock2.GetForegroundColor();
await Assert.That(foreground2).IsNotNull();
await AssertContrastRatio(
foreground2.Value,
await textBlock2.GetEffectiveBackground(),
MinimumContrastSmallText);
});
recorder.Success();
}
[Test]
[Description("Issue 2772")]
public async Task CornerRadius_AppliedToContentCoverBorder_WhenSetOnDialogHost()
{
await using var recorder = new TestRecorder(App);
IVisualElement grid = await LoadXaml<Grid>(@"
<Grid>
<materialDesign:DialogHost x:Name=""DialogHost"" CornerRadius=""1,2,3,4"">
<materialDesign:DialogHost.DialogContent>
<TextBlock Text=""Some Text"" />
</materialDesign:DialogHost.DialogContent>
<Button Content=""Show Dialog"" x:Name=""ShowButton"" Command=""{x:Static materialDesign:DialogHost.OpenDialogCommand}"" />
</materialDesign:DialogHost>
</Grid>");
var showButton = await grid.GetElement<Button>("ShowButton");
var dialogHost = await grid.GetElement<DialogHost>("DialogHost");
await showButton.LeftClick();
await Wait.For(async () =>
{
var contentCoverBorder = await dialogHost.GetElement<Border>("ContentCoverBorder");
await Assert.That((await contentCoverBorder.GetCornerRadius()).TopLeft).IsEqualTo(1);
await Assert.That((await contentCoverBorder.GetCornerRadius()).TopRight).IsEqualTo(2);
await Assert.That((await contentCoverBorder.GetCornerRadius()).BottomRight).IsEqualTo(3);
await Assert.That((await contentCoverBorder.GetCornerRadius()).BottomLeft).IsEqualTo(4);
});
recorder.Success();
}
[Test]
[Description("Issue 2772")]
public async Task CornerRadius_AppliedToContentCoverBorder_WhenSetOnEmbeddedDialogHost()
{
await using var recorder = new TestRecorder(App);
IVisualElement grid = await LoadXaml<Grid>(@"
<Grid>
<materialDesign:DialogHost x:Name=""DialogHost"" Style=""{StaticResource MaterialDesignEmbeddedDialogHost}"" CornerRadius=""1,2,3,4"">
<materialDesign:DialogHost.DialogContent>
<TextBlock Text=""Some Text"" />
</materialDesign:DialogHost.DialogContent>
<Button Content=""Show Dialog"" x:Name=""ShowButton"" Command=""{x:Static materialDesign:DialogHost.OpenDialogCommand}"" />
</materialDesign:DialogHost>
</Grid>");
var showButton = await grid.GetElement<Button>("ShowButton");
var dialogHost = await grid.GetElement<DialogHost>("DialogHost");
await showButton.LeftClick();
await Wait.For(async () =>
{
var contentCoverBorder = await dialogHost.GetElement<Border>("ContentCoverBorder");
await Assert.That((await contentCoverBorder.GetCornerRadius()).TopLeft).IsEqualTo(1);
await Assert.That((await contentCoverBorder.GetCornerRadius()).TopRight).IsEqualTo(2);
await Assert.That((await contentCoverBorder.GetCornerRadius()).BottomRight).IsEqualTo(3);
await Assert.That((await contentCoverBorder.GetCornerRadius()).BottomLeft).IsEqualTo(4);
});
recorder.Success();
}
[Test]
[Description("Issue 3069")]
public async Task DialogHost_WithOpenDialog_ShowsPopupWhenLoaded()
{
await using var recorder = new TestRecorder(App);
IVisualElement<Grid> rootGrid = (await LoadUserControl<LoadAndUnloadControl>()).As<Grid>();
IVisualElement<Button> loadButton = await rootGrid.GetElement<Button>("LoadDialogHost");
IVisualElement<Button> unloadButton = await rootGrid.GetElement<Button>("UnloadDialogHost");
IVisualElement<Button> toggleButton = await rootGrid.GetElement<Button>("ToggleIsOpen");
IVisualElement<DialogHost> dialogHost = await rootGrid.GetElement<DialogHost>("DialogHost");
IVisualElement<Button> closeButton = await dialogHost.GetElement<Button>("CloseButton");
await toggleButton.LeftClick();
await Wait.For(async () => await Assert.That(await dialogHost.GetIsOpen()).IsTrue());
await Wait.For(async () => await Assert.That(await closeButton.GetIsVisible()).IsTrue());
await unloadButton.LeftClick();
await Wait.For(async () => await Assert.That(await closeButton.GetIsVisible()).IsFalse() == false);
await loadButton.LeftClick();
await Wait.For(async () => await Assert.That(await closeButton.GetIsVisible()).IsTrue());
await Wait.For(async () =>
{
await closeButton.LeftClick();
await Assert.That(await dialogHost.GetIsOpen()).IsFalse();
});
recorder.Success();
}
[Test]
[Description("Issue 3094")]
public async Task DialogHost_ChangesSelectedTabItem_DoesNotPerformTabChangeWhenRestoringFocus()
{
await using var recorder = new TestRecorder(App);
IVisualElement<Grid> rootGrid = (await LoadUserControl<RestoreFocus>()).As<Grid>();
IVisualElement<TabItem> tabItem1 = await rootGrid.GetElement<TabItem>("TabItem1");
IVisualElement<TabItem> tabItem2 = await rootGrid.GetElement<TabItem>("TabItem2");
IVisualElement<Button> navigateHomeButton = await rootGrid.GetElement<Button>("NavigateHomeButton");
// Select TabItem2
await tabItem2.LeftClick();
// Open menu
IVisualElement<MenuItem> menuItem1 = await rootGrid.GetElement<MenuItem>("MenuItem1");
await menuItem1.LeftClick();
await Task.Delay(1000, TestContext.Current!.CancellationToken); // Wait for menu to open
IVisualElement<MenuItem> menuItem2 = await rootGrid.GetElement<MenuItem>("MenuItem2");
await menuItem2.LeftClick();
await Task.Delay(1000, TestContext.Current.CancellationToken); // Wait for dialog content to show
// Click navigate button
await navigateHomeButton.LeftClick();
await Task.Delay(1000, TestContext.Current.CancellationToken); // Wait for dialog content to close
await Assert.That(await tabItem1.GetIsSelected()).IsTrue();
await Assert.That(await tabItem2.GetIsSelected()).IsFalse();
recorder.Success();
}
[Test]
[Description("Issue 3094")]
public async Task DialogHost_ChangesSelectedRailItem_DoesNotPerformRailChangeWhenRestoringFocus()
{
await using var recorder = new TestRecorder(App);
IVisualElement<Grid> rootGrid = (await LoadUserControl<RestoreFocus>()).As<Grid>();
IVisualElement<TabItem> railItem1 = await rootGrid.GetElement<TabItem>("RailItem1");
IVisualElement<TabItem> railItem2 = await rootGrid.GetElement<TabItem>("RailItem2");
IVisualElement<Button> navigateHomeButton = await rootGrid.GetElement<Button>("NavigateHomeButton");
// Select TabItem2
await railItem2.LeftClick();
// Open menu
IVisualElement<MenuItem> menuItem1 = await rootGrid.GetElement<MenuItem>("MenuItem1");
await menuItem1.LeftClick();
await Task.Delay(1000, TestContext.Current!.CancellationToken); // Wait for menu to open
IVisualElement<MenuItem> menuItem2 = await rootGrid.GetElement<MenuItem>("MenuItem2");
await menuItem2.LeftClick();
await Task.Delay(1000, TestContext.Current.CancellationToken); // Wait for dialog content to show
// Click navigate button
await navigateHomeButton.LeftClick();
await Task.Delay(1000, TestContext.Current.CancellationToken); // Wait for dialog content to close
await Assert.That(await railItem1.GetIsSelected()).IsTrue();
await Assert.That(await railItem2.GetIsSelected()).IsFalse();
recorder.Success();
}
[Test]
[Description("Issue 3094")]
public async Task DialogHost_ChangesSelectedTabItem_DoesNotPerformTabChangeWhenRestoreFocusIsDisabled()
{
await using var recorder = new TestRecorder(App);
IVisualElement<Grid> rootGrid = (await LoadUserControl<RestoreFocusDisabled>()).As<Grid>();
IVisualElement<TabItem> tabItem1 = await rootGrid.GetElement<TabItem>("TabItem1");
IVisualElement<TabItem> tabItem2 = await rootGrid.GetElement<TabItem>("TabItem2");
IVisualElement<Button> navigateHomeButton = await rootGrid.GetElement<Button>("NavigateHomeButton");
// Select TabItem2
await tabItem2.LeftClick();
// Open menu
IVisualElement<MenuItem> menuItem1 = await rootGrid.GetElement<MenuItem>("MenuItem1");
await menuItem1.LeftClick();
await Task.Delay(1000, TestContext.Current!.CancellationToken); // Wait for menu to open
IVisualElement<MenuItem> menuItem2 = await rootGrid.GetElement<MenuItem>("MenuItem2");
await menuItem2.LeftClick();
await Task.Delay(1000, TestContext.Current.CancellationToken); // Wait for dialog content to show
// Click navigate button
await navigateHomeButton.LeftClick();
await Task.Delay(1000, TestContext.Current.CancellationToken); // Wait for dialog content to close
await Assert.That(await tabItem1.GetIsSelected()).IsTrue();
await Assert.That(await tabItem2.GetIsSelected()).IsFalse();
recorder.Success();
}
[Test]
[Description("Issue 3094")]
public async Task DialogHost_ChangesSelectedRailItem_DoesNotPerformRailChangeWhenRestoreFocusIsDisabled()
{
await using var recorder = new TestRecorder(App);
IVisualElement<Grid> rootGrid = (await LoadUserControl<RestoreFocusDisabled>()).As<Grid>();
IVisualElement<TabItem> railItem1 = await rootGrid.GetElement<TabItem>("RailItem1");
IVisualElement<TabItem> railItem2 = await rootGrid.GetElement<TabItem>("RailItem2");
IVisualElement<Button> navigateHomeButton = await rootGrid.GetElement<Button>("NavigateHomeButton");
// Select TabItem2
await railItem2.LeftClick();
// Open menu
IVisualElement<MenuItem> menuItem1 = await rootGrid.GetElement<MenuItem>("MenuItem1");
await menuItem1.LeftClick();
await Task.Delay(1000, TestContext.Current!.CancellationToken); // Wait for menu to open
IVisualElement<MenuItem> menuItem2 = await rootGrid.GetElement<MenuItem>("MenuItem2");
await menuItem2.LeftClick();
await Task.Delay(1000, TestContext.Current.CancellationToken); // Wait for dialog content to show
// Click navigate button
await navigateHomeButton.LeftClick();
await Task.Delay(1000, TestContext.Current.CancellationToken); // Wait for dialog content to close
await Assert.That(await railItem1.GetIsSelected()).IsTrue();
await Assert.That(await railItem2.GetIsSelected()).IsFalse();
recorder.Success();
}
[Test]
[Description("Issue 3450")]
public async Task DialogHost_WithComboBox_CanSelectItem()
{
await using var recorder = new TestRecorder(App);
IVisualElement dialogHost = await LoadUserControl<WithComboBox>();
var comboBox = await dialogHost.GetElement<ComboBox>("TargetedPlatformComboBox");
await Task.Delay(500, TestContext.Current!.CancellationToken);
await comboBox.LeftClick();
var item = await Wait.For(() => comboBox.GetElement<ComboBoxItem>("TargetItem"));
await Task.Delay(TimeSpan.FromSeconds(1));
await item.LeftClick();
await Wait.For(async () =>
{
var index = await comboBox.GetSelectedIndex();
await Assert.That(index).IsEqualTo(1);
});
recorder.Success();
}
[Test]
[Description("Issue 4027")]
[Arguments("", new[] { Key.Tab })]
[Arguments("", new[] { Key.LeftShift, Key.Tab })]
[Arguments("MaterialDesignEmbeddedDialogHost", new[] { Key.Tab })]
[Arguments("MaterialDesignEmbeddedDialogHost", new[] { Key.LeftShift, Key.Tab })]
public async Task DialogHost_TrapsFocusInsidePopup_WhenTabbing(string dialogHostStyle, Key[] inputActions)
{
await using var recorder = new TestRecorder(App);
var dialogHost = await LoadXaml<DialogHost>("""
<materialDesign:DialogHost>
<Grid>
<StackPanel>
<TextBox />
<Button x:Name="btnOpenDialog"
Content="Open dialog"
Command="{x:Static materialDesign:DialogHost.OpenDialogCommand}" />
</StackPanel>
</Grid>
<materialDesign:DialogHost.DialogContent>
<StackPanel Width="300">
<TextBox x:Name="TextBoxOne" />
<TextBox x:Name="TextBoxTwo" />
</StackPanel>
</materialDesign:DialogHost.DialogContent>
</materialDesign:DialogHost>
""");
if (!string.IsNullOrEmpty(dialogHostStyle))
{
await dialogHost.RemoteExecute(SetDialogHostStyle, dialogHostStyle);
}
var openDialogButton = await dialogHost.GetElement<Button>("btnOpenDialog");
var textBoxOne = await dialogHost.GetElement<TextBox>("TextBoxOne");
var textBoxTwo = await dialogHost.GetElement<TextBox>("TextBoxTwo");
await openDialogButton.LeftClick();
// By default the first focusable element should be focused
await Wait.For(async () => await Assert.That(await textBoxOne.GetIsFocused()).IsTrue());
await textBoxOne.SendInput(new KeyboardInput(inputActions));
await Wait.For(async () => await Assert.That(await textBoxTwo.GetIsFocused()).IsTrue());
await textBoxTwo.SendInput(new KeyboardInput(inputActions));
await Wait.For(async () => await Assert.That(await textBoxOne.GetIsFocused()).IsTrue());
recorder.Success();
static object SetDialogHostStyle(DialogHost dialogHost, string styleName)
{
var style = (Style)dialogHost.FindResource(styleName);
dialogHost.Style = style;
return null!;
}
}
}