|
| 1 | +import { BehaviorSubject, of } from 'rxjs'; |
1 | 2 | import { ComponentFixture, TestBed } from '@angular/core/testing'; |
| 3 | +import { ConfigService } from '../services/config.service'; |
2 | 4 | import { CurriculumComponent } from './curriculum.component'; |
3 | | -import { MockComponents, MockProvider } from 'ng-mocks'; |
| 5 | +import { LibraryFiltersComponent } from '../modules/library/library-filters/library-filters.component'; |
4 | 6 | import { LibraryService } from '../services/library.service'; |
5 | | -import { of } from 'rxjs'; |
| 7 | +import { MockComponents, MockProvider, MockProviders } from 'ng-mocks'; |
| 8 | +import { PersonalLibraryComponent } from '../modules/library/personal-library/personal-library.component'; |
6 | 9 | import { ProjectFilterValues } from '../domain/projectFilterValues'; |
7 | | -import { LibraryFiltersComponent } from '../modules/library/library-filters/library-filters.component'; |
8 | 10 | import { PublicLibraryComponent } from '../modules/library/public-library/public-library.component'; |
| 11 | +import { User } from '../domain/user'; |
| 12 | +import { UserService } from '../services/user.service'; |
9 | 13 |
|
10 | 14 | describe('CurriculumComponent', () => { |
11 | 15 | let component: CurriculumComponent; |
12 | 16 | let fixture: ComponentFixture<CurriculumComponent>; |
13 | 17 |
|
14 | 18 | beforeEach(async () => { |
15 | 19 | await TestBed.configureTestingModule({ |
16 | | - declarations: [MockComponents(LibraryFiltersComponent, PublicLibraryComponent)], |
| 20 | + declarations: [ |
| 21 | + MockComponents(LibraryFiltersComponent, PersonalLibraryComponent, PublicLibraryComponent) |
| 22 | + ], |
17 | 23 | imports: [CurriculumComponent], |
18 | 24 | providers: [ |
| 25 | + MockProviders(ConfigService, UserService), |
19 | 26 | MockProvider(LibraryService, { |
20 | 27 | projectFilterValuesSource$: of({} as ProjectFilterValues), |
21 | | - communityLibraryProjectsSource$: of([]) |
| 28 | + communityLibraryProjectsSource$: of([]), |
| 29 | + numberOfPublicProjectsVisible$: of(3), |
| 30 | + numberOfPersonalProjectsVisible$: of(2) |
22 | 31 | }) |
23 | 32 | ] |
24 | 33 | }).compileComponents(); |
| 34 | + spyOn(TestBed.inject(ConfigService), 'getAuthoringToolLink').and.returnValue(''); |
25 | 35 |
|
26 | 36 | fixture = TestBed.createComponent(CurriculumComponent); |
27 | 37 | component = fixture.componentInstance; |
28 | 38 | fixture.detectChanges(); |
29 | 39 | }); |
30 | 40 |
|
31 | | - it('should create', () => { |
32 | | - expect(component).toBeTruthy(); |
| 41 | + it('should hide My Units tab and authoring tool link when not logged in as a teacher', () => { |
| 42 | + spyOn(TestBed.inject(UserService), 'isTeacher').and.returnValue(false); |
| 43 | + component.ngOnInit(); |
| 44 | + fixture.detectChanges(); |
| 45 | + expect(numAuthoringToolButtonElements(fixture)).toEqual(0); |
| 46 | + expect(numTabGroupElements(fixture)).toEqual(0); |
| 47 | + }); |
| 48 | + |
| 49 | + it('should show My Units tab and authoring tool link when logged in as teacher', () => { |
| 50 | + spyOn(TestBed.inject(UserService), 'isTeacher').and.returnValue(true); |
| 51 | + component.ngOnInit(); |
| 52 | + fixture.detectChanges(); |
| 53 | + expect(numAuthoringToolButtonElements(fixture)).toEqual(1); |
| 54 | + expect(numTabGroupElements(fixture)).toEqual(1); |
| 55 | + expect(component['showMyUnits']).toBeTruthy(); |
33 | 56 | }); |
34 | 57 | }); |
| 58 | + |
| 59 | +function numAuthoringToolButtonElements(fixture: ComponentFixture<CurriculumComponent>) { |
| 60 | + return fixture.debugElement.nativeElement.querySelectorAll('a').length; |
| 61 | +} |
| 62 | + |
| 63 | +function numTabGroupElements(fixture: ComponentFixture<CurriculumComponent>) { |
| 64 | + return fixture.debugElement.nativeElement.querySelectorAll('mat-tab-group').length; |
| 65 | +} |
0 commit comments