Skip to content

Comments

fix: add tests to expand-collapse-content#6628

Merged
GZolla merged 4 commits intomainfrom
gzolla/inspiration-expand-collapse-tests
Feb 24, 2026
Merged

fix: add tests to expand-collapse-content#6628
GZolla merged 4 commits intomainfrom
gzolla/inspiration-expand-collapse-tests

Conversation

@GZolla
Copy link
Contributor

@GZolla GZolla commented Feb 24, 2026

GAUD-9516

As part of inspiration I'm working with copilot to reduce the number of updates requested by our components. While refactoring d2l-expand-collapse-content I noticed the tests where only capturing that events were fired and not much else.

This PR adds some more robust tests, including:

  • Not firing events on first update
  • Transition logic between states
  • A defect where no content would cause the state to be stuck in EXPANDING

@GZolla GZolla requested a review from a team as a code owner February 24, 2026 00:11
@github-actions
Copy link
Contributor

Thanks for the PR! 🎉

We've deployed an automatic preview for this PR - you can see your changes here:

URL https://live.d2l.dev/prs/BrightspaceUI/core/pr-6628/

Note

The build needs to finish before your changes are deployed.
Changes to the PR will automatically update the instance.

const e = await new Promise(resolve => {
content.addEventListener('d2l-expand-collapse-content-expand', (e) => resolve(e), { once: true });
[true, false].forEach(expand => {
const event = `d2l-expand-collapse-content-${expand ? 'expand' : 'collapse'}`;
Copy link
Member

Choose a reason for hiding this comment

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

Nit: we often code search for event names when trying to find consumers, either when we're making breaking changes or when we're considering removing an event altogether. I'd suggest just using the full event name in the string instead of concatenating it.

Comment on lines 93 to 95
await content.updateComplete;
await nextFrame();
await nextFrame();
Copy link
Member

Choose a reason for hiding this comment

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

This feels pretty fragile. I'd suggest just using await waitUntil(() => content._state === expand ? states.EXPANDED : states.COLLAPSING).

/* eslint-disable lit/no-private-properties */
return html`
<d2l-expand-collapse-content
._reduceMotion="${!this.transitions}"
Copy link
Member

Choose a reason for hiding this comment

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

Disabling reduced motion is going to cause the tests to run quite slowly. We don't normally do this for that reason, but I guess it could be worth it if we think testing it is valuable enough.

Copy link
Contributor Author

@GZolla GZolla Feb 24, 2026

Choose a reason for hiding this comment

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

Yeah I thought the same, before I made this PR while testing the refactored expand-collapse I was mocking the transitionend event and that was passing and working fine.
But with the current expand-collapse the timing was off and it was because this version solved the no-height defect by forcing the expanded state.
Then I thought about mocking the transition event only when the component was empty, but then it felt very implementation-specific.
With this tests, my refactored version now fails since it has the same defect, so this successfully captured the regression.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, sounds good!

@GZolla GZolla merged commit dd28150 into main Feb 24, 2026
9 of 10 checks passed
@GZolla GZolla deleted the gzolla/inspiration-expand-collapse-tests branch February 24, 2026 20:01
@d2l-github-release-tokens
Copy link

🎉 This PR is included in version 3.219.8 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants