public async Task OnEditableComboBox_WithDefaultContextMenu_ShowsCutCopyPaste() { await using var recorder = new TestRecorder(App); var comboBox = await LoadXaml <ComboBox>(@" <ComboBox IsEditable=""True"" Width=""200"" Style=""{StaticResource MaterialDesignComboBox}""> <ComboBoxItem Content=""Select1"" /> <ComboBoxItem>Select2</ComboBoxItem> <ComboBoxItem>Select3</ComboBoxItem> <ComboBoxItem>Select4</ComboBoxItem> <ComboBoxItem>Select5</ComboBoxItem> </ComboBox>"); await comboBox.RightClick(); IVisualElement <ContextMenu>?contextMenu = await comboBox.GetContextMenu(); Assert.True(contextMenu is not null, "No context menu set on the ComboBox"); await AssertMenu("Cut"); await AssertMenu("Copy"); await AssertMenu("Paste"); recorder.Success(); async Task AssertMenu(string menuHeader) { var menuItem = await contextMenu !.GetElement(ElementQuery.PropertyExpression <MenuItem>(x => x.Header, menuHeader)); Assert.True(menuItem is not null, $"{menuHeader} menu item not found"); } }
public async Task OnLostFocusIfSelectedTimeIsNonNull_DatePartDoesNotChange(int year, int month, int day) { await using var recorder = new TestRecorder(App); var stackPanel = await LoadXaml(@" <StackPanel> <materialDesign:TimePicker Language=""en-US"" /> <TextBox /> </StackPanel>"); var timePicker = await stackPanel.GetElement("/TimePicker"); var timePickerTextBox = await timePicker.GetElement("/TimePickerTextBox"); var textBox = await stackPanel.GetElement("/TextBox"); await timePicker.SetSelectedTime(new DateTime(year, month, day)); await timePickerTextBox.MoveKeyboardFocus(); await timePickerTextBox.SetText("1:10"); await textBox.MoveKeyboardFocus(); var actual = await timePicker.GetSelectedTime(); Assert.Equal(new DateTime(year, month, day, 1, 10, 0), actual); recorder.Success(); }
public async Task OnDatePicker_WithClearButton_ClearsSelectedDate() { await using var recorder = new TestRecorder(App); var stackPanel = await LoadXaml <StackPanel>($@" <StackPanel> <DatePicker SelectedDate=""{DateTime.Today:d}"" materialDesign:TextFieldAssist.HasClearButton=""True""/> </StackPanel>"); var datePicker = await stackPanel.GetElement <DatePicker>("/DatePicker"); var clearButton = await datePicker.GetElement <Button>("PART_ClearButton"); DateTime?selectedDate = await datePicker.GetSelectedDate(); Assert.NotNull(selectedDate); await clearButton.LeftClick(); await Wait.For(async() => { selectedDate = await datePicker.GetSelectedDate(); Assert.Null(selectedDate); }); recorder.Success(); }
public async Task OnTimePickedIfTimeHasNotBeenChanged_TextWillbeFormated(string text) { await using var recorder = new TestRecorder(App); var stackPanel = await LoadXaml(@" <StackPanel> <materialDesign:TimePicker/> </StackPanel>"); var timePicker = await stackPanel.GetElement("/TimePicker"); var timePickerTextBox = await timePicker.GetElement("/TimePickerTextBox"); await timePicker.SetSelectedTime(new DateTime(2020, 8, 10, 1, 2, 0)); await timePickerTextBox.MoveKeyboardFocus(); await timePickerTextBox.SendInput($"{text}"); await timePicker.PickClock(1, 2); var actual = await timePickerTextBox.GetText(); Assert.Equal("1:02 AM", actual); recorder.Success(); }
public async Task OutlinedButton_OnMouseOver_UsesThemeBrush() { await using var recorder = new TestRecorder(App); //Arrange IVisualElement button = await LoadXaml( @"<Button Content=""Button"" Style=""{StaticResource MaterialDesignOutlinedButton}""/>"); Color midColor = await GetThemeColor("PrimaryHueMidBrush"); IVisualElement?internalBorder = await button.GetElement("border"); //Act await button.MoveCursorToElement(Position.Center); await Wait.For(async() => { SolidColorBrush internalBorderBackground = await internalBorder.GetProperty <SolidColorBrush>(nameof(Border.Background)); //Assert Assert.Equal(midColor, internalBorderBackground.Color); }); recorder.Success(); }
public async Task OnLostFocusIfSelectedTimeIsNull_DatePartWillBeToday() { await using var recorder = new TestRecorder(App); var stackPanel = await LoadXaml(@" <StackPanel> <materialDesign:TimePicker Language=""en-US"" /> <TextBox /> </StackPanel>"); var timePicker = await stackPanel.GetElement("/TimePicker"); var timePickerTextBox = await timePicker.GetElement("/TimePickerTextBox"); var textBox = await stackPanel.GetElement("/TextBox"); var today = DateTime.Today; await timePickerTextBox.MoveKeyboardFocus(); await timePickerTextBox.SetText("1:23"); await textBox.MoveKeyboardFocus(); var actual = await timePicker.GetSelectedTime(); Assert.Equal(AdjustToday(today, actual).Add(new TimeSpan(1, 23, 0)), actual); recorder.Success(); }
public async Task OnLostFocusIfTimeHasBeenChanged_TextWillbeFormated(string text) { await using var recorder = new TestRecorder(App); var stackPanel = await LoadXaml(@" <StackPanel> <materialDesign:TimePicker/> <TextBox/> </StackPanel>"); var timePicker = await stackPanel.GetElement("/TimePicker"); var timePickerTextBox = await timePicker.GetElement("/TimePickerTextBox"); var textBox = await stackPanel.GetElement("/TextBox"); await timePickerTextBox.MoveKeyboardFocus(); await timePickerTextBox.SendInput($"{text}"); await textBox.MoveKeyboardFocus(); var actual = await timePickerTextBox.GetText(); Assert.Equal("1:02 AM", actual); recorder.Success(); }
public async Task OnTextBox_WithClearButton_ClearsText() { await using var recorder = new TestRecorder(App); var grid = await LoadXaml <Grid>(@" <Grid Margin=""30""> <TextBox VerticalAlignment=""Top"" Text=""Some Text"" materialDesign:TextFieldAssist.HasClearButton=""True""> </TextBox> </Grid>"); var textBox = await grid.GetElement <TextBox>("/TextBox"); var clearButton = await textBox.GetElement <Button>("PART_ClearButton"); string?text = await textBox.GetText(); Assert.NotNull(text); await clearButton.LeftClick(); await Wait.For(async() => { text = await textBox.GetText(); Assert.Null(text); }); recorder.Success(); }
public async Task OutlinedButton_BorderCanBeOverridden() { await using var recorder = new TestRecorder(App); //Arrange IVisualElement button = await LoadXaml( @"<Button Content=""Button"" Style=""{StaticResource MaterialDesignOutlinedButton}"" BorderThickness=""5"" BorderBrush=""Red"" />"); Color midColor = await GetThemeColor("PrimaryHueMidBrush"); IVisualElement?internalBorder = await button.GetElement("border"); //Act Thickness borderThickness = await internalBorder.GetProperty <Thickness>(nameof(Border.BorderThickness)); SolidColorBrush borderBrush = await internalBorder.GetProperty <SolidColorBrush>(nameof(Border.BorderBrush)); //Assert Assert.Equal(new Thickness(5), borderThickness); Assert.Equal(Colors.Red, borderBrush.Color); recorder.Success(); }
public async Task HasNoItemsExpanderVisibility_SetOnTreeView_ChangesVisibiliyOnExpanders(Visibility visibility) { await using var recorder = new TestRecorder(App); var treeView = await LoadXaml <TreeView>($@" <TreeView materialDesign:TreeViewAssist.HasNoItemsExpanderVisibility=""{visibility}""> <TreeViewItem Header=""NoChild"" /> <TreeViewItem Header=""HasChild""> <TreeViewItem Header=""Child"" /> </TreeViewItem> </TreeView>"); var expander = await GetExpanderForHeader("NoChild"); Assert.Equal(visibility, await expander.GetVisibility()); expander = await GetExpanderForHeader("HasChild"); Assert.Equal(Visibility.Visible, await expander.GetVisibility()); recorder.Success(); async Task <IVisualElement <ToggleButton> > GetExpanderForHeader(string header) { var item = await treeView !.GetElement(ElementQuery.PropertyExpression <TreeViewItem>(x => x.Header, header)); return(await item.GetElement <ToggleButton>()); } }
public async Task OnRegisterSerializer_RegistersCustomSerializer() { await using var recorder = new TestRecorder(App); await App.RegisterSerializer <CustomSerializer>(); Assert.AreEqual("In-Test Window Title-Out", await Window.GetTitle()); recorder.Success(); }
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); 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() => Assert.Equal("Clicks: 2", await resultTextBlock.GetText()), retry); recorder.Success(); }
public async Task DrawerHost_CancelingClosingEvent_DrawerStaysOpen() { await using var recorder = new TestRecorder(App); IVisualElement <DrawerHost> drawerHost = (await LoadUserControl <CancellingDrawerHost>()).As <DrawerHost>(); var showButton = await drawerHost.GetElement <Button>("ShowButton"); var closeButton = await drawerHost.GetElement <Button>("CloseButton"); var closeButtonDp = await drawerHost.GetElement <Button>("CloseButtonDp"); var openedEvent = await drawerHost.RegisterForEvent(nameof(DrawerHost.DrawerOpened)); await showButton.LeftClick(); //Allow open animation to finish await Task.Delay(300); await Wait.For(async() => (await openedEvent.GetInvocations()).Count == 1); var closingEvent = await drawerHost.RegisterForEvent(nameof(DrawerHost.DrawerClosing)); //Attempt closing with routed command await closeButton.LeftClick(); await Task.Delay(100); await Wait.For(async() => (await closingEvent.GetInvocations()).Count == 1); Assert.True(await drawerHost.GetIsLeftDrawerOpen()); //Attempt closing with click away await drawerHost.LeftClick(); await Task.Delay(100); await Wait.For(async() => (await closingEvent.GetInvocations()).Count == 2); Assert.True(await drawerHost.GetIsLeftDrawerOpen()); //Attempt closing with DP property toggle await closeButtonDp.LeftClick(); await Task.Delay(100); await Wait.For(async() => (await closingEvent.GetInvocations()).Count == 3); Assert.True(await drawerHost.GetIsLeftDrawerOpen()); recorder.Success(); }
public async Task OnCreateWindow_CanUseCustomWindow() { await using var app = App.StartRemote(); await using var recorder = new TestRecorder(app); await app.InitializeWithDefaults(Assembly.GetExecutingAssembly().Location); IWindow window = await app.CreateWindow <TestWindow>(); Assert.AreEqual("Custom Test Window", await window.GetTitle()); recorder.Success(); }
public async Task OnCreateWindow_CanReadTitle() { await using var app = App.StartRemote(); await using var recorder = new TestRecorder(app); await app.InitializeWithDefaults(Assembly.GetExecutingAssembly().Location); IWindow window = await app.CreateWindowWithContent("", title : "Test Window Title"); Assert.AreEqual("Test Window Title", await window.GetTitle()); recorder.Success(); }
public async Task OnGetMainWindow_ReturnsNullBeforeWindowCreated() { await using var app = App.StartRemote(); await using var recorder = new TestRecorder(app); await app.InitializeWithDefaults(Assembly.GetExecutingAssembly().Location); IWindow?mainWindow = await app.GetMainWindow(); Assert.IsNull(mainWindow); recorder.Success(); }
public async Task FontSettingsSholdInheritIntoDialog() { 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); var text1 = await grid.GetElement <TextBlock>("TextBlock1"); var text2 = await grid.GetElement <TextBlock>("TextBlock2"); Assert.Equal(42, await text1.GetFontSize()); Assert.True((await text1.GetFontFamily())?.FamilyNames.Values.Contains("Times New Roman")); Assert.Equal(FontWeights.ExtraBold, await text1.GetFontWeight()); Assert.Equal(42, await text2.GetFontSize()); Assert.True((await text2.GetFontFamily())?.FamilyNames.Values.Contains("Times New Roman")); Assert.Equal(FontWeights.ExtraBold, await text2.GetFontWeight()); recorder.Success(); }
public async Task ScrollBarAssist_ButtonsVisibility_HidesButtonsOnMinimalistStyle() { await using var recorder = new TestRecorder(App); string xaml = @"<ListBox Height=""300"" Width=""300"" materialDesign:ScrollBarAssist.ButtonsVisibility=""Collapsed"" ScrollViewer.HorizontalScrollBarVisibility=""Visible"" ScrollViewer.VerticalScrollBarVisibility=""Visible""> <ListBox.Resources> <Style BasedOn=""{StaticResource MaterialDesignScrollBarMinimal}"" TargetType=""{x:Type ScrollBar}"" /> </ListBox.Resources> "; for (int i = 0; i < 50; i++) { xaml += $" <ListBoxItem>This is a pretty long meaningless text just to make horizontal scrollbar visibile</ListBoxItem>{Environment.NewLine}"; } xaml += "</ListBox>"; var listBox = await LoadXaml <ListBox>(xaml); var verticalScrollBar = await listBox.GetElement <ScrollBar>("PART_VerticalScrollBar"); var horizontalScrollBar = await listBox.GetElement <ScrollBar>("PART_HorizontalScrollBar"); Assert.Equal(17, await verticalScrollBar.GetActualWidth()); var verticalThumb = await verticalScrollBar.GetElement <Border>("/Thumb~border"); Assert.Equal(10, await verticalThumb.GetActualWidth()); var upButton = await verticalScrollBar.GetElement <RepeatButton>("PART_LineUpButton"); Assert.False(await upButton.GetIsVisible()); var downButton = await verticalScrollBar.GetElement <RepeatButton>("PART_LineDownButton"); Assert.False(await downButton.GetIsVisible()); Assert.Equal(17, await horizontalScrollBar.GetActualHeight()); var horizontalThumb = await horizontalScrollBar.GetElement <Border>("/Thumb~border"); Assert.Equal(10, await horizontalThumb.GetActualHeight()); var leftButton = await horizontalScrollBar.GetElement <RepeatButton>("PART_LineLeftButton"); Assert.False(await leftButton.GetIsVisible()); var rightButton = await horizontalScrollBar.GetElement <RepeatButton>("PART_LineRightButton"); Assert.False(await rightButton.GetIsVisible()); recorder.Success(); }
public async Task OnRegisterSerializer_RegistersCustomSerializer() { await using var app = App.StartRemote(); await using var recorder = new TestRecorder(app); await app.InitializeWithDefaults(Assembly.GetExecutingAssembly().Location); IWindow window = await app.CreateWindowWithContent("", title : "Test Window Title"); await app.RegisterSerializer <CustomSerializer>(); Assert.AreEqual("In-Test Window Title-Out", await window.GetTitle()); recorder.Success(); }
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"); Assert.Equal(Colors.Red, await card1.GetBackgroundColor()); Assert.Equal(Colors.Red, await card2.GetBackgroundColor()); }); recorder.Success(); }
public async Task ContextMenu_FollowsTextBoxFontFamily() { await using var recorder = new TestRecorder(App); var textBox = await LoadXaml <TextBox>(@"<TextBox FontFamily=""Times New Roman""/>"); await textBox.RightClick(); var contextMenu = await textBox.GetElement <ContextMenu>(".ContextMenu"); var textBoxFont = await textBox.GetFontFamily(); Assert.Equal("Times New Roman", textBoxFont?.FamilyNames.Values.First()); Assert.Equal(textBoxFont, await contextMenu.GetFontFamily()); recorder.Success(); }
public async Task OnLoad_ThemeBrushesSet() { await using var recorder = new TestRecorder(App); //Arrange IVisualElement <Button> button = await LoadXaml <Button>(@"<Button Content=""Button"" />"); Color midColor = await GetThemeColor("PrimaryHueMidBrush"); //Act Color?color = await button.GetBackgroundColor(); //Assert Assert.Equal(midColor, color); recorder.Success(); }
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}"); } }
public async Task OnGetWindows_ReturnsAllWindows() { await using var app = App.StartRemote(); await using var recorder = new TestRecorder(app); await app.InitializeWithDefaults(Assembly.GetExecutingAssembly().Location); IWindow window1 = await app.CreateWindowWithContent(""); IWindow window2 = await app.CreateWindowWithContent(""); IReadOnlyList <IWindow> windows = await app.GetWindows(); CollectionAssert.AreEqual(new[] { window1, window2 }, windows.ToArray()); recorder.Success(); }
public async Task CharacterCount_WithoutMaxLengthSet_IsCollapsed() { await using var recorder = new TestRecorder(App); IVisualElement grid = await LoadXaml(@" <Grid Margin=""30""> <TextBox /> </Grid>"); IVisualElement textBox = await grid.GetElement("/TextBox"); IVisualElement characterCounter = await textBox.GetElement("CharacterCounterTextBlock"); Assert.Equal(Visibility.Collapsed, await characterCounter.GetVisibility()); recorder.Success(); }
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(); }
public async Task OnGetMainWindow_AfterMainWindowShownReturnsMainWindow() { await using var app = App.StartRemote(); await using var recorder = new TestRecorder(app); await app.InitializeWithDefaults(Assembly.GetExecutingAssembly().Location); IWindow window1 = await app.CreateWindowWithContent(""); IWindow window2 = await app.CreateWindowWithContent(""); IWindow?mainWindow = await app.GetMainWindow(); Assert.AreEqual(window1, mainWindow); recorder.Success(); }