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: Adds test id to flashbar dom selector #2955

Conversation

orangevolon
Copy link
Contributor

@orangevolon orangevolon commented Oct 30, 2024

Description

Adds testId prop to flash items inside the flashbar component.

Related links, issue #, if available:

Collective PR: #2985
Project: Improving test utils API

How has this been tested?

Tests added to cover the change.

Review checklist

The following items are to be evaluated by the author(s) and the reviewer(s).

Correctness

  • Changes include appropriate documentation updates.
  • Changes are backward-compatible if not indicated, see CONTRIBUTING.md.
  • Changes do not include unsupported browser features, see CONTRIBUTING.md.
  • Changes were manually tested for accessibility, see accessibility guidelines.

Security

Testing

  • Changes are covered with new/existing unit tests?
  • Changes are covered with new/existing integration tests?

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@orangevolon orangevolon changed the base branch from main to feat/test-utils-project-m2 November 4, 2024 10:37
@orangevolon orangevolon force-pushed the alamiami/adds-test-id-to-flashbar-items branch 4 times, most recently from 7aff7c9 to 2e88cbb Compare November 8, 2024 09:18
@@ -13,6 +13,7 @@ exports[`test-utils selectors 1`] = `
],
"anchor-navigation": [
"awsui_anchor-item--active_17oho",
"awsui_anchor-item_17oho",
Copy link
Contributor Author

@orangevolon orangevolon Nov 8, 2024

Choose a reason for hiding this comment

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

This is residual snapshot change from #2855.

Since we are merging to the project branch feat/test-utils-project-m2 rather than main, this wasn't caught by the Github checks.

You can ignore this one.

@@ -72,7 +72,7 @@ export const focusFlashById = throttle(
{ trailing: false }
);

export interface FlashProps extends FlashbarProps.MessageDefinition {
export interface FlashProps extends Omit<FlashbarProps.MessageDefinition, 'testId'> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's a bit of an inconsistency when it comes to FlashWrapper.

FlashWrapper should point to the list item and not the flash component itself:

static rootSelector: string = styles['flash-list-item'];

But the existing findFlashByType returns the flash rather than the parent <li />:

return this.findAll(`.${styles['flash-list-item']} .${styles[`flash-type-${type}`]}`).map(

To make sure than this mistake doesn't happen with testId I omitted that from the FlashProps so that it is not assigned by mistake in the future.

@orangevolon orangevolon marked this pull request as ready for review November 8, 2024 09:26
@orangevolon orangevolon requested a review from a team as a code owner November 8, 2024 09:26
@orangevolon orangevolon requested review from gethinwebster and removed request for a team November 8, 2024 09:26
* @returns {FlashbarWrapper | null}
*/
findItemByTestId(testId: string): FlashWrapper | null {
return this.findComponent(`.${styles['flash-list-item']}[data-testid="${CSS.escape(testId)}"]`, FlashWrapper);
Copy link
Member

Choose a reason for hiding this comment

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

Existing similar places use escapeSelector from test-utils (https://github.com/cloudscape-design/test-utils/blob/f49a5a90ce077253f74d82659f1cb6e83092a2a4/src/core/utils.ts#L7), which ensures that this is polyfilled. Might be good to use that here too for consistency

Copy link
Contributor Author

@orangevolon orangevolon Nov 8, 2024

Choose a reason for hiding this comment

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

Good point! Replaced it. Also replaced one more occurrence that was using CSS.escape from before!

@orangevolon orangevolon force-pushed the alamiami/adds-test-id-to-flashbar-items branch from 2e88cbb to 7644234 Compare November 8, 2024 10:51
@orangevolon orangevolon merged commit 3225969 into feat/test-utils-project-m2 Nov 8, 2024
1 check passed
@orangevolon orangevolon deleted the alamiami/adds-test-id-to-flashbar-items branch November 8, 2024 11:04
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.

2 participants