Skip to content

Commit 07ea6a1

Browse files
committed
Fixed unit test
1 parent de384f9 commit 07ea6a1

2 files changed

Lines changed: 34 additions & 9 deletions

File tree

src/app/component/activity-description/activity-description.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<div class="activity-title">
44
<div class="title-above">
55
<mat-icon mat-list-icon color="primary" *ngIf="iconName">{{ iconName }}</mat-icon>
6-
{{ currentActivity.dimension }}
6+
<span>{{ currentActivity.dimension }}</span>
77
</div>
88
<h1>
99
{{ currentActivity.name }}
@@ -20,7 +20,7 @@ <h1>
2020

2121
<div class="activity-subheader">
2222
<span class="level">Level {{ currentActivity.level }}</span>
23-
<span class="uuid"><span class="uuid-label">id: </span>{{ currentActivity.uuid }}</span>
23+
<div class="uuid"><span class="uuid-label">id: </span><span class="uuid-value">{{ currentActivity.uuid }}</span></div>
2424
</div>
2525
<mat-accordion multi="true">
2626
<mat-expansion-panel *ngIf="currentActivity.description?.hasContent()" [expanded]="true">

src/app/component/activity-description/activity-description.component.spec.ts

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { HttpClient, HttpHandler } from '@angular/common/http';
22
import { ComponentFixture, TestBed } from '@angular/core/testing';
3+
import { Component, EventEmitter, Input, Output } from '@angular/core';
34
import { RouterTestingModule } from '@angular/router/testing';
45
import { ActivatedRoute } from '@angular/router';
56
import { of } from 'rxjs';
@@ -10,6 +11,9 @@ import { MockLoaderService } from 'src/app/service/loader/mock-data-loader.servi
1011
import { MarkdownText } from 'src/app/model/markdown-text';
1112
import { Data } from 'src/app/model/activity-store';
1213
import { 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

1418
let mockLoaderService: MockLoaderService;
1519
let 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+
4457
describe('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

Comments
 (0)