diff --git a/tests/UI/Logic/AccessibleNamesTests.cs b/tests/UI/Logic/AccessibleNamesTests.cs index 387887d73f..2d817820ce 100644 --- a/tests/UI/Logic/AccessibleNamesTests.cs +++ b/tests/UI/Logic/AccessibleNamesTests.cs @@ -88,6 +88,12 @@ public void EveryInputInEveryWindow_HasAnAccessibleName() if (!AccessibleLabels.HasAccessibleName(control)) { unnamed.AppendLine($"{type.Name}: {control.GetType().Name} {Describe(control)}"); + continue; + } + + if (!HasUsableAccessibleName(control)) + { + unnamed.AppendLine($"{type.Name}: {control.GetType().Name} has an empty/unusable accessible label {Describe(control)}"); } } } @@ -122,6 +128,34 @@ private static void DrainJobs() } } + private static bool HasUsableAccessibleName(Control control) + { + if (!string.IsNullOrWhiteSpace(AutomationProperties.GetName(control))) + { + return true; + } + + var labeledBy = AutomationProperties.GetLabeledBy(control); + if (labeledBy == null) + { + return false; + } + + if (!string.IsNullOrWhiteSpace(AutomationProperties.GetName(labeledBy))) + { + return true; + } + + return labeledBy switch + { + TextBlock textBlock => !string.IsNullOrWhiteSpace(textBlock.Text), + Label label => !string.IsNullOrWhiteSpace(label.Content?.ToString()), + CheckBox checkBox => !string.IsNullOrWhiteSpace(checkBox.Content?.ToString()), + RadioButton radioButton => !string.IsNullOrWhiteSpace(radioButton.Content?.ToString()), + _ => false, + }; + } + private static string Describe(Control control) { var parts = new List();