Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expect(locator).toHaveAccessibleErrorMessage #33904

Merged
merged 20 commits into from
Dec 27, 2024

Conversation

pengooseDev
Copy link
Contributor

Closes #31249

  • Add new toHaveAccessibleErrorMessage matcher for expect(locator).

Looking forward to teams feedback. Thanks! :)

This comment has been minimized.

@pengooseDev pengooseDev force-pushed the feat-toHaveAccessibleErrorMessage branch 2 times, most recently from e68009a to cccdd97 Compare December 7, 2024 16:10

This comment has been minimized.

@pengooseDev pengooseDev force-pushed the feat-toHaveAccessibleErrorMessage branch from cccdd97 to 6623a77 Compare December 7, 2024 16:12

This comment has been minimized.

This comment has been minimized.

@pengooseDev pengooseDev force-pushed the feat-toHaveAccessibleErrorMessage branch from 95d0978 to 0a4ee89 Compare December 8, 2024 03:28

This comment has been minimized.

This comment has been minimized.

@pengooseDev pengooseDev force-pushed the feat-toHaveAccessibleErrorMessage branch from 0a4ee89 to c963a6d Compare December 10, 2024 04:46

This comment has been minimized.

@pengooseDev pengooseDev force-pushed the feat-toHaveAccessibleErrorMessage branch from c963a6d to 2195194 Compare December 11, 2024 01:51

This comment has been minimized.

@pengooseDev pengooseDev marked this pull request as draft December 11, 2024 03:56
@pengooseDev pengooseDev force-pushed the feat-toHaveAccessibleErrorMessage branch 2 times, most recently from f764780 to 139b5dd Compare December 14, 2024 16:11

This comment has been minimized.

This comment has been minimized.

@pengooseDev pengooseDev marked this pull request as ready for review December 14, 2024 17:01

This comment has been minimized.

Copy link
Contributor

@dgozman dgozman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks very good! Just a few comments about aria spec/semantics, and this will be good to do.

@pengooseDev pengooseDev force-pushed the feat-toHaveAccessibleErrorMessage branch 2 times, most recently from 3c01c81 to 41921ed Compare December 16, 2024 20:40

This comment has been minimized.

This comment has been minimized.

Copy link
Contributor

@dgozman dgozman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR, looks very good!

export const kInputValidityAttributes = ['required', 'pattern', 'min', 'max', 'minlength', 'maxlength', 'step', 'type', 'value'];

export function hasValidationAttributes(element: Element): boolean {
if (!(element instanceof HTMLInputElement))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

validity is defined for a lot of elements, e.g. <select>, <textarea>, <object>, <button>, <fieldset>, probably more. I'd drop this check, and assume that element.validity?.valid === false means it is invalid.

const role = getAriaRole(element) || '';
if (!role || !kAriaInvalidRoles.includes(role))
return 'false';
if (element instanceof HTMLInputElement && hasValidationAttributes(element) && element.validity)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps check both aria-invalid and element.validity?.valid === false, and consider the element invalid when either of the indicators is present?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I understood it as being asked to remove hasValidationAttributes and evaluate only with element.validity?.valid === false without assessing the kAriaInvalidRoles attributes. Would that be correct? :)

  2. According to the spec, it seems that the return values of the getAriaInvalid function should be 'false' | 'true' | 'grammar' | 'spelling'.
    Rather than evaluating validity within this function, I think it would be better to separate it into a dedicated function, such as getValidityInvalid. I look forward to your feedback on this! :)

@pengooseDev pengooseDev force-pushed the feat-toHaveAccessibleErrorMessage branch from 41921ed to 9378431 Compare December 18, 2024 01:43

This comment has been minimized.

@pengooseDev pengooseDev force-pushed the feat-toHaveAccessibleErrorMessage branch from 9378431 to b28ad83 Compare December 20, 2024 05:07

This comment has been minimized.

@pengooseDev pengooseDev force-pushed the feat-toHaveAccessibleErrorMessage branch from b28ad83 to cab504b Compare December 22, 2024 13:38
Copy link
Contributor

Test results for "tests 1"

8 flaky ⚠️ [firefox-page] › page/page-evaluate.spec.ts:403:3 › should throw for too deep reference chain @firefox-ubuntu-22.04-node18
⚠️ [playwright-test] › ui-mode-test-watch.spec.ts:184:5 › should watch new file @ubuntu-latest-node20-1
⚠️ [webkit-library] › library/browsercontext-clearcookies.spec.ts:146:3 › should remove cookies by name and domain @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › library/browsercontext-har.spec.ts:529:3 › should ignore aborted requests @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › library/logger.spec.ts:34:3 › should log context-level @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › library/trace-viewer.spec.ts:149:1 › should open simple trace viewer @webkit-ubuntu-22.04-node18
⚠️ [webkit-page] › page/page-set-input-files.spec.ts:147:3 › should upload large file @webkit-ubuntu-22.04-node18
⚠️ [playwright-test] › ui-mode-test-watch.spec.ts:145:5 › should watch all @windows-latest-node18-1

37461 passed, 650 skipped
✔️✔️✔️

Merge workflow run.

Copy link
Contributor

@dgozman dgozman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! Thank you for the PR! and following through the review process. Merging in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: expect(locator).toHaveAccessibleErrorMessage(…)
3 participants