refactor(testing): add stable Playwright test hooks#1048
refactor(testing): add stable Playwright test hooks#1048
Conversation
Expose framework-agnostic test ids in shared UI primitives and update common Playwright helpers to use them. Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly improves the stability and maintainability of integration tests by refactoring UI components to include explicit Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces stable test hooks (data-testid) across various shared UI components, which is a great step towards more robust and less brittle integration tests. The changes are well-implemented, consistently applying data-testid attributes and updating Playwright page models and helpers to use them. I've found one area for potential improvement in StructuredList.tsx regarding the value used for data-testid to make it even more resilient. Overall, this is a solid refactoring that will improve the testability of the codebase.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Glad Chinda <117656861+glad-adyen@users.noreply.github.com>
| getCell(label: string, row = 0) { | ||
| return this.getRow(row).locator(`div[aria-labelledby=${label}]`); | ||
| getCell(testId: string, row = 0) { | ||
| return this.getRow(row).getByTestId(label); |
There was a problem hiding this comment.
Now we missed switching to the testId parameter in the body of the function.
| return this.getRow(row).getByTestId(label); | |
| return this.getRow(row).getByTestId(testId); |
|
|
||
| return ( | ||
| <div className={cx('adyen-pe-payment-link-creation-form__field-container', className)}> | ||
| <div className={cx('adyen-pe-payment-link-creation-form__field-container', className)} role="group" aria-label={label} data-testid={testId}> |
There was a problem hiding this comment.
Why is this modified to have a "group" role here? The "group" role is particularly useful for defining a logical group of related interactive elements. Since it might be a bit tricky to establish the content of children, it is better to remove it.
| <div className={cx('adyen-pe-payment-link-creation-form__field-container', className)} role="group" aria-label={label} data-testid={testId}> | |
| <div className={cx('adyen-pe-payment-link-creation-form__field-container', className)} data-testid={testId}> |
| validate, | ||
| }: FormSelectProps<TFieldValues>) { | ||
| const { control, fieldsConfig, getValues, setValue } = useWizardFormContext<TFieldValues>(); | ||
| const fieldNameValue = String(fieldName); |
There was a problem hiding this comment.
Why is this explicit String() casting needed here?
Using the fieldName value directly in the template literal (like so: form-field-${fieldName} or field-error-${fieldName}) implicitly has the same effect as casting to string.
Also, would be nice to double check and ensure that the fieldName prop is always a non-empty string. Otherwise, it would result in malformed and less useful test ids.
| }: FormTextInputProps<TFieldValues>) { | ||
| const { control, fieldsConfig } = useWizardFormContext<TFieldValues>(); | ||
| const { i18n } = useCoreContext(); | ||
| const fieldNameValue = String(fieldName); |
| )} | ||
| </dt> | ||
| <dd className={cx(SL_CONTENT_CLASS, VALUE_COL_CLASS)}> | ||
| <dd className={cx(SL_CONTENT_CLASS, VALUE_COL_CLASS)} data-testid={`${item.key}-value`}> |
There was a problem hiding this comment.
Just thinking, item.key may not be the ideal choice for constructing test ids, since it is usually a translation key.
Summary
Adds framework-agnostic test hooks to shared UI primitives and updates shared Playwright helpers/models to consume them.
Why
The current integration tests rely on framework-coupled selectors in several shared paths. This PR introduces stable
data-testidand accessible hook points so tests can target component behavior rather than implementation details.Included
tests/utilsandtests/modelsValidation
pnpm run types:check