Skip to content
Merged
Prev Previous commit
Next Next commit
refactor: TT-106 New tests for the ProjectListHover component to veri…
…fy the behavior of ngOnDestroy when the flag is true or false
  • Loading branch information
VanessaIniguezG authored and scastillo-jp committed Feb 17, 2021
commit 38d25bf28f1f75d4da72b3802db8c6deb02be67c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('ProjectListHoverComponent', () => {
fixture = TestBed.createComponent(ProjectListHoverComponent);
component = fixture.componentInstance;
fixture.detectChanges();
// featureManagerService = TestBed.inject(FeatureManagerService);
featureManagerService = TestBed.inject(FeatureManagerService);
});

it('should create', () => {
Expand Down Expand Up @@ -143,6 +143,36 @@ describe('ProjectListHoverComponent', () => {
expect(component.projectsForm.setValue)
.toHaveBeenCalledWith({ project_id: 'customer - xyz'});
});

var toggleValue = true;
fit(`when FeatureToggle is ${toggleValue} should return ${toggleValue}`, () => {
spyOn(featureManagerService, 'isToggleEnabledForUser').and.returnValue(of(toggleValue));
component.projectsSubscription = new Subscription();
component.activeEntrySubscription = new Subscription();

spyOn(component.projectsSubscription, 'unsubscribe');
spyOn(component.activeEntrySubscription, 'unsubscribe');

component.ngOnDestroy();

expect(component.projectsSubscription.unsubscribe).toHaveBeenCalled();
expect(component.activeEntrySubscription.unsubscribe).toHaveBeenCalled();
});

toggleValue = false;
fit(`when FeatureToggle is ${toggleValue} should return ${toggleValue}`, () => {
spyOn(component, 'isFeatureToggleActivated').and.returnValue(of(toggleValue));
component.projectsSubscription = new Subscription();
component.activeEntrySubscription = new Subscription();

spyOn(component.projectsSubscription, 'unsubscribe');
spyOn(component.activeEntrySubscription, 'unsubscribe');

component.ngOnDestroy();

expect(component.projectsSubscription.unsubscribe).not.toHaveBeenCalled();
expect(component.activeEntrySubscription.unsubscribe).not.toHaveBeenCalled();
});

// const exponentialGrowth = [true, false];
// exponentialGrowth.map((toggleValue) => {
Expand Down Expand Up @@ -187,4 +217,5 @@ describe('ProjectListHoverComponent', () => {
// })
// );
// });

});
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class ProjectListHoverComponent implements OnInit, OnDestroy {
}
}

ngOnDestroy(): void {
ngOnDestroy(): void {
if(this.isFeatureToggleActivated()){
this.projectsSubscription.unsubscribe();
this.activeEntrySubscription.unsubscribe();
Expand All @@ -119,6 +119,6 @@ export class ProjectListHoverComponent implements OnInit, OnDestroy {

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