// Covers the round "?" help of TEA's cards: hover or focus shows the text, a click keeps it until the next click. // Fixture: a host component that projects one line of text into the button. import { Component } from '@angular/core'; import { TestBed } from '@angular/core/testing'; import { IndicadorAyuda } from './indicador-ayuda'; @Component({ imports: [IndicadorAyuda], template: `Texto de ayuda` }) class Host { aperturas = 0; } describe('Ayuda redonda', () => { function crear() { const fixture = TestBed.createComponent(Host); fixture.detectChanges(); const root: HTMLElement = fixture.nativeElement; const boton = () => root.querySelector('.ayuda-boton')!; const texto = () => root.querySelector('.ayuda-texto')?.textContent?.trim(); const ayuda = root.querySelector('.ayuda')!; return { fixture, boton, texto, ayuda }; } it('muestra el texto al pasar el cursor y lo oculta al salir', () => { // Fails if hovering stops showing the guide or leaving leaves it open when it was not pinned. const { fixture, texto, ayuda } = crear(); expect(texto()).toBeUndefined(); ayuda.dispatchEvent(new MouseEvent('mouseenter')); fixture.detectChanges(); expect(texto()).toBe('Texto de ayuda'); ayuda.dispatchEvent(new MouseEvent('mouseleave')); fixture.detectChanges(); expect(texto()).toBeUndefined(); }); it('un clic fija el texto hasta el siguiente clic', () => { // Fails if the click stops pinning the text, if leaving closes a pinned text, or if a second click does not close it. const { fixture, boton, texto, ayuda } = crear(); ayuda.dispatchEvent(new MouseEvent('mouseenter')); boton().click(); fixture.detectChanges(); ayuda.dispatchEvent(new MouseEvent('mouseleave')); fixture.detectChanges(); expect(texto()).toBe('Texto de ayuda'); expect(boton().getAttribute('aria-expanded')).toBe('true'); boton().click(); fixture.detectChanges(); expect(texto()).toBeUndefined(); expect(boton().getAttribute('aria-expanded')).toBe('false'); }); it('avisa solo al abrirse con un clic y nombra el botón', () => { // Fails if closing also reports an opening (the metadata would be requested again) or the accessible name is lost. const { fixture, boton } = crear(); boton().click(); boton().click(); boton().click(); fixture.detectChanges(); expect(fixture.componentInstance.aperturas).toBe(2); expect(boton().getAttribute('aria-label')).toBe('Cómo leer: prueba'); }); });