/
filter-collapsible.component.spec.ts
54 lines (46 loc) · 1.81 KB
/
filter-collapsible.component.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
import { FaIconComponent } from '@fortawesome/angular-fontawesome';
import { MockComponent } from 'ng-mocks';
import { FilterCollapsibleComponent } from './filter-collapsible.component';
describe('Filter Collapsible Component', () => {
let component: FilterCollapsibleComponent;
let fixture: ComponentFixture<FilterCollapsibleComponent>;
let element: HTMLElement;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [FilterCollapsibleComponent, MockComponent(FaIconComponent)],
}).compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(FilterCollapsibleComponent);
component = fixture.componentInstance;
element = fixture.nativeElement;
component.title = 'Price';
});
it('should be created', () => {
expect(component).toBeTruthy();
expect(element).toBeTruthy();
expect(() => fixture.detectChanges()).not.toThrow();
});
it('should hide content when header is clicked', fakeAsync(() => {
fixture.detectChanges();
expect(element).toMatchInlineSnapshot(`
<div class="filter-group">
<h3 tabindex="0" aria-expanded="true" aria-controls="filter-list_Price">
Price <fa-icon class="float-right" ng-reflect-icon="fas,angle-down"></fa-icon>
</h3>
</div>
`);
const filterGroupHead = fixture.nativeElement.querySelectorAll('h3')[0];
filterGroupHead.click();
tick(500);
fixture.detectChanges();
expect(element).toMatchInlineSnapshot(`
<div class="filter-group collapsed">
<h3 tabindex="0" aria-expanded="false" aria-controls="filter-list_Price">
Price <fa-icon class="float-right" ng-reflect-icon="fas,angle-right"></fa-icon>
</h3>
</div>
`);
}));
});