-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'Fyle-8679027wa' of https://github.com/fylein/fyle-mobil…
…e-app into Fyle-8679027wa
- Loading branch information
Showing
39 changed files
with
5,812 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { ActivatedRoute, Router } from '@angular/router'; | ||
import { OrgSettingsService } from '../services/org-settings.service'; | ||
import { BetaPageFeatureFlagGuard } from './beta-page-feature-flag.guard'; | ||
import { TestBed } from '@angular/core/testing'; | ||
import { Observable, of } from 'rxjs'; | ||
import { routerStateSnapshotData } from '../mock-data/router-state-snapshot.data'; | ||
|
||
describe('BetaPageFeatureFlagGuard', () => { | ||
let guard: BetaPageFeatureFlagGuard; | ||
let orgSettingsService: jasmine.SpyObj<OrgSettingsService>; | ||
let router: jasmine.SpyObj<Router>; | ||
let activatedRoute: jasmine.SpyObj<ActivatedRoute>; | ||
|
||
beforeEach(() => { | ||
const orgSettingsServiceSpy = jasmine.createSpyObj('OrgSettingsService', ['isBetaPageEnabledForPath']); | ||
const routerSpy = jasmine.createSpyObj('Router', ['navigate']); | ||
|
||
TestBed.configureTestingModule({ | ||
providers: [ | ||
{ | ||
provide: OrgSettingsService, | ||
useValue: orgSettingsServiceSpy, | ||
}, | ||
{ | ||
provide: Router, | ||
useValue: routerSpy, | ||
}, | ||
{ | ||
provide: ActivatedRoute, | ||
useValue: { | ||
snapshot: { | ||
routeConfig: { | ||
path: 'my_view_report', | ||
}, | ||
data: { | ||
url: '/enterprise/my_view_report', | ||
root: null, | ||
}, | ||
}, | ||
}, | ||
}, | ||
], | ||
}); | ||
guard = TestBed.inject(BetaPageFeatureFlagGuard); | ||
orgSettingsService = TestBed.inject(OrgSettingsService) as jasmine.SpyObj<OrgSettingsService>; | ||
activatedRoute = TestBed.inject(ActivatedRoute) as jasmine.SpyObj<ActivatedRoute>; | ||
router = TestBed.inject(Router) as jasmine.SpyObj<Router>; | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(guard).toBeTruthy(); | ||
}); | ||
|
||
describe('canActivate(): ', () => { | ||
it('Should navigate to the beta page if the feature flag is enabled', (done) => { | ||
orgSettingsService.isBetaPageEnabledForPath.and.returnValue(of(true)); | ||
const canActivate = guard.canActivate(activatedRoute.snapshot, routerStateSnapshotData) as Observable<boolean>; | ||
canActivate.subscribe((res) => { | ||
expect(orgSettingsService.isBetaPageEnabledForPath).toHaveBeenCalledTimes(1); | ||
expect(res).toBeFalse(); | ||
expect(router.navigate).toHaveBeenCalledWith(['/', 'enterprise', 'my_view_report_beta', {}]); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('Should navigate to the correct page if the feature flag is disabled', (done) => { | ||
orgSettingsService.isBetaPageEnabledForPath.and.returnValue(of(false)); | ||
const canActivate = guard.canActivate(activatedRoute.snapshot, routerStateSnapshotData) as Observable<boolean>; | ||
canActivate.subscribe((res) => { | ||
expect(orgSettingsService.isBetaPageEnabledForPath).toHaveBeenCalledTimes(1); | ||
expect(res).toBeTrue(); | ||
expect(router.navigate).not.toHaveBeenCalled(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree } from '@angular/router'; | ||
import { Observable, map, of } from 'rxjs'; | ||
import { OrgSettingsService } from '../services/org-settings.service'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class BetaPageFeatureFlagGuard implements CanActivate { | ||
constructor(private orgSettingsService: OrgSettingsService, private router: Router) {} | ||
|
||
canActivate( | ||
route: ActivatedRouteSnapshot, | ||
state: RouterStateSnapshot | ||
): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree { | ||
const currentPath = route.routeConfig && route.routeConfig.path; | ||
|
||
if (currentPath) { | ||
return this.orgSettingsService.isBetaPageEnabledForPath(currentPath).pipe( | ||
map((isBetaPageEnabled) => { | ||
if (isBetaPageEnabled) { | ||
this.router.navigate(['/', 'enterprise', `${currentPath}_beta`, { ...route.params }]); | ||
return false; | ||
} | ||
return true; | ||
}) | ||
); | ||
} else { | ||
return of(true); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.