-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcurriculum.component.spec.ts
More file actions
64 lines (57 loc) · 2.74 KB
/
Copy pathcurriculum.component.spec.ts
File metadata and controls
64 lines (57 loc) · 2.74 KB
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
55
56
57
58
59
60
61
62
63
64
import { of } from 'rxjs';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ConfigService } from '../services/config.service';
import { CurriculumComponent } from './curriculum.component';
import { LibraryFiltersComponent } from '../modules/library/library-filters/library-filters.component';
import { LibraryService } from '../services/library.service';
import { MockComponents, MockProvider, MockProviders } from 'ng-mocks';
import { PersonalLibraryComponent } from '../modules/library/personal-library/personal-library.component';
import { PublicLibraryComponent } from '../modules/library/public-library/public-library.component';
import { UserService } from '../services/user.service';
import { provideRouter } from '@angular/router';
describe('CurriculumComponent', () => {
let component: CurriculumComponent;
let fixture: ComponentFixture<CurriculumComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [
MockComponents(LibraryFiltersComponent, PersonalLibraryComponent, PublicLibraryComponent)
],
imports: [CurriculumComponent],
providers: [
MockProviders(ConfigService, UserService),
MockProvider(LibraryService, {
communityLibraryProjectsSource$: of([]),
numberOfPublicProjectsVisible$: of(3),
numberOfPersonalProjectsVisible$: of(2)
}),
provideRouter([])
]
}).compileComponents();
spyOn(TestBed.inject(ConfigService), 'getAuthoringToolLink').and.returnValue('');
fixture = TestBed.createComponent(CurriculumComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should hide My Units tab and authoring tool link when not logged in as a teacher', () => {
spyOn(TestBed.inject(UserService), 'isTeacher').and.returnValue(false);
component.ngOnInit();
fixture.detectChanges();
expect(numAuthoringToolButtonElements(fixture)).toEqual(0);
expect(numTabNavBarElements(fixture)).toEqual(0);
});
it('should show My Units tab and teacher home and authoring tool links when logged in as teacher', () => {
spyOn(TestBed.inject(UserService), 'isTeacher').and.returnValue(true);
component.ngOnInit();
fixture.detectChanges();
expect(numAuthoringToolButtonElements(fixture)).toEqual(2);
expect(numTabNavBarElements(fixture)).toEqual(1);
expect(component['showMyUnits']).toBeTruthy();
});
});
function numAuthoringToolButtonElements(fixture: ComponentFixture<CurriculumComponent>) {
return fixture.debugElement.nativeElement.querySelectorAll('header * a').length;
}
function numTabNavBarElements(fixture: ComponentFixture<CurriculumComponent>) {
return fixture.debugElement.nativeElement.querySelectorAll('nav').length;
}