@@ -324,3 +324,96 @@ test.describe("given an expander event handling", () => {
324324// await expect(firstLink).toBeFocused();
325325// });
326326// });
327+
328+ test . describe ( "given an expander with useAriaExpanded=false (tooltip)" , ( ) => {
329+ let containerEl ;
330+ let hostEl ;
331+ let contentEl ;
332+
333+ test . beforeEach ( async ( { page } ) => {
334+ await page . goto ( "/core/makeup-expander/index.html" ) ;
335+ containerEl = page . locator ( ".expander--tooltip" ) . first ( ) ;
336+ hostEl = containerEl . locator ( ".expander__host" ) ;
337+ contentEl = containerEl . locator ( ".expander__content" ) ;
338+ } ) ;
339+
340+ test ( "should not have aria-expanded attribute on host" , async ( ) => {
341+ await expect ( hostEl ) . not . toHaveAttribute ( "aria-expanded" ) ;
342+ } ) ;
343+
344+ test ( "should not have aria-controls attribute on host" , async ( ) => {
345+ await expect ( hostEl ) . not . toHaveAttribute ( "aria-controls" ) ;
346+ } ) ;
347+
348+ test ( "should have the correct initial state" , async ( ) => {
349+ expect ( containerEl ) . toBeTruthy ( ) ;
350+ await expect ( containerEl ) . not . toHaveClass ( / e x p a n d e r _ _ h o s t - c o n t a i n e r - - e x p a n d e d / ) ;
351+ await expect ( contentEl ) . not . toBeVisible ( ) ;
352+ } ) ;
353+
354+ test ( "should expand on host focus using expandedClass" , async ( ) => {
355+ await hostEl . focus ( ) ;
356+ await expect ( containerEl ) . toHaveClass ( / e x p a n d e r _ _ h o s t - c o n t a i n e r - - e x p a n d e d / ) ;
357+ await expect ( contentEl ) . toBeVisible ( ) ;
358+ // Verify aria-expanded is still not set
359+ await expect ( hostEl ) . not . toHaveAttribute ( "aria-expanded" ) ;
360+ } ) ;
361+
362+ test ( "should expand on host hover using expandedClass" , async ( ) => {
363+ await hostEl . hover ( ) ;
364+ await expect ( containerEl ) . toHaveClass ( / e x p a n d e r _ _ h o s t - c o n t a i n e r - - e x p a n d e d / ) ;
365+ await expect ( contentEl ) . toBeVisible ( ) ;
366+ // Verify aria-expanded is still not set
367+ await expect ( hostEl ) . not . toHaveAttribute ( "aria-expanded" ) ;
368+ } ) ;
369+
370+ test ( "should collapse on mouse out" , async ( { page } ) => {
371+ await hostEl . hover ( ) ;
372+ await expect ( containerEl ) . toHaveClass ( / e x p a n d e r _ _ h o s t - c o n t a i n e r - - e x p a n d e d / ) ;
373+
374+ // Move mouse away to trigger mouseout
375+ await page . mouse . move ( 10 , 10 ) ;
376+
377+ // Wait for the timeout (300ms in the code)
378+ await page . waitForTimeout ( 350 ) ;
379+
380+ await expect ( containerEl ) . not . toHaveClass ( / e x p a n d e r _ _ h o s t - c o n t a i n e r - - e x p a n d e d / ) ;
381+ await expect ( contentEl ) . not . toBeVisible ( ) ;
382+ // Verify aria-expanded is still not set
383+ await expect ( hostEl ) . not . toHaveAttribute ( "aria-expanded" ) ;
384+ } ) ;
385+
386+ test ( "should emit expander-expand event on expansion" , async ( { page } ) => {
387+ await page . evaluate ( ( ) => {
388+ window . tooltipExpandFired = false ;
389+ document . querySelector ( ".expander--tooltip" ) . addEventListener ( "expander-expand" , ( ) => {
390+ window . tooltipExpandFired = true ;
391+ } ) ;
392+ } ) ;
393+
394+ await hostEl . focus ( ) ;
395+
396+ const eventFired = await page . evaluate ( ( ) => window . tooltipExpandFired ) ;
397+ expect ( eventFired ) . toBe ( true ) ;
398+ } ) ;
399+
400+ test ( "should emit expander-collapse event on collapse" , async ( { page } ) => {
401+ // First expand
402+ await hostEl . hover ( ) ;
403+ await expect ( containerEl ) . toHaveClass ( / e x p a n d e r _ _ h o s t - c o n t a i n e r - - e x p a n d e d / ) ;
404+
405+ await page . evaluate ( ( ) => {
406+ window . tooltipCollapseFired = false ;
407+ document . querySelector ( ".expander--tooltip" ) . addEventListener ( "expander-collapse" , ( ) => {
408+ window . tooltipCollapseFired = true ;
409+ } ) ;
410+ } ) ;
411+
412+ // Move mouse away to trigger collapse
413+ await page . mouse . move ( 10 , 10 ) ;
414+ await page . waitForTimeout ( 350 ) ;
415+
416+ const eventFired = await page . evaluate ( ( ) => window . tooltipCollapseFired ) ;
417+ expect ( eventFired ) . toBe ( true ) ;
418+ } ) ;
419+ } ) ;
0 commit comments