Skip to content

Commit c18d267

Browse files
committed
fix: fix build
1 parent 97d0d7b commit c18d267

File tree

6 files changed

+522
-99
lines changed

6 files changed

+522
-99
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ All notable changes to **bUnit** will be documented in this file. The project ad
88

99
### Added
1010

11-
- `FindByRole` and `FindAllByRole` to `bunit.web.query` to find elements by their WAI-ARIA role, mirroring Playwright's `GetByRole` API. Supports implicit roles from semantic HTML (e.g. `<button>` → button, `<a href>` → link, `<h1>`heading), explicit `role` attributes, and filtering by accessible name, level, checked, pressed, selected, expanded, and disabled states.
11+
- `FindByRole` and `FindAllByRole` to `bunit.web.query` to find elements by their WAI-ARIA role, mirroring Playwright's `GetByRole` API. Supports implicit roles from semantic HTML (e.g. button, anchor with href, heading elements), explicit `role` attributes, and filtering by accessible name, level, checked, pressed, selected, expanded, and disabled states.
1212

1313
## [2.6.2] - 2026-02-27
1414

src/bunit.web.query/Roles/AriaRole.cs

Lines changed: 165 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,92 +2,256 @@ namespace Bunit;
22

33
/// <summary>
44
/// Represents WAI-ARIA roles used to identify the type of an element.
5-
/// Mirrors Playwright.NET's AriaRole enum for familiarity.
65
/// </summary>
76
public enum AriaRole
87
{
8+
/// <summary>Represents the WAI-ARIA "alert" role.</summary>
99
Alert,
10+
11+
/// <summary>Represents the WAI-ARIA "alertdialog" role.</summary>
1012
AlertDialog,
13+
14+
/// <summary>Represents the WAI-ARIA "application" role.</summary>
1115
Application,
16+
17+
/// <summary>Represents the WAI-ARIA "article" role.</summary>
1218
Article,
19+
20+
/// <summary>Represents the WAI-ARIA "banner" role.</summary>
1321
Banner,
22+
23+
/// <summary>Represents the WAI-ARIA "blockquote" role.</summary>
1424
Blockquote,
25+
26+
/// <summary>Represents the WAI-ARIA "button" role.</summary>
1527
Button,
28+
29+
/// <summary>Represents the WAI-ARIA "caption" role.</summary>
1630
Caption,
31+
32+
/// <summary>Represents the WAI-ARIA "cell" role.</summary>
1733
Cell,
34+
35+
/// <summary>Represents the WAI-ARIA "checkbox" role.</summary>
1836
Checkbox,
37+
38+
/// <summary>Represents the WAI-ARIA "code" role.</summary>
1939
Code,
40+
41+
/// <summary>Represents the WAI-ARIA "columnheader" role.</summary>
2042
ColumnHeader,
43+
44+
/// <summary>Represents the WAI-ARIA "combobox" role.</summary>
2145
Combobox,
46+
47+
/// <summary>Represents the WAI-ARIA "complementary" role.</summary>
2248
Complementary,
49+
50+
/// <summary>Represents the WAI-ARIA "contentinfo" role.</summary>
2351
ContentInfo,
52+
53+
/// <summary>Represents the WAI-ARIA "definition" role.</summary>
2454
Definition,
55+
56+
/// <summary>Represents the WAI-ARIA "deletion" role.</summary>
2557
Deletion,
58+
59+
/// <summary>Represents the WAI-ARIA "dialog" role.</summary>
2660
Dialog,
61+
62+
/// <summary>Represents the WAI-ARIA "directory" role.</summary>
2763
Directory,
64+
65+
/// <summary>Represents the WAI-ARIA "document" role.</summary>
2866
Document,
67+
68+
/// <summary>Represents the WAI-ARIA "emphasis" role.</summary>
2969
Emphasis,
70+
71+
/// <summary>Represents the WAI-ARIA "feed" role.</summary>
3072
Feed,
73+
74+
/// <summary>Represents the WAI-ARIA "figure" role.</summary>
3175
Figure,
76+
77+
/// <summary>Represents the WAI-ARIA "form" role.</summary>
3278
Form,
79+
80+
/// <summary>Represents the WAI-ARIA "generic" role.</summary>
3381
Generic,
82+
83+
/// <summary>Represents the WAI-ARIA "grid" role.</summary>
3484
Grid,
85+
86+
/// <summary>Represents the WAI-ARIA "gridcell" role.</summary>
3587
GridCell,
88+
89+
/// <summary>Represents the WAI-ARIA "group" role.</summary>
3690
Group,
91+
92+
/// <summary>Represents the WAI-ARIA "heading" role.</summary>
3793
Heading,
94+
95+
/// <summary>Represents the WAI-ARIA "img" role.</summary>
3896
Img,
97+
98+
/// <summary>Represents the WAI-ARIA "insertion" role.</summary>
3999
Insertion,
100+
101+
/// <summary>Represents the WAI-ARIA "link" role.</summary>
40102
Link,
103+
104+
/// <summary>Represents the WAI-ARIA "list" role.</summary>
41105
List,
106+
107+
/// <summary>Represents the WAI-ARIA "listbox" role.</summary>
42108
Listbox,
109+
110+
/// <summary>Represents the WAI-ARIA "listitem" role.</summary>
43111
Listitem,
112+
113+
/// <summary>Represents the WAI-ARIA "log" role.</summary>
44114
Log,
115+
116+
/// <summary>Represents the WAI-ARIA "main" role.</summary>
45117
Main,
118+
119+
/// <summary>Represents the WAI-ARIA "mark" role.</summary>
46120
Mark,
121+
122+
/// <summary>Represents the WAI-ARIA "marquee" role.</summary>
47123
Marquee,
124+
125+
/// <summary>Represents the WAI-ARIA "math" role.</summary>
48126
Math,
127+
128+
/// <summary>Represents the WAI-ARIA "menu" role.</summary>
49129
Menu,
130+
131+
/// <summary>Represents the WAI-ARIA "menubar" role.</summary>
50132
Menubar,
133+
134+
/// <summary>Represents the WAI-ARIA "menuitem" role.</summary>
51135
Menuitem,
136+
137+
/// <summary>Represents the WAI-ARIA "menuitemcheckbox" role.</summary>
52138
Menuitemcheckbox,
139+
140+
/// <summary>Represents the WAI-ARIA "menuitemradio" role.</summary>
53141
Menuitemradio,
142+
143+
/// <summary>Represents the WAI-ARIA "meter" role.</summary>
54144
Meter,
145+
146+
/// <summary>Represents the WAI-ARIA "navigation" role.</summary>
55147
Navigation,
148+
149+
/// <summary>Represents the WAI-ARIA "none" role.</summary>
56150
None,
151+
152+
/// <summary>Represents the WAI-ARIA "note" role.</summary>
57153
Note,
154+
155+
/// <summary>Represents the WAI-ARIA "option" role.</summary>
58156
Option,
157+
158+
/// <summary>Represents the WAI-ARIA "paragraph" role.</summary>
59159
Paragraph,
160+
161+
/// <summary>Represents the WAI-ARIA "presentation" role.</summary>
60162
Presentation,
163+
164+
/// <summary>Represents the WAI-ARIA "progressbar" role.</summary>
61165
Progressbar,
166+
167+
/// <summary>Represents the WAI-ARIA "radio" role.</summary>
62168
Radio,
169+
170+
/// <summary>Represents the WAI-ARIA "radiogroup" role.</summary>
63171
Radiogroup,
172+
173+
/// <summary>Represents the WAI-ARIA "region" role.</summary>
64174
Region,
175+
176+
/// <summary>Represents the WAI-ARIA "row" role.</summary>
65177
Row,
178+
179+
/// <summary>Represents the WAI-ARIA "rowgroup" role.</summary>
66180
Rowgroup,
181+
182+
/// <summary>Represents the WAI-ARIA "rowheader" role.</summary>
67183
Rowheader,
184+
185+
/// <summary>Represents the WAI-ARIA "scrollbar" role.</summary>
68186
Scrollbar,
187+
188+
/// <summary>Represents the WAI-ARIA "search" role.</summary>
69189
Search,
190+
191+
/// <summary>Represents the WAI-ARIA "searchbox" role.</summary>
70192
Searchbox,
193+
194+
/// <summary>Represents the WAI-ARIA "separator" role.</summary>
71195
Separator,
196+
197+
/// <summary>Represents the WAI-ARIA "slider" role.</summary>
72198
Slider,
199+
200+
/// <summary>Represents the WAI-ARIA "spinbutton" role.</summary>
73201
Spinbutton,
202+
203+
/// <summary>Represents the WAI-ARIA "status" role.</summary>
74204
Status,
205+
206+
/// <summary>Represents the WAI-ARIA "strong" role.</summary>
75207
Strong,
208+
209+
/// <summary>Represents the WAI-ARIA "subscript" role.</summary>
76210
Subscript,
211+
212+
/// <summary>Represents the WAI-ARIA "superscript" role.</summary>
77213
Superscript,
214+
215+
/// <summary>Represents the WAI-ARIA "switch" role.</summary>
78216
Switch,
217+
218+
/// <summary>Represents the WAI-ARIA "tab" role.</summary>
79219
Tab,
220+
221+
/// <summary>Represents the WAI-ARIA "table" role.</summary>
80222
Table,
223+
224+
/// <summary>Represents the WAI-ARIA "tablist" role.</summary>
81225
Tablist,
226+
227+
/// <summary>Represents the WAI-ARIA "tabpanel" role.</summary>
82228
Tabpanel,
229+
230+
/// <summary>Represents the WAI-ARIA "term" role.</summary>
83231
Term,
232+
233+
/// <summary>Represents the WAI-ARIA "textbox" role.</summary>
84234
Textbox,
235+
236+
/// <summary>Represents the WAI-ARIA "time" role.</summary>
85237
Time,
238+
239+
/// <summary>Represents the WAI-ARIA "timer" role.</summary>
86240
Timer,
241+
242+
/// <summary>Represents the WAI-ARIA "toolbar" role.</summary>
87243
Toolbar,
244+
245+
/// <summary>Represents the WAI-ARIA "tooltip" role.</summary>
88246
Tooltip,
247+
248+
/// <summary>Represents the WAI-ARIA "tree" role.</summary>
89249
Tree,
250+
251+
/// <summary>Represents the WAI-ARIA "treegrid" role.</summary>
90252
Treegrid,
253+
254+
/// <summary>Represents the WAI-ARIA "treeitem" role.</summary>
91255
Treeitem,
92256
}
93257

src/bunit.web.query/Roles/ImplicitRoleMapping.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ internal static class ImplicitRoleMapping
8484
private static AriaRole? GetImgRole(IElement element)
8585
{
8686
var alt = element.GetAttribute("alt");
87-
return alt == string.Empty ? AriaRole.Presentation : AriaRole.Img;
87+
return alt is not null && alt.Length == 0 ? AriaRole.Presentation : AriaRole.Img;
8888
}
8989

9090
private static bool HasAccessibleName(IElement element)

src/bunit.web.query/Roles/RoleNotFoundException.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ private static string BuildMessage(AriaRole role, ByRoleOptions options)
3535
if (options.Level.HasValue)
3636
filters.Add($"level: {options.Level.Value}");
3737
if (options.Checked.HasValue)
38-
filters.Add($"checked: {(options.Checked.Value == true ? "true" : "false")}");
38+
filters.Add($"checked: {(options.Checked.Value ? "true" : "false")}");
3939
if (options.Pressed.HasValue)
40-
filters.Add($"pressed: {(options.Pressed.Value == true ? "true" : "false")}");
40+
filters.Add($"pressed: {(options.Pressed.Value ? "true" : "false")}");
4141
if (options.Selected.HasValue)
42-
filters.Add($"selected: {(options.Selected.Value == true ? "true" : "false")}");
42+
filters.Add($"selected: {(options.Selected.Value ? "true" : "false")}");
4343
if (options.Expanded.HasValue)
44-
filters.Add($"expanded: {(options.Expanded.Value == true ? "true" : "false")}");
44+
filters.Add($"expanded: {(options.Expanded.Value ? "true" : "false")}");
4545
if (options.Disabled.HasValue)
46-
filters.Add($"disabled: {(options.Disabled.Value == true ? "true" : "false")}");
46+
filters.Add($"disabled: {(options.Disabled.Value ? "true" : "false")}");
4747

4848
if (filters.Count > 0)
4949
message += $" ({string.Join(", ", filters)})";

0 commit comments

Comments
 (0)