@@ -6,14 +6,16 @@ import { Project } from '../../../domain/project';
66import { NGSSStandards } from '../ngssStandards' ;
77import { ConfigService } from '../../../services/config.service' ;
88import { ParentProject } from '../../../domain/parentProject' ;
9- import { MockProviders } from 'ng-mocks' ;
9+ import { MockComponent , MockProviders } from 'ng-mocks' ;
10+ import { By } from '@angular/platform-browser' ;
11+ import { LibraryProjectMenuComponent } from '../library-project-menu/library-project-menu.component' ;
1012
13+ let component : LibraryProjectDetailsComponent ;
14+ let fixture : ComponentFixture < LibraryProjectDetailsComponent > ;
1115describe ( 'LibraryProjectDetailsComponent' , ( ) => {
12- let component : LibraryProjectDetailsComponent ;
13- let fixture : ComponentFixture < LibraryProjectDetailsComponent > ;
14-
1516 beforeEach ( ( ) => {
1617 TestBed . configureTestingModule ( {
18+ declarations : [ MockComponent ( LibraryProjectMenuComponent ) ] ,
1719 imports : [ LibraryProjectDetailsComponent ] ,
1820 providers : [
1921 MockProviders ( ConfigService , MatDialog , MatDialogRef , UserService ) ,
@@ -30,11 +32,13 @@ describe('LibraryProjectDetailsComponent', () => {
3032 grades : [ '7' ] ,
3133 title : 'Photosynthesis & Cellular Respiration' ,
3234 summary : 'A really great unit.' ,
35+ unitType : 'Platform' ,
3336 totalTime : '6-7 hours' ,
3437 authors : [
3538 { id : 10 , firstName : 'Spaceman' , lastName : 'Spiff' , username : 'SpacemanSpiff' } ,
3639 { id : 12 , firstName : 'Captain' , lastName : 'Napalm' , username : 'CaptainNapalm' }
37- ]
40+ ] ,
41+ resources : [ { name : 'Resource 1' , uri : 'http://example.com/resource1' } ]
3842 } ;
3943 const ngssObject : any = {
4044 disciplines : [
@@ -90,6 +94,11 @@ describe('LibraryProjectDetailsComponent', () => {
9094 expect ( compiled . textContent ) . toContain ( 'by Spaceman Spiff, Captain Napalm' ) ;
9195 } ) ;
9296
97+ it ( 'should show project resources' , ( ) => {
98+ const compiled = fixture . debugElement . nativeElement ;
99+ expect ( compiled . textContent ) . toContain ( 'Resource 1' ) ;
100+ } ) ;
101+
93102 it ( 'should show copied project info' , ( ) => {
94103 component [ 'project' ] . metadata . authors = [ ] ;
95104 component [ 'parentProject' ] = new ParentProject ( {
@@ -103,4 +112,33 @@ describe('LibraryProjectDetailsComponent', () => {
103112 const compiled = fixture . debugElement . nativeElement ;
104113 expect ( compiled . textContent ) . toContain ( 'is a copy of Photosynthesis' ) ;
105114 } ) ;
115+
116+ it ( 'should show use with class and preview buttons' , ( ) => {
117+ component [ 'isTeacher' ] = true ;
118+ fixture . detectChanges ( ) ;
119+ expect ( getButtonWithText ( 'Use with Class' ) ) . toBeTruthy ( ) ;
120+ expect ( getButtonWithText ( 'Preview' ) ) . toBeTruthy ( ) ;
121+ } ) ;
122+
123+ isResourceUnitType_HideButtons ( ) ;
106124} ) ;
125+
126+ function isResourceUnitType_HideButtons ( ) {
127+ describe ( 'is not Resource unit type' , ( ) => {
128+ beforeEach ( ( ) => {
129+ component [ 'project' ] . metadata . unitType = 'Resource' ;
130+ fixture . detectChanges ( ) ;
131+ } ) ;
132+
133+ it ( 'should hide buttons when unit type is Resource' , ( ) => {
134+ expect ( getButtonWithText ( 'Use with Class' ) ) . toBeFalsy ( ) ;
135+ expect ( getButtonWithText ( 'Preview' ) ) . toBeFalsy ( ) ;
136+ } ) ;
137+ } ) ;
138+ }
139+
140+ function getButtonWithText ( text : string ) {
141+ return fixture . debugElement
142+ . queryAll ( By . css ( 'button' ) )
143+ . find ( ( el ) => el . nativeElement . textContent . includes ( text ) ) ;
144+ }
0 commit comments