Skip to content

feat(tooltip): tests and code conformance#6344

Open
5t3ph wants to merge 5 commits into
swc-2017/tooltipfrom
seckles/tooltip-code-styles-tests
Open

feat(tooltip): tests and code conformance#6344
5t3ph wants to merge 5 commits into
swc-2017/tooltipfrom
seckles/tooltip-code-styles-tests

Conversation

@5t3ph
Copy link
Copy Markdown
Contributor

@5t3ph 5t3ph commented May 27, 2026

Description

Adds Phase 6 (migration testing) and the post-Phase-6 code conformance pass for swc-tooltip.

Testing (SWC-2024)

Adds two test files:

  • tooltip.test.ts — Storybook play-function tests using Vitest and @storybook/test. Covers defaults, property/attribute mutation, open/close state, lifecycle events (swc-open, swc-close, swc-after-open, swc-after-close), ARIA ariaDescribedByElements wiring for native triggers, swc-button shadow triggers, triggerElement overrides, standalone (no trigger), and manual mode. Also covers Escape key dismissal, all variants, all placements, and the dev-mode warning for an unresolved for attribute.
  • tooltip.a11y.spec.ts — Playwright ARIA snapshot tests. Validates that a closed tooltip is hidden from the accessibility tree, that an open tooltip exposes role="tooltip", that it is removed from the tree when closed, that Escape closes it, and that variant and placement trigger buttons are reachable.

Conformance pass (SWC-2025)

  • Tooltip.ts — Added @fires JSDoc tags for all four lifecycle events.
  • tooltip.css — Added explanatory comment for !important on ::slotted() resets.
  • tooltip.stories.ts — Section separator renamed from "METADATA SETUP" to "METADATA"
  • tooltip.test.ts — Restructured from ad-hoc section headers to the 5 prescribed standard sections; step labels updated to start with verbs; EscapeClosesTest moved to the Variants / States section; section renamed from "Debug warnings" to "Dev mode warnings".

Motivation and context

Phase 6 of the 2nd-gen tooltip migration. Tests validate the full public API surface defined in Phase 3 and the accessibility wiring implemented in Phase 4. The conformance pass ensures all files align with project style guides before Phase 7 (documentation) begins.

Related issue(s)

  • SWC-2024
  • SWC-2025

Manual review test cases

  • Play-function tests pass in the Storybook test runner

    1. Run yarn test:storybook (or equivalent) scoped to the tooltip component
    2. Confirm all stories under Tooltip/Tests show green in the test results panel
    3. Confirm no regressions in any other component's test stories
  • Playwright a11y tests pass

    1. Run yarn test:a11y scoped to tooltip
    2. Confirm all six tests in tooltip.a11y.spec.ts pass
    3. Confirm ARIA snapshots match expected output
  • Conformance-only changes produce no behavioral regressions

    1. Open TooltipOverview in Storybook
    2. Click the trigger button; confirm the tooltip opens and closes as expected
    3. Open TooltipVariants and TooltipPlacements; confirm all variants and placements render correctly

@5t3ph 5t3ph requested a review from a team as a code owner May 27, 2026 15:40
@5t3ph 5t3ph added Component:Tooltip Status:Ready for review PR ready for review or re-review. 2nd gen These issues or PRs map to our 2nd generation work to modernizing infrastructure. labels May 27, 2026
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 27, 2026

⚠️ No Changeset found

Latest commit: 2460440

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 27, 2026

📚 Branch Preview Links

🔍 First Generation Visual Regression Test Results

When a visual regression test fails (or has previously failed while working on this branch), its results can be found in the following URLs:

Deployed to Azure Blob Storage: pr-6344

If the changes are expected, update the current_golden_images_cache hash in the circleci config to accept the new images. Instructions are included in that file.
If the changes are unexpected, you can investigate the cause of the differences and update the code accordingly.

Copy link
Copy Markdown
Member

@cdransf cdransf left a comment

Choose a reason for hiding this comment

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

Looks good! Just one nit ✨

Comment thread 2nd-gen/packages/swc/components/tooltip/test/tooltip.test.ts
@caseyisonit caseyisonit added Status:Ready for merge PR has 2 approvals, all tests pass, and is ready to merge and removed Status:Ready for review PR ready for review or re-review. labels May 28, 2026
Copy link
Copy Markdown
Contributor

@rubencarvalho rubencarvalho left a comment

Choose a reason for hiding this comment

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

Left some out of scope comments, but I stumbled upon them when checking the tests 😛

if (!trigger) {
return;
}
const target = (trigger.shadowRoot?.querySelector('button') ??
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I've been thinking about this (also because of the popover), we had these "focusable-selectors" in Gen1 (1st-gen/tools/shared/src/focusable-selectors.ts), I'm wondering if we'll ever want to extend this.

* When set, wires `ariaLabelledByElements` instead of `ariaDescribedByElements` on the trigger's
* inner interactive element. For icon-only triggers where the tooltip text is the sole accessible name.
*
* Additive/deferred: active in the additive phase.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what's exactly the plan for this property? This is going to surface on the API table but it does not seem like it has effect.

this.open = isOpen;
}
// When no CSS transition is active, dispatch after-* immediately since transitionend will not fire.
if (getComputedStyle(this).transitionDuration === '0s') {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this will not work for all cases... Check here: https://codepen.io/rubencarvalho/pen/yyVpGez
when multiple transition-property values are declared, we get a comma-separated duration list ("0s, 0s, …"), which would never === '0s'

} as Meta;

// Type alias for elements with ariaDescribedByElements (available in Chrome 135+, Firefox 136+, Safari 16.4+).
type AriaRelatable = Element & { ariaDescribedByElements: Element[] | null };
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: could we tighten these casts? maybe it even makes sense to augment the globals in in 2nd-gen/packages/core/global.d.ts if we need.

Something along the lines of:

  /**
   * ARIA element-reflection properties (the IDREF-free associations). Not yet in
   * the TypeScript DOM lib. Available in Chrome 135+, Firefox 136+, Safari 16.4+.
   */
  interface ARIAMixin {
    ariaDescribedByElements: Element[] | null;
    ariaLabelledByElements: Element[] | null;
  }

I think ARIAMixin is the interface that Element/HTMLElement/HTMLButtonElement all implement, so this lands the property on every element type without more casting 😄

const swcButton = canvasElement.querySelector(
'#tt-swc-trigger'
) as HTMLElement;
await (swcButton as HTMLElement & { updateComplete: Promise<boolean> })
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We can cast this as an actuall Button clas which will bring updateComplete out of the box 😄

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this supposed to be included? I've been getting this file regenerating and getting stale every time I run Storybook locally, prob worth looking into this.

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

Labels

2nd gen These issues or PRs map to our 2nd generation work to modernizing infrastructure. Component:Tooltip Status:Ready for merge PR has 2 approvals, all tests pass, and is ready to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants