Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2fa6d83

Browse filesBrowse files
committed
test(placeholder): coverage
1 parent aa5162a commit 2fa6d83
Copy full SHA for 2fa6d83

File tree

Expand file treeCollapse file tree

2 files changed

+54
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+54
-1
lines changed

‎CHANGELOG.md

Copy file name to clipboardExpand all lines: CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
- test(accordion): coverage
1717
- test(element-ref): update
1818
- test(backdrop): coverage
19+
- test(placeholder): coverage
1920

2021
---
2122

+53-1Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,63 @@
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';
24
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+
}
319

420
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+
539
it('should create an instance', () => {
640
TestBed.runInInjectionContext(() => {
741
const directive = new PlaceholderDirective();
842
expect(directive).toBeTruthy();
943
});
1044
});
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+
});
1163
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.