Skip to content

Commit 0e2cc72

Browse files
refactor: TT-106 New tests for the ProjectListHover component to verify the behavior of ngOnDestroy when the flag is true or false
1 parent 5a294b0 commit 0e2cc72

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

src/app/modules/time-clock/components/project-list-hover/project-list-hover.component.spec.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ describe('ProjectListHoverComponent', () => {
5858
fixture = TestBed.createComponent(ProjectListHoverComponent);
5959
component = fixture.componentInstance;
6060
fixture.detectChanges();
61-
// featureManagerService = TestBed.inject(FeatureManagerService);
61+
featureManagerService = TestBed.inject(FeatureManagerService);
6262
});
6363

6464
it('should create', () => {
@@ -143,6 +143,36 @@ describe('ProjectListHoverComponent', () => {
143143
expect(component.projectsForm.setValue)
144144
.toHaveBeenCalledWith({ project_id: 'customer - xyz'});
145145
});
146+
147+
var toggleValue = true;
148+
fit(`when FeatureToggle is ${toggleValue} should return ${toggleValue}`, () => {
149+
spyOn(featureManagerService, 'isToggleEnabledForUser').and.returnValue(of(toggleValue));
150+
component.projectsSubscription = new Subscription();
151+
component.activeEntrySubscription = new Subscription();
152+
153+
spyOn(component.projectsSubscription, 'unsubscribe');
154+
spyOn(component.activeEntrySubscription, 'unsubscribe');
155+
156+
component.ngOnDestroy();
157+
158+
expect(component.projectsSubscription.unsubscribe).toHaveBeenCalled();
159+
expect(component.activeEntrySubscription.unsubscribe).toHaveBeenCalled();
160+
});
161+
162+
toggleValue = false;
163+
fit(`when FeatureToggle is ${toggleValue} should return ${toggleValue}`, () => {
164+
spyOn(component, 'isFeatureToggleActivated').and.returnValue(of(toggleValue));
165+
component.projectsSubscription = new Subscription();
166+
component.activeEntrySubscription = new Subscription();
167+
168+
spyOn(component.projectsSubscription, 'unsubscribe');
169+
spyOn(component.activeEntrySubscription, 'unsubscribe');
170+
171+
component.ngOnDestroy();
172+
173+
expect(component.projectsSubscription.unsubscribe).not.toHaveBeenCalled();
174+
expect(component.activeEntrySubscription.unsubscribe).not.toHaveBeenCalled();
175+
});
146176

147177
// const exponentialGrowth = [true, false];
148178
// exponentialGrowth.map((toggleValue) => {
@@ -187,4 +217,5 @@ describe('ProjectListHoverComponent', () => {
187217
// })
188218
// );
189219
// });
220+
190221
});

src/app/modules/time-clock/components/project-list-hover/project-list-hover.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export class ProjectListHoverComponent implements OnInit, OnDestroy {
109109
}
110110
}
111111

112-
ngOnDestroy(): void {
112+
ngOnDestroy(): void {
113113
if(this.isFeatureToggleActivated()){
114114
this.projectsSubscription.unsubscribe();
115115
this.activeEntrySubscription.unsubscribe();
@@ -119,6 +119,6 @@ export class ProjectListHoverComponent implements OnInit, OnDestroy {
119119

120120
isFeatureToggleActivated() {
121121
return this.featureManagerService.isToggleEnabledForUser('exponential-growth').pipe(
122-
map((enabled) => enabled));
122+
map((enabled) => enabled === true ? true : false));
123123
}
124124
}

0 commit comments

Comments
 (0)