11import { HttpClient , HttpHandler } from '@angular/common/http' ;
22import { ComponentFixture , TestBed } from '@angular/core/testing' ;
3+ import { Component , EventEmitter , Input , Output } from '@angular/core' ;
34import { RouterTestingModule } from '@angular/router/testing' ;
45import { ActivatedRoute } from '@angular/router' ;
56import { of } from 'rxjs' ;
@@ -10,6 +11,9 @@ import { MockLoaderService } from 'src/app/service/loader/mock-data-loader.servi
1011import { MarkdownText } from 'src/app/model/markdown-text' ;
1112import { Data } from 'src/app/model/activity-store' ;
1213import { isEmptyObj } from 'src/app/util/util' ;
14+ import { MaterialModule } from 'src/app/material/material.module' ;
15+ import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
16+ import { DataStore } from 'src/app/model/data-store' ;
1317
1418let mockLoaderService : MockLoaderService ;
1519let mockActivatedRoute = {
@@ -41,28 +45,47 @@ let mockData = {
4145 } ,
4246} ;
4347
48+ @Component ( {
49+ selector : 'app-dependency-graph' ,
50+ template : '' ,
51+ } )
52+ class DependencyGraphStubComponent {
53+ @Input ( ) activityName : string = '' ;
54+ @Output ( ) activityClicked = new EventEmitter < string > ( ) ;
55+ }
56+
4457describe ( 'ActivityDescriptionComponent' , ( ) => {
4558 let component : ActivityDescriptionComponent ;
4659 let fixture : ComponentFixture < ActivityDescriptionComponent > ;
4760 mockLoaderService = new MockLoaderService ( mockData as unknown as Data ) ;
61+ let dataStore : DataStore ;
4862
4963 beforeEach ( async ( ) => {
50- await mockLoaderService . load ( ) ;
64+ dataStore = ( await mockLoaderService . load ( ) ) as DataStore ;
5165 await TestBed . configureTestingModule ( {
5266 providers : [
5367 HttpClient ,
5468 HttpHandler ,
5569 { provide : ActivatedRoute , useValue : mockActivatedRoute } ,
5670 { provide : LoaderService , useValue : mockLoaderService } ,
5771 ] ,
58- imports : [ RouterTestingModule ] ,
59- declarations : [ ActivityDescriptionComponent ] ,
72+ imports : [ RouterTestingModule , MaterialModule , NoopAnimationsModule ] ,
73+ declarations : [ ActivityDescriptionComponent , DependencyGraphStubComponent ] ,
6074 } ) . compileComponents ( ) ;
6175 } ) ;
6276
6377 beforeEach ( async ( ) => {
6478 fixture = TestBed . createComponent ( ActivityDescriptionComponent ) ;
6579 component = fixture . componentInstance ;
80+ // Provide the @Input activity before first change detection so ngOnInit uses it
81+ const testUUID = '00000000-1111-1111-1111-0000000000000' ;
82+ const activity =
83+ dataStore . activityStore ?. getActivityByUuid ( testUUID ) ||
84+ dataStore . activityStore ?. getActivityByName ( 'Activity 111' ) ;
85+ // Fallback for safety in case lookup fails in future changes
86+ if ( activity ) {
87+ component . activity = activity as any ;
88+ }
6689 fixture . detectChanges ( ) ;
6790 await fixture . whenStable ( ) ;
6891 fixture . detectChanges ( ) ;
@@ -78,14 +101,17 @@ describe('ActivityDescriptionComponent', () => {
78101
79102 it ( 'check if header is being generated' , async ( ) => {
80103 const testSubDimension = 'SubDim-1.1' ;
104+ const testActivity = 'Activity 111' ;
81105
82106 await fixture . whenStable ( ) ;
83107 fixture . detectChanges ( ) ;
84108
85109 const HTMLElement : HTMLElement = fixture . nativeElement ;
86- const heading = HTMLElement . querySelector ( 'h1' ) ! ;
110+ const subDimHeading = HTMLElement . querySelector ( '.title-above span' ) ! ;
111+ const activityHeading = HTMLElement . querySelector ( '.activity-header h1' ) ! ;
87112
88- expect ( heading ?. textContent ) . toContain ( testSubDimension ) ;
113+ expect ( subDimHeading ?. textContent ) . toContain ( testSubDimension ) ;
114+ expect ( activityHeading ?. textContent ) . toContain ( testActivity ) ;
89115 } ) ;
90116
91117 it ( 'check if content is displayed' , async ( ) => {
@@ -102,12 +128,11 @@ describe('ActivityDescriptionComponent', () => {
102128 fixture . detectChanges ( ) ;
103129 const HTMLElement : HTMLElement = fixture . nativeElement ;
104130
105- expect ( HTMLElement . querySelector ( '# uuid' ) ?. textContent ) . toContain ( testUUID ) ;
131+ expect ( HTMLElement . querySelector ( '. uuid-value ' ) ?. textContent ) . toContain ( testUUID ) ;
106132 expect ( HTMLElement . querySelector ( '#description' ) ?. textContent ) . toContain ( testDesc ) ;
107133 expect ( HTMLElement . querySelector ( '#risk' ) ?. textContent ) . toContain ( testRisk ) ;
108134 expect ( HTMLElement . querySelector ( '#measure' ) ?. textContent ) . toContain ( testMeasure ) ;
109135 expect ( HTMLElement . querySelector ( '#assessment' ) ?. textContent ) . toContain ( testAssessment ) ;
110- expect ( HTMLElement . querySelector ( '#comments' ) ?. textContent ) . toContain ( testComments ) ;
111136 expect ( HTMLElement . querySelector ( '#implementationGuide' ) ?. textContent ) . toContain ( testImplementationGuide ) ; // eslint-disable-line
112137 } ) ;
113138
0 commit comments