|  | 
| 1 |  | -import { TestBed } from '@angular/core/testing'; | 
|  | 1 | +import { Component, ComponentRef, DebugElement, input } from '@angular/core'; | 
|  | 2 | +import { ComponentFixture, TestBed } from '@angular/core/testing'; | 
|  | 3 | +import { By } from '@angular/platform-browser'; | 
| 2 | 4 | import { PlaceholderDirective } from './placeholder.directive'; | 
|  | 5 | +import { PlaceholderAnimationDirective } from './placeholder-animation.directive'; | 
|  | 6 | + | 
|  | 7 | +@Component({ | 
|  | 8 | +  template: ` | 
|  | 9 | +    <p [cPlaceholderAnimation]="animation()"> | 
|  | 10 | +      <span [cPlaceholder]="visible()" cPlaceholderSize="sm"></span> | 
|  | 11 | +    </p> | 
|  | 12 | +  `, | 
|  | 13 | +  imports: [PlaceholderDirective, PlaceholderAnimationDirective] | 
|  | 14 | +}) | 
|  | 15 | +class TestComponent { | 
|  | 16 | +  readonly visible = input(true); | 
|  | 17 | +  readonly animation = input<'glow' | 'wave' | undefined>(undefined); | 
|  | 18 | +} | 
| 3 | 19 | 
 | 
| 4 | 20 | describe('PlaceholderDirective', () => { | 
|  | 21 | +  let component: TestComponent; | 
|  | 22 | +  let componentRef: ComponentRef<TestComponent>; | 
|  | 23 | +  let fixture: ComponentFixture<TestComponent>; | 
|  | 24 | +  let debugElement: DebugElement; | 
|  | 25 | +  let wrapperElement: DebugElement; | 
|  | 26 | + | 
|  | 27 | +  beforeEach(() => { | 
|  | 28 | +    TestBed.configureTestingModule({ | 
|  | 29 | +      imports: [TestComponent] | 
|  | 30 | +    }).compileComponents(); | 
|  | 31 | + | 
|  | 32 | +    fixture = TestBed.createComponent(TestComponent); | 
|  | 33 | +    component = fixture.componentInstance; | 
|  | 34 | +    componentRef = fixture.componentRef; | 
|  | 35 | +    debugElement = fixture.debugElement.query(By.directive(PlaceholderDirective)); | 
|  | 36 | +    wrapperElement = fixture.debugElement.query(By.directive(PlaceholderAnimationDirective)); | 
|  | 37 | +  }); | 
|  | 38 | + | 
| 5 | 39 |   it('should create an instance', () => { | 
| 6 | 40 |     TestBed.runInInjectionContext(() => { | 
| 7 | 41 |       const directive = new PlaceholderDirective(); | 
| 8 | 42 |       expect(directive).toBeTruthy(); | 
| 9 | 43 |     }); | 
| 10 | 44 |   }); | 
|  | 45 | + | 
|  | 46 | +  it('should toggle visibility for the placeholder', () => { | 
|  | 47 | +    componentRef.setInput('visible', true); | 
|  | 48 | +    fixture.detectChanges(); | 
|  | 49 | +    expect(debugElement.nativeElement).toHaveClass('placeholder'); | 
|  | 50 | +    expect(debugElement.nativeElement).toHaveClass('placeholder-sm'); | 
|  | 51 | +    componentRef.setInput('visible', false); | 
|  | 52 | +    fixture.detectChanges(); | 
|  | 53 | +    expect(debugElement.nativeElement.getAttribute('aria-hidden')).toBe('true'); | 
|  | 54 | +    expect(debugElement.nativeElement).not.toHaveClass('placeholder'); | 
|  | 55 | +  }); | 
|  | 56 | + | 
|  | 57 | +  it('should toggle animation for the placeholder', () => { | 
|  | 58 | +    expect(wrapperElement.nativeElement).not.toHaveClass('placeholder-glow'); | 
|  | 59 | +    componentRef.setInput('animation', 'glow'); | 
|  | 60 | +    fixture.detectChanges(); | 
|  | 61 | +    expect(wrapperElement.nativeElement).toHaveClass('placeholder-glow'); | 
|  | 62 | +  }); | 
| 11 | 63 | }); | 
0 commit comments