public async Task OnOpenDialog_OverlayCoversContent() { await using var recorder = new TestRecorder(App); IVisualElement dialogHost = await LoadUserControl <WithCounter>(); IVisualElement overlay = await dialogHost.GetElement("PART_ContentCoverGrid"); IVisualElement resultTextBlock = await dialogHost.GetElement("ResultTextBlock"); await Wait.For(async() => await resultTextBlock.GetText() == "Clicks: 0"); IVisualElement testOverlayButton = await dialogHost.GetElement("TestOverlayButton"); await testOverlayButton.Click(); await Wait.For(async() => await resultTextBlock.GetText() == "Clicks: 1"); IVisualElement showDialogButton = await dialogHost.GetElement("ShowDialogButton"); await showDialogButton.Click(); IVisualElement closeDialogButton = await dialogHost.GetElement("CloseDialogButton"); await Wait.For(async() => await closeDialogButton.GetIsVisible() == true); await testOverlayButton.Click(); await Wait.For(async() => await resultTextBlock.GetText() == "Clicks: 1"); await closeDialogButton.Click(); var retry = new Retry(5, TimeSpan.FromSeconds(5)); await Wait.For(async() => await overlay.GetVisibility() != Visibility.Visible, retry); await testOverlayButton.Click(); await Wait.For(async() => Assert.Equal("Clicks: 2", await resultTextBlock.GetText()), retry); }
public async Task OnOpenDialog_OverlayCoversContent() { await using var recorder = new TestRecorder(App); IVisualElement dialogHost = await LoadUserControl <WithCounter>(); IVisualElement resultTextBlock = await dialogHost.GetElement("ResultTextBlock"); await Wait.For(async() => await resultTextBlock.GetText() == "Clicks: 0"); IVisualElement testOverlayButton = await dialogHost.GetElement("TestOverlayButton"); await testOverlayButton.Click(); await Wait.For(async() => await resultTextBlock.GetText() == "Clicks: 1"); IVisualElement showDialogButton = await dialogHost.GetElement("ShowDialogButton"); await showDialogButton.Click(); IVisualElement closeDialogButton = await dialogHost.GetElement("CloseDialogButton"); await Wait.For(async() => await closeDialogButton.GetIsVisible() == true); await testOverlayButton.Click(); await Wait.For(async() => await resultTextBlock.GetText() == "Clicks: 1"); await closeDialogButton.Click(); await Wait.For(async() => { Output.WriteLine("Input"); await testOverlayButton.Click(); Assert.Equal("Clicks: 2", await resultTextBlock.GetText()); Output.WriteLine("Output"); }); }
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 OnClickChoiceChipListBox_ChangesSelectedItem(string listBoxStyle) { await using var recorder = new TestRecorder(App); IVisualElement listBox = await LoadXaml($@" <ListBox x:Name=""ChipsListBox"" Style=""{{StaticResource {listBoxStyle}}}""> <ListBoxItem>Mercury</ListBoxItem> <ListBoxItem>Venus</ListBoxItem> <ListBoxItem>Earth</ListBoxItem> <ListBoxItem>Pluto</ListBoxItem> </ListBox> "); IVisualElement earth = await listBox.GetElement("/ListBoxItem[2]"); await earth.Click(); await Wait.For(async() => Assert.Equal(2, await listBox.GetProperty <int>(nameof(Selector.SelectedIndex)))); recorder.Success(); }
public async Task ClosingDialogWithIsOpenProperty_ShouldRaiseDialogClosingEvent() { await using var recorder = new TestRecorder(App); IVisualElement dialogHost = await LoadUserControl <ClosingEventCounter>(); IVisualElement showButton = await dialogHost.GetElement("ShowDialogButton"); IVisualElement closeButton = await dialogHost.GetElement("CloseButton"); IVisualElement resultTextBlock = await dialogHost.GetElement("ResultTextBlock"); await showButton.Click(); await Wait.For(async() => await closeButton.GetIsVisible()); await closeButton.Click(); await Wait.For(async() => Assert.Equal("1", await resultTextBlock.GetText())); }
public async Task OnClearButtonShown_ControlHeighDoesNotChange() { await using var recorder = new TestRecorder(App); //Arrange IVisualElement grid = await LoadXaml(@" <Grid Margin=""30""> <TextBox VerticalAlignment=""Top"" Text=""Some Text"" materialDesign:TextFieldAssist.HasClearButton=""True""> </TextBox> </Grid>"); IVisualElement textBox = await grid.GetElement("/TextBox"); IVisualElement clearButton = await grid.GetElement("PART_ClearButton"); await textBox.MoveKeyboardFocus(); //Delay needed to accout for transition storyboard await Task.Delay(MaterialDesignTextBox.FocusedAimationTime); double initialHeight = await textBox.GetActualHeight(); //Act await clearButton.Click(); //Assert await Task.Delay(MaterialDesignTextBox.FocusedAimationTime); double height = await textBox.GetActualHeight(); Assert.Equal(initialHeight, height); recorder.Success(); }