From 937d49de389c9b101f86222782b5746b6be4bd49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Lag=C3=AAdo?= Date: Wed, 31 Aug 2022 09:40:39 -0300 Subject: [PATCH 1/4] test(ByRole): filter by name or description when hidden --- src/__tests__/role.js | 66 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/src/__tests__/role.js b/src/__tests__/role.js index c709d82e..ec99da79 100644 --- a/src/__tests__/role.js +++ b/src/__tests__/role.js @@ -233,6 +233,44 @@ test('can be filtered by accessible name', () => { ).not.toBeNull() }) +test('when hidden can be filtered by accessible name', () => { + const {getByRole} = renderIntoDocument( + ` +
+

Order

+

Delivery Adress

+ +

Invoice Adress

+
+ + +
+
`, + ) + + const deliveryForm = getByRole('form', { + name: 'Delivery Adress', + hidden: true, + }) + expect(deliveryForm).not.toBeNull() + + expect( + getQueriesForElement(deliveryForm).getByRole('button', { + name: 'Submit', + hidden: true, + }), + ).not.toBeNull() +}) + test('accessible name comparison is case sensitive', () => { const {getByRole} = render(`

Sign up

`) @@ -609,6 +647,34 @@ test('can be filtered by accessible description', () => { ).not.toBeNull() }) +test('when hidden can be filtered by accessible description', () => { + const targetedNotificationMessage = 'Your session is about to expire!' + const {getByRole} = renderIntoDocument( + ` +`, + ) + + const notification = getByRole('alertdialog', { + description: targetedNotificationMessage, + hidden: true, + }) + + expect(notification).not.toBeNull() + expect(notification).toHaveTextContent(targetedNotificationMessage) + + expect( + getQueriesForElement(notification).getByRole('button', { + name: 'Close', + hidden: true, + }), + ).not.toBeNull() +}) + test('error should include description when filtering and no results are found', () => { const targetedNotificationMessage = 'Your session is about to expire!' const {getByRole} = renderIntoDocument( From 70a5ac9d3c26bfc58047d0880c3aa7c117f5261f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Lag=C3=AAdo?= Date: Wed, 31 Aug 2022 09:41:29 -0300 Subject: [PATCH 2/4] fix(ByRole): filter by name or description when hidden --- src/queries/role.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/queries/role.js b/src/queries/role.js index a46d8a2b..79ab261f 100644 --- a/src/queries/role.js +++ b/src/queries/role.js @@ -165,6 +165,7 @@ function queryAllByRole( return matches( computeAccessibleName(element, { + hidden, computedStyleSupportsPseudoElements: getConfig().computedStyleSupportsPseudoElements, }), @@ -181,6 +182,7 @@ function queryAllByRole( return matches( computeAccessibleDescription(element, { + hidden, computedStyleSupportsPseudoElements: getConfig().computedStyleSupportsPseudoElements, }), From fdee23f08438925a11944192e16b8254c8f7e6c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Lag=C3=AAdo?= Date: Wed, 31 Aug 2022 09:43:47 -0300 Subject: [PATCH 3/4] test(ByRole): when hidden, logs elements with their names --- src/__tests__/role.js | 49 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/__tests__/role.js b/src/__tests__/role.js index ec99da79..3e9093e9 100644 --- a/src/__tests__/role.js +++ b/src/__tests__/role.js @@ -53,6 +53,55 @@ test('when hidden: true logs available roles when it fails', () => { `) }) +test('when hidden: logs elements with their names when it fails', () => { + const {getByRole} = render( + `

Hi

`, + ) + expect(() => getByRole('article', {hidden: true})) + .toThrowErrorMatchingInlineSnapshot(` + Unable to find an element with the role "article" + + Here are the available roles: + + heading: + + Name "Hi": +

+ + -------------------------------------------------- + alertdialog: + + Name "My Dialog": +