How to use the @angular/router.ActivatedRouteSnapshot function in @angular/router

To help you get started, we’ve selected a few @angular/router examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dotCMS / core-web / src / app / portlets / content-types / create-edit / content-types-form / content-types-form.component.spec.ts View on Github external
it('should edit and send form with valid data', () => {
        let url = [
            new UrlSegment('edit', { name: 'edit' }),
            new UrlSegment('file', { name: 'file' })
        ];

        // The isEditMode needs data and that is set until the second
        // ngOnChanges, that's why we delay this a little bit
        route.url = Observable.of(url).delay(100);

        let snapshot: ActivatedRouteSnapshot = new ActivatedRouteSnapshot();
        route.snapshot = snapshot;
        route.snapshot.url = url;

        let data: any = {
            clazz: 'com.dotcms.contenttype.model.type.ImmutableFileAssetContentType',
            defaultType: false,
            description: 'Hey I\'m a description',
            fields: [],
            fixed: false,
            folder: 'SYSTEM_FOLDER',
            host: 'host-identifier',
            iDate: 1496963858000,
            id: '1234567890',
            modDate: 1496967718000,
            multilingualable: false,
            name: 'A content type name',
github jhipster / ng-jhipster / tests / service / resolve-paging-params.service.spec.ts View on Github external
it(`should return default when page and sort and defaultSort is undefined`, inject([JhiResolvePagingParams], (service: JhiResolvePagingParams) => {
            const route = new ActivatedRouteSnapshot();
            route.queryParams = { page: undefined, sort: undefined };
            route.data = { defaultSort: undefined };
            const { page, predicate, ascending } = service.resolve(route, null);

            expect(page).toEqual(1);
            expect(predicate).toEqual('id');
            expect(ascending).toEqual(true);
        }));
github Alfresco / alfresco-ng2-components / lib / core / services / auth-guard-sso-role.service.spec.ts View on Github external
it('Should canActivate be false hasRealm is true and hasClientRole is false', () => {
        const materialDialog = TestBed.get(MatDialog);

        spyOn(materialDialog, 'closeAll');

        const route: ActivatedRouteSnapshot = new ActivatedRouteSnapshot();
        spyOn(jwtHelperService, 'hasRealmRoles').and.returnValue(true);
        spyOn(jwtHelperService, 'hasRealmRolesForClientRole').and.returnValue(false);

        route.params = { appName: 'fakeapp' };
        route.data = { 'clientRoles': ['appName'], 'roles': ['role1', 'role2'] };

        expect(materialDialog.closeAll).toHaveBeenCalled();
    });
github machinelabs / machinelabs / client / src / app / lab.resolver.spec.ts View on Github external
it('should resolve with existing lab if id is given', () => {
      const existingLab = Object.assign({}, LAB_STUB);

      const activatedRouteSnapshotStub = new ActivatedRouteSnapshot();
      activatedRouteSnapshotStub.params = { id: 'some-id' };

      spyOn(labStorageService, 'getLab').and.returnValue(of(existingLab));

      labResolver.resolve(activatedRouteSnapshotStub).subscribe(lab => {
        expect(labStorageService.getLab).toHaveBeenCalledWith(activatedRouteSnapshotStub.params['id']);
        expect(lab).toEqual(existingLab);
      });
    });
github Alfresco / alfresco-ng2-components / lib / core / services / auth-guard-sso-role.service.spec.ts View on Github external
it('Should canActivate return false if the data Role to check is empty', async(() => {
        spyOn(jwtHelperService, 'getAccessToken').and.returnValue('my-access_token');
        spyOn(jwtHelperService, 'decodeToken').and.returnValue({ 'realm_access': { roles: ['role1', 'role3'] } });

        const router: ActivatedRouteSnapshot = new ActivatedRouteSnapshot();

        expect(authGuard.canActivate(router)).toBeFalsy();
    }));
github Alfresco / alfresco-ng2-components / lib / core / services / auth-guard-sso-role.service.spec.ts View on Github external
it('Should canActivate be true if both Real Role and Client Role are present int the JWT token', () => {
        const route: ActivatedRouteSnapshot = new ActivatedRouteSnapshot();
        spyOn(jwtHelperService, 'getAccessToken').and.returnValue('my-access_token');

        spyOn(jwtHelperService, 'decodeToken').and.returnValue({
            'realm_access': { roles: ['role1'] },
            'resource_access': { fakeapp: { roles: ['role2'] } }
        });

        route.params = { appName: 'fakeapp' };
        route.data = { 'clientRoles': ['appName'], 'roles': ['role1', 'role2'] };

        expect(authGuard.canActivate(route)).toBeTruthy();
    });
github machinelabs / machinelabs / client / src / app / user-profile / user.resolver.spec.ts View on Github external
beforeEach(() => {
    TestBed.configureTestingModule({
      providers: [UserLabsResolver, SnackbarService, { provide: LabStorageService, useValue: labStorageStub }],
      imports: [MatSnackBarModule]
    });
    userLabsResolver = TestBed.get(UserLabsResolver);
    labStorage = TestBed.get(LabStorageService);
    routeSnapshotStub = new ActivatedRouteSnapshot();
    spyOn(labStorage, 'getLabsFromUser').and.returnValue(of(null));
  });
github wpcfan / taskmgr / src / app / services / auth-guard.service.spec.ts View on Github external
(service: AuthGuardService, store$: Store) => {
        const fixture = TestBed.createComponent(RoutingComponent);
        const guard$ = service.canActivate(new ActivatedRouteSnapshot(), mockSnapshot);
        const auth$ = store$.pipe(select(getAuth));
        const merge$ = guard$.pipe(
            withLatestFrom(
          auth$, (g, a) => ({ result: g, auth: a.err === undefined && a.user !== undefined })));
        merge$.subscribe(r => {
          expect(r.result).toBe(r.auth);
        });
        store$.dispatch({
          type: authActions.LOGIN_SUCCESS,
          payload: {
            token: 'xxxx',
            user: { id: 'xxxx', email: 'abc@dev.local', name: 'xxxx', password: 'sssss' }
          }
        });
      })));
github ovh / cds / ui / src / app / views / application / show / application.component.spec.ts View on Github external
constructor() {
        super();
        this.params = of({ key: 'key1', appName: 'app1' });
        this.queryParams = of({ key: 'key1', appName: 'app1', version: 0, branch: 'master' });

        this.snapshot = new ActivatedRouteSnapshot();

        let project = new Project();
        project.key = 'key1';
        this.snapshot.data = {
            project: project
        };
        this.snapshot.queryParams = { key: 'key1', appName: 'app1', version: 0, branch: 'master' };

        this.data = of({ project: project });
    }
}