-
Notifications
You must be signed in to change notification settings - Fork 75
LG-5778(feat): update expandable card test utils #3442
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
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 40c6465 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds three new test utility functions (getTitle, getDescription, and getFlagText) to the ExpandableCard component's test harness, enabling consumers to more easily test these specific elements in their test suites.
- Adds
getTitle,getDescription, andgetFlagTexthelper functions to the test utils - Updates the ExpandableCard component to include
data-lgidattributes on title, description, and flag text elements - Adds comprehensive test coverage and documentation for the new test utilities
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/expandable-card/src/testing/utils.tsx | Adds new lgId constants for title, description, and flagText elements |
| packages/expandable-card/src/testing/getTestUtils.types.ts | Defines TypeScript interfaces for the three new test utility functions |
| packages/expandable-card/src/testing/getTestUtils.ts | Implements the new getter functions using queryByLgId |
| packages/expandable-card/src/testing/getTestUtils.spec.tsx | Adds test coverage for the new utility functions in both single and multiple card scenarios |
| packages/expandable-card/src/ExpandableCard/ExpandableCard.tsx | Adds data-lgid and data-testid attributes to title, description, and flagText elements; removes DEFAULT_LGID_ROOT default |
| packages/expandable-card/README.md | Documents the new test utilities with usage examples |
| .changeset/eager-yaks-wash.md | Documents the changes for the release notes |
…LgId and adjust return types
…, description, and flag text
|
Size Change: +359 B (+0.02%) Total Size: 1.83 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
…expandable-card-test-utils
…escription, and flag text
|
Coverage after merging LG-5778-expandable-card-test-utils into main will be
Coverage Report for Changed Files
|
|||||||||||||||||||||||||
| const findToggle = () => findByLgId!<HTMLDivElement>(lgIds.toggle); | ||
| const queryToggle = () => queryByLgId!<HTMLDivElement>(lgIds.toggle); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The toggle always renders. What are cases where findToggle and queryToggle would be necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is true. I didn't think there was any harm in giving more options, but if it seems unnecessary, I can remove them.
| const getTitle = () => getByLgId!<HTMLHeadingElement>(lgIds.title); | ||
| const queryTitle = () => queryByLgId!<HTMLHeadingElement>(lgIds.title); | ||
| const findTitle = () => findByLgId!<HTMLHeadingElement>(lgIds.title); | ||
|
|
||
| const getDescription = () => getByLgId!<HTMLDivElement>(lgIds.description); | ||
| const queryDescription = () => | ||
| queryByLgId!<HTMLDivElement>(lgIds.description); | ||
| const findDescription = () => findByLgId!<HTMLDivElement>(lgIds.description); | ||
|
|
||
| const getFlagText = () => getByLgId!<HTMLSpanElement>(lgIds.flagText); | ||
| const queryFlagText = () => queryByLgId!<HTMLSpanElement>(lgIds.flagText); | ||
| const findFlagText = () => findByLgId!<HTMLSpanElement>(lgIds.flagText); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TheSonOfThomp saw you had created the initial ticket. I'm curious what cases might require these test utils? When I implemented the initial set, I explicitly chose not to implement these because they are re-implementations of what is already available from existing testing libraries (getByText, queryByText, findByText)
| <Subtitle className={summaryHeader}>{title}</Subtitle> | ||
| {flagText && <span className={flagTextStyle}>{flagText}</span>} | ||
| <Subtitle | ||
| data-testid={lgIds.title} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been looking into this pattern of adding lgIds to data-testid, and it seems like 3/4ths as many instances of it as passing it into data-lgid. My personal opinion is allowing the users to control what they want data-testid to do while we control data-lgid. What do you think?
CC @stephl3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would agree. The pattern of implementing test utils and setting data-testid seems duplicative and confusing. What is the purpose of setting both?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a few reasons. This is to support consumers who are testing without a DOM. Our test utils require the use of the DOM, but without a DOM you can still query with data-testid. This is also helpful for components with child components, where consumers can't add data-testid. For example, in Modal, consumers can't add a data-testid to the close button`.
✍️ Proposed changes
🎟 Jira ticket: LG-5778
Adds a few more test utils.
✅ Checklist
For new components
For bug fixes, new features & breaking changes
pnpm changesetand documented my changes🧪 How to test changes