|
| 1 | +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; |
| 2 | +import { AppSidebarComponent } from './app-sidebar.component'; |
| 3 | + |
| 4 | +describe('AppSidebarComponent', () => { |
| 5 | + let component: AppSidebarComponent; |
| 6 | + let fixture: ComponentFixture<AppSidebarComponent>; |
| 7 | + |
| 8 | + beforeEach(async(() => { |
| 9 | + TestBed.configureTestingModule({ |
| 10 | + declarations: [ AppSidebarComponent ], |
| 11 | + }) |
| 12 | + .compileComponents(); |
| 13 | + })); |
| 14 | + |
| 15 | + beforeEach(() => { |
| 16 | + fixture = TestBed.createComponent(AppSidebarComponent); |
| 17 | + component = fixture.componentInstance; |
| 18 | + fixture.detectChanges(); |
| 19 | + }); |
| 20 | + |
| 21 | + it('should create', () => { |
| 22 | + expect(component).toBeTruthy(); |
| 23 | + }); |
| 24 | + |
| 25 | + it('has sidebar class', () => { |
| 26 | + expect(fixture.nativeElement.classList.contains('sidebar')).toBeTruthy(); |
| 27 | + }); |
| 28 | + |
| 29 | + describe('minimized', () => { |
| 30 | + it('updates document.body classes', () => { |
| 31 | + component.minimized = true; |
| 32 | + expect(document.body.classList.contains('sidebar-minimized')).toBeTruthy(); |
| 33 | + expect(document.body.classList.contains('brand-minimized')).toBeTruthy(); |
| 34 | + |
| 35 | + component.minimized = false; |
| 36 | + expect(document.body.classList.contains('sidebar-minimized')).toBeFalsy(); |
| 37 | + expect(document.body.classList.contains('brand-minimized')).toBeFalsy(); |
| 38 | + }); |
| 39 | + |
| 40 | + it('emits only when value changes', async(() => { |
| 41 | + spyOn(component.minimizedChange, 'emit'); |
| 42 | + |
| 43 | + component.minimized = true; |
| 44 | + component.minimized = true; |
| 45 | + component.minimized = false; |
| 46 | + |
| 47 | + expect(component.minimizedChange.emit).toHaveBeenCalledTimes(2); |
| 48 | + })); |
| 49 | + }); |
| 50 | +}); |
0 commit comments