Skip to content

Commit 229dea2

Browse files
authored
Merge branch 'master' into pr/support-fake-timers
2 parents 5f603df + 260e1e8 commit 229dea2

File tree

4 files changed

+24
-20
lines changed

4 files changed

+24
-20
lines changed

src/__tests__/element-queries.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -531,16 +531,12 @@ test('queryAllByRole returns semantic html elements', () => {
531531
expect(queryAllByRole(/heading/i)).toHaveLength(6)
532532
expect(queryAllByRole('list')).toHaveLength(2)
533533
expect(queryAllByRole(/listitem/i)).toHaveLength(3)
534-
// TODO: with https://github.com/A11yance/aria-query/pull/42
535-
// the actual value will match `toHaveLength(2)`
536-
expect(queryAllByRole(/textbox/i)).toHaveLength(1)
534+
expect(queryAllByRole(/textbox/i)).toHaveLength(2)
537535
expect(queryAllByRole(/checkbox/i)).toHaveLength(1)
538536
expect(queryAllByRole(/radio/i)).toHaveLength(1)
539537
expect(queryAllByRole('row')).toHaveLength(3)
540538
expect(queryAllByRole(/rowgroup/i)).toHaveLength(2)
541-
// TODO: with https://github.com/A11yance/aria-query/pull/42
542-
// the actual value will match `toHaveLength(3)`
543-
expect(queryAllByRole(/(table)|(textbox)/i)).toHaveLength(2)
539+
expect(queryAllByRole(/(table)|(textbox)/i)).toHaveLength(3)
544540
expect(queryAllByRole(/img/i)).toHaveLength(1)
545541
expect(queryAllByRole('meter')).toHaveLength(1)
546542
expect(queryAllByRole('progressbar')).toHaveLength(0)

src/__tests__/suggestions.js

+18-12
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ test(`should not suggest if the suggestion would give different results`, () =>
7474
})
7575

7676
test('should suggest by label over title', () => {
77-
renderIntoDocument(`<label><span>bar</span><input title="foo" /></label>`)
77+
renderIntoDocument(
78+
`<label><span>bar</span><input type="password" title="foo" /></label>`,
79+
)
7880

7981
expect(() => screen.getByTitle('foo')).toThrowError(
8082
/getByLabelText\(\/bar\/i\)/,
@@ -181,7 +183,7 @@ test('escapes regular expressions in suggestion', () => {
181183

182184
test('should suggest getByLabelText when no role available', () => {
183185
renderIntoDocument(
184-
`<label for="foo">Username</label><input data-testid="foo" id="foo" />`,
186+
`<label for="foo">Username</label><input type="password" data-testid="foo" id="foo" />`,
185187
)
186188
expect(() => screen.getByTestId('foo')).toThrowError(
187189
/getByLabelText\(\/username\/i\)/,
@@ -232,19 +234,21 @@ test.each([
232234

233235
test(`should suggest label over placeholder text`, () => {
234236
renderIntoDocument(
235-
`<label for="foo">Username</label><input id="foo" data-testid="foo" placeholder="Username" />`,
237+
`<label for="foo">Password</label><input type="password" id="foo" data-testid="foo" placeholder="Password" />`,
236238
)
237239

238-
expect(() => screen.getByPlaceholderText('Username')).toThrowError(
239-
/getByLabelText\(\/username\/i\)/,
240+
expect(() => screen.getByPlaceholderText('Password')).toThrowError(
241+
/getByLabelText\(\/password\/i\)/,
240242
)
241243
})
242244

243245
test(`should suggest getByPlaceholderText`, () => {
244-
renderIntoDocument(`<input data-testid="foo" placeholder="Username" />`)
246+
renderIntoDocument(
247+
`<input type="password" data-testid="foo" placeholder="Password" />`,
248+
)
245249

246250
expect(() => screen.getByTestId('foo')).toThrowError(
247-
/getByPlaceholderText\(\/username\/i\)/,
251+
/getByPlaceholderText\(\/password\/i\)/,
248252
)
249253
})
250254

@@ -257,25 +261,27 @@ test(`should suggest getByText for simple elements`, () => {
257261
})
258262

259263
test(`should suggest getByDisplayValue`, () => {
260-
renderIntoDocument(`<input id="lastName" data-testid="lastName" />`)
264+
renderIntoDocument(
265+
`<input type="password" id="password" data-testid="password" />`,
266+
)
261267

262-
document.getElementById('lastName').value = 'Prine' // RIP John Prine
268+
document.getElementById('password').value = 'Prine' // RIP John Prine
263269

264-
expect(() => screen.getByTestId('lastName')).toThrowError(
270+
expect(() => screen.getByTestId('password')).toThrowError(
265271
/getByDisplayValue\(\/prine\/i\)/,
266272
)
267273
})
268274

269275
test(`should suggest getByAltText`, () => {
270276
renderIntoDocument(`
271-
<input data-testid="input" alt="last name" />
277+
<input type="password" data-testid="input" alt="password" />
272278
<map name="workmap">
273279
<area data-testid="area" shape="rect" coords="34,44,270,350" alt="Computer">
274280
</map>
275281
`)
276282

277283
expect(() => screen.getByTestId('input')).toThrowError(
278-
/getByAltText\(\/last name\/i\)/,
284+
/getByAltText\(\/password\/i\)/,
279285
)
280286
expect(() => screen.getByTestId('area')).toThrowError(
281287
/getByAltText\(\/computer\/i\)/,

src/role-helpers.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,9 @@ function getRoles(container, {hidden = false} = {}) {
154154

155155
function prettyRoles(dom, {hidden}) {
156156
const roles = getRoles(dom, {hidden})
157-
157+
//We prefer to skip generic role, we don't reccomand it
158158
return Object.entries(roles)
159+
.filter(([role]) => role !== 'generic')
159160
.map(([role, elements]) => {
160161
const delimiterBar = '-'.repeat(50)
161162
const elementsString = elements

src/suggestions.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,10 @@ export function getSuggestedQuery(element, variant = 'get', method) {
8282
return undefined
8383
}
8484

85+
//We prefer to suggest something else if the role is generic
8586
const role =
8687
element.getAttribute('role') ?? getImplicitAriaRoles(element)?.[0]
87-
if (canSuggest('Role', method, role)) {
88+
if (role !== 'generic' && canSuggest('Role', method, role)) {
8889
return makeSuggestion('Role', role, {
8990
variant,
9091
name: computeAccessibleName(element),

0 commit comments

Comments
 (0)