Skip to content

Commit 1dc314a

Browse files
Add UI test from Corvinz review
1 parent eaf05f1 commit 1dc314a

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

tests/MaterialDesignThemes.UITests/WPF/TabControls/TabControlTests.cs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,4 +418,69 @@ public async Task ScrollingTabs_WithNavigationPanelAndScrollBehavior_ShouldScrol
418418

419419
recorder.Success();
420420
}
421+
422+
[Test]
423+
public async Task ScrollingTabs_NavigationPanel_ScrollsAndBringsSelectedTabIntoView()
424+
{
425+
await using var recorder = new TestRecorder(App);
426+
427+
// Arrange
428+
const int numTabs = 20;
429+
StringBuilder xaml = new($"<TabControl Width=\"504\" materialDesign:TabAssist.HeaderBehavior=\"Scrolling\" materialDesign:TabAssist.UseNavigationPanel=\"True\" materialDesign:TabAssist.NavigationPanelPlacement=\"Right\">");
430+
for (int i = 1; i <= numTabs; i++)
431+
{
432+
xaml.Append($"""
433+
<TabItem Header="TAB {i}">
434+
<TextBlock Margin="8" Text="Tab {i}" />
435+
</TabItem>
436+
""");
437+
}
438+
xaml.Append("</TabControl>");
439+
440+
IVisualElement<TabControl> tabControl = await LoadXaml<TabControl>(xaml.ToString());
441+
IVisualElement<PaddedBringIntoViewStackPanel> headerPanel = await tabControl.GetElement<PaddedBringIntoViewStackPanel>();
442+
IVisualElement<StackPanel> navigationPanel = await tabControl.GetElement<StackPanel>("NavigationPanelRight");
443+
IVisualElement<Button> rightNextButton = await navigationPanel.GetElement<Button>("RightNextButton");
444+
IVisualElement<Button> rightPreviousButton = await navigationPanel.GetElement<Button>("RightPreviousButton");
445+
446+
// Act
447+
// Scroll right once
448+
await Task.Delay(300);
449+
await rightNextButton.LeftClick();
450+
await Task.Delay(300);
451+
452+
// Select an arbitrary tab (index 8)
453+
IVisualElement<TabItem> someTab = await tabControl.GetElement<TabItem>("/TabItem[8]");
454+
await someTab.LeftClick();
455+
456+
// Scroll back to the left
457+
await Task.Delay(300);
458+
await rightPreviousButton.LeftClick();
459+
await Task.Delay(300);
460+
461+
// Select the last visible tab
462+
// NB: The last visible tab is "hardcoded" to always be index 4 due to the fixed Width of 504 on the TabControl
463+
IVisualElement<TabItem> lastVisibleTab = await tabControl.GetElement<TabItem>($"/TabItem[4]");
464+
await lastVisibleTab.LeftClick();
465+
await Task.Delay(300);
466+
467+
// Assert
468+
int selectedTabIndex = await tabControl.GetSelectedIndex();
469+
await Assert.That(selectedTabIndex).IsEqualTo(4);
470+
471+
double offsetWhenOverflowingWidth = await headerPanel.GetHeaderPadding();
472+
Thickness margin = await headerPanel.GetMargin();
473+
474+
await Assert.That(offsetWhenOverflowingWidth).IsGreaterThan(0);
475+
await Assert.That(margin.Left).IsEqualTo(offsetWhenOverflowingWidth);
476+
477+
static Thickness GetNavigationPanelMargin(TabControl tc) => TabAssist.GetNavigationPanelMargin(tc);
478+
479+
Thickness navigationPanelMargin = await tabControl.RemoteExecute(GetNavigationPanelMargin);
480+
double navigationPanelActualWidth = await navigationPanel.GetActualWidth() + navigationPanelMargin.Left + navigationPanelMargin.Right;
481+
482+
await Assert.That(margin.Right).IsEqualTo(offsetWhenOverflowingWidth + navigationPanelActualWidth);
483+
484+
recorder.Success();
485+
}
421486
}

0 commit comments

Comments
 (0)