当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript RouterTestingModule.withRoutes方法代码示例

本文整理汇总了TypeScript中@angular/router/testing.RouterTestingModule.withRoutes方法的典型用法代码示例。如果您正苦于以下问题:TypeScript RouterTestingModule.withRoutes方法的具体用法?TypeScript RouterTestingModule.withRoutes怎么用?TypeScript RouterTestingModule.withRoutes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在@angular/router/testing.RouterTestingModule的用法示例。


在下文中一共展示了RouterTestingModule.withRoutes方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: beforeEach

 beforeEach(() => {
   TestBed.configureTestingModule({
     imports: [
       AppMaterialModule,
       RouterTestingModule.withRoutes([{
         path: '',
         component: ParentComponent,
         children: [{
           path: '',
           component: DummyComponent
         }, {
           path: 'title',
           children: [{
             path: '',
             outlet: 'other',
             component: DummyComponent,
             data: {
               title: 'Hidden Title'
             }
           }, {
             path: '',
             component: DummyComponent,
             data: {
               title: 'Test Title'
             }
           }]
         }, {
           path: 'back',
           children: [{
             path: '',
             outlet: 'other',
             component: DummyComponent,
             data: {
               back: {
                 title: 'Other',
                 route: '/other'
               }
             }
           }, {
             path: '',
             component: DummyComponent,
             data: {
               back: {
                 title: 'Home',
                 route: '/home'
               }
             }
           }]
         }, {
           path: 'home',
           component: DummyComponent,
           data: {
             title: 'Home'
           }
         }, {
           path: 'about',
           component: DummyComponent,
           data: {
             title: 'About'
           }
         }]
       }])
     ],
     providers: [
       { provide: AuthService, useValue: mockAuthService },
       { provide: ConfirmService, useValue: mockConfirm },
     ],
     declarations: [
       AppComponent,
       DummyComponent,
       ParentComponent,
     ],
   });
   TestBed.compileComponents();
 });
开发者ID:bradyisom,项目名称:sp90x2,代码行数:75,代码来源:app.component.spec.ts

示例2: describe

describe('UserFormComponent', () => {
  let component: UserFormComponent;
  let form: CdFormGroup;
  let fixture: ComponentFixture<UserFormComponent>;
  let httpTesting: HttpTestingController;
  let userService: UserService;
  let modalService: BsModalService;
  let router: Router;
  let formHelper: FormHelper;

  const setUrl = (url) => Object.defineProperty(router, 'url', { value: url });

  @Component({ selector: 'cd-fake', template: '' })
  class FakeComponent {}

  const routes: Routes = [
    { path: 'login', component: FakeComponent },
    { path: 'users', component: FakeComponent }
  ];

  configureTestBed(
    {
      imports: [
        RouterTestingModule.withRoutes(routes),
        HttpClientTestingModule,
        ReactiveFormsModule,
        ComponentsModule,
        ToastModule.forRoot(),
        SharedModule
      ],
      declarations: [UserFormComponent, FakeComponent],
      providers: i18nProviders
    },
    true
  );

  beforeEach(() => {
    fixture = TestBed.createComponent(UserFormComponent);
    component = fixture.componentInstance;
    form = component.userForm;
    httpTesting = TestBed.get(HttpTestingController);
    userService = TestBed.get(UserService);
    modalService = TestBed.get(BsModalService);
    router = TestBed.get(Router);
    spyOn(router, 'navigate');
    fixture.detectChanges();
    const notify = TestBed.get(NotificationService);
    spyOn(notify, 'show');
    formHelper = new FormHelper(form);
  });

  it('should create', () => {
    expect(component).toBeTruthy();
    expect(form).toBeTruthy();
  });

  describe('create mode', () => {
    beforeEach(() => {
      setUrl('/user-management/users/add');
      component.ngOnInit();
    });

    it('should not disable fields', () => {
      ['username', 'name', 'password', 'confirmpassword', 'email', 'roles'].forEach((key) =>
        expect(form.get(key).disabled).toBeFalsy()
      );
    });

    it('should validate username required', () => {
      formHelper.expectErrorChange('username', '', 'required');
      formHelper.expectValidChange('username', 'user1');
    });

    it('should validate password match', () => {
      formHelper.setValue('password', 'aaa');
      formHelper.expectErrorChange('confirmpassword', 'bbb', 'match');
      formHelper.expectValidChange('confirmpassword', 'aaa');
    });

    it('should validate email', () => {
      formHelper.expectErrorChange('email', 'aaa', 'email');
    });

    it('should set mode', () => {
      expect(component.mode).toBeUndefined();
    });

    it('should submit', () => {
      const user: UserFormModel = {
        username: 'user0',
        password: 'pass0',
        name: 'User 0',
        email: 'user0@email.com',
        roles: ['administrator']
      };
      formHelper.setMultipleValues(user);
      formHelper.setValue('confirmpassword', user.password);
      component.submit();
      const userReq = httpTesting.expectOne('api/user');
      expect(userReq.request.method).toBe('POST');
//.........这里部分代码省略.........
开发者ID:LenzGr,项目名称:ceph,代码行数:101,代码来源:user-form.component.spec.ts

示例3: describe

describe('ModuleStatusGuardService', () => {
  let service: ModuleStatusGuardService;
  let httpClient: HttpClient;
  let router: Router;
  let route: ActivatedRouteSnapshot;
  let ngZone: NgZone;

  @Component({ selector: 'cd-foo', template: '' })
  class FooComponent {}

  const fakeService = {
    get: () => true
  };

  const routes: Routes = [{ path: '**', component: FooComponent }];

  const testCanActivate = (getResult: {}, activateResult: boolean, urlResult: string) => {
    let result: boolean;
    spyOn(httpClient, 'get').and.returnValue(observableOf(getResult));
    ngZone.run(() => {
      service.canActivateChild(route).subscribe((resp) => {
        result = resp;
      });
    });

    tick();
    expect(result).toBe(activateResult);
    expect(router.url).toBe(urlResult);
  };

  configureTestBed(
    {
      imports: [RouterTestingModule.withRoutes(routes)],
      providers: [ModuleStatusGuardService, { provide: HttpClient, useValue: fakeService }],
      declarations: [FooComponent]
    },
    true
  );

  beforeEach(() => {
    service = TestBed.get(ModuleStatusGuardService);
    httpClient = TestBed.get(HttpClient);
    router = TestBed.get(Router);
    route = new ActivatedRouteSnapshot();
    route.url = [];
    route.data = {
      moduleStatusGuardConfig: {
        apiPath: 'bar',
        redirectTo: '/foo'
      }
    };
    ngZone = TestBed.get(NgZone);
  });

  it('should be created', () => {
    expect(service).toBeTruthy();
  });

  it('should test canActivate with status available', fakeAsync(() => {
    route.data.moduleStatusGuardConfig.redirectTo = 'foo';
    testCanActivate({ available: true, message: 'foo' }, true, '/');
  }));

  it('should test canActivateChild with status unavailable', fakeAsync(() => {
    testCanActivate({ available: false, message: null }, false, '/foo/');
  }));

  it('should test canActivateChild with status unavailable', fakeAsync(() => {
    testCanActivate(null, false, '/foo');
  }));
});
开发者ID:LenzGr,项目名称:ceph,代码行数:71,代码来源:module-status-guard.service.spec.ts

示例4: describe

describe('BreadcrumbsComponent', () => {
  let component: BreadcrumbsComponent;
  let fixture: ComponentFixture<BreadcrumbsComponent>;
  let router: Router;

  @Component({ selector: 'cd-fake', template: '' })
  class FakeComponent {}

  const routes: Routes = [
    {
      path: 'hosts',
      component: FakeComponent,
      data: { breadcrumbs: 'Cluster/Hosts' }
    },
    {
      path: 'perf_counters',
      component: FakeComponent,
      data: {
        breadcrumbs: PerformanceCounterBreadcrumbsResolver
      }
    },
    {
      path: 'block',
      data: { breadcrumbs: true, text: 'Block', path: null },
      children: [
        {
          path: 'rbd',
          data: { breadcrumbs: 'Images' },
          children: [
            { path: '', component: FakeComponent },
            { path: 'add', component: FakeComponent, data: { breadcrumbs: 'Add' } }
          ]
        }
      ]
    }
  ];

  configureTestBed({
    declarations: [BreadcrumbsComponent, FakeComponent],
    imports: [CommonModule, RouterTestingModule.withRoutes(routes)],
    providers: [PerformanceCounterBreadcrumbsResolver]
  });

  beforeEach(() => {
    fixture = TestBed.createComponent(BreadcrumbsComponent);
    router = TestBed.get(Router);
    component = fixture.componentInstance;
    fixture.detectChanges();
    expect(component.crumbs).toEqual([]);
  });

  it('should create', () => {
    expect(component).toBeTruthy();
    expect(component.subscription).toBeDefined();
  });

  it(
    'should run postProcess and split the breadcrumbs when navigating to hosts',
    fakeAsync(() => {
      router.navigateByUrl('/hosts');
      tick();
      expect(component.crumbs).toEqual([
        { path: null, text: 'Cluster' },
        { path: '/hosts', text: 'Hosts' }
      ]);
    })
  );

  it(
    'should display empty breadcrumb when navigating to perf_counters from unknown path',
    fakeAsync(() => {
      router.navigateByUrl('/perf_counters');
      tick();
      expect(component.crumbs).toEqual([
        { path: null, text: 'Cluster' },
        { path: null, text: '' },
        { path: '', text: 'Performance Counters' }
      ]);
    })
  );

  it(
    'should display Monitor breadcrumb when navigating to perf_counters from Monitors',
    fakeAsync(() => {
      router.navigate(['/perf_counters'], { queryParams: { fromLink: '/monitor' } });
      tick();
      expect(component.crumbs).toEqual([
        { path: null, text: 'Cluster' },
        { path: '/monitor', text: 'Monitors' },
        { path: '', text: 'Performance Counters' }
      ]);
    })
  );

  it(
    'should display Hosts breadcrumb when navigating to perf_counters from Hosts',
    fakeAsync(() => {
      router.navigate(['/perf_counters'], { queryParams: { fromLink: '/hosts' } });
      tick();
      expect(component.crumbs).toEqual([
//.........这里部分代码省略.........
开发者ID:ShiqiCooperation,项目名称:ceph,代码行数:101,代码来源:breadcrumbs.component.spec.ts

示例5: describe

describe('RoleFormComponent', () => {
  let component: RoleFormComponent;
  let form: CdFormGroup;
  let fixture: ComponentFixture<RoleFormComponent>;
  let httpTesting: HttpTestingController;
  let roleService: RoleService;
  let router: Router;
  const setUrl = (url) => Object.defineProperty(router, 'url', { value: url });

  @Component({ selector: 'cd-fake', template: '' })
  class FakeComponent {}

  const routes: Routes = [{ path: 'roles', component: FakeComponent }];

  configureTestBed(
    {
      imports: [
        [RouterTestingModule.withRoutes(routes)],
        HttpClientTestingModule,
        ReactiveFormsModule,
        RouterTestingModule,
        ComponentsModule,
        ToastModule.forRoot(),
        SharedModule
      ],
      declarations: [RoleFormComponent, FakeComponent]
    },
    true
  );

  beforeEach(() => {
    fixture = TestBed.createComponent(RoleFormComponent);
    component = fixture.componentInstance;
    form = component.roleForm;
    httpTesting = TestBed.get(HttpTestingController);
    roleService = TestBed.get(RoleService);
    router = TestBed.get(Router);
    spyOn(router, 'navigate');
    fixture.detectChanges();
    const notify = TestBed.get(NotificationService);
    spyOn(notify, 'show');
  });

  it('should create', () => {
    expect(component).toBeTruthy();
    expect(form).toBeTruthy();
  });

  describe('create mode', () => {
    beforeEach(() => {
      setUrl('/user-management/roles/add');
      component.ngOnInit();
    });

    it('should not disable fields', () => {
      ['name', 'description', 'scopes_permissions'].forEach((key) =>
        expect(form.get(key).disabled).toBeFalsy()
      );
    });

    it('should validate name required', () => {
      form.get('name').setValue('');
      expect(form.get('name').hasError('required')).toBeTruthy();
    });

    it('should set mode', () => {
      expect(component.mode).toBeUndefined();
    });

    it('should submit', () => {
      const role: RoleFormModel = {
        name: 'role1',
        description: 'Role 1',
        scopes_permissions: { osd: ['read'] }
      };
      Object.keys(role).forEach((k) => form.get(k).setValue(role[k]));
      component.submit();
      const roleReq = httpTesting.expectOne('api/role');
      expect(roleReq.request.method).toBe('POST');
      expect(roleReq.request.body).toEqual(role);
      roleReq.flush({});
      expect(router.navigate).toHaveBeenCalledWith(['/user-management/roles']);
    });

    it('should check all perms for a scope', () => {
      form.get('scopes_permissions').setValue({ cephfs: ['read'] });
      component.onClickCellCheckbox('grafana', 'scope');
      const scopes_permissions = form.getValue('scopes_permissions');
      expect(Object.keys(scopes_permissions)).toContain('grafana');
      expect(scopes_permissions['grafana']).toEqual(['create', 'delete', 'read', 'update']);
    });

    it('should uncheck all perms for a scope', () => {
      form.get('scopes_permissions').setValue({ cephfs: ['read', 'create', 'update', 'delete'] });
      component.onClickCellCheckbox('cephfs', 'scope');
      const scopes_permissions = form.getValue('scopes_permissions');
      expect(Object.keys(scopes_permissions)).not.toContain('cephfs');
    });

    it('should uncheck all scopes and perms', () => {
//.........这里部分代码省略.........
开发者ID:Yan-waller,项目名称:ceph,代码行数:101,代码来源:role-form.component.spec.ts

示例6: beforeEach

  beforeEach(async(() => {

    TestBed.configureTestingModule({
      imports: [AppModule, RouterTestingModule.withRoutes([])]
    }).compileComponents();
  }));
开发者ID:MarcosPrieto,项目名称:Angular-AlbumStoreProductPage,代码行数:6,代码来源:app-component-html-uses-router-outlet.projects.spec.ts

示例7: platformBrowserDynamicTesting

        'title': 'Post 1',
        'description': 'Post Description 1'
      }]);
      // to complete stream use observer.complete();
    });
  }
}

@Component({
  selector: 'test',
  template: 'test'
})
class RouterTestingComponent {
}
let MockRoutes = RouterTestingModule.withRoutes([
  { path: 'new', component: RouterTestingComponent }
]);

describe('FeedsListComponent', () => {
  TestBed.initTestEnvironment(
    BrowserDynamicTestingModule,
    platformBrowserDynamicTesting()
  );

  beforeEach(() => {
    TestBed.configureTestingModule({
      imports: [MockRoutes],
      declarations: [FeedsListComponent, FeedsComponent, EllipsisAfterPipe, RouterTestingComponent],
      providers: [
        { provide: FeedsService, useClass: MockFeedsService }
      ]
开发者ID:ramana-chavakula,项目名称:angular2-webpack,代码行数:31,代码来源:feedsList.component.spec.ts

示例8: describe


//.........这里部分代码省略.........
        }
      },
      call: undefined // because of stub
    });
  };

  const setUpPoolComponent = () => {
    fixture = TestBed.createComponent(PoolFormComponent);
    fixtureHelper = new FixtureHelper(fixture);
    component = fixture.componentInstance;
    component.info = {
      pool_names: [],
      osd_count: OSDS,
      is_all_bluestore: true,
      bluestore_compression_algorithm: 'snappy',
      compression_algorithms: ['snappy'],
      compression_modes: ['none', 'passive'],
      crush_rules_replicated: [],
      crush_rules_erasure: []
    };
    const ecp1 = new ErasureCodeProfile();
    ecp1.name = 'ecp1';
    component.ecProfiles = [ecp1];
    form = component.form;
    formHelper = new FormHelper(form);
  };

  const routes: Routes = [{ path: '404', component: NotFoundComponent }];

  configureTestBed({
    declarations: [NotFoundComponent],
    imports: [
      HttpClientTestingModule,
      RouterTestingModule.withRoutes(routes),
      ToastModule.forRoot(),
      TabsModule.forRoot(),
      PoolModule
    ],
    providers: [
      ErasureCodeProfileService,
      SelectBadgesComponent,
      { provide: ActivatedRoute, useValue: { params: of({ name: 'somePoolName' }) } },
      i18nProviders
    ]
  });

  beforeEach(() => {
    setUpPoolComponent();
    poolService = TestBed.get(PoolService);
    spyOn(poolService, 'getInfo').and.callFake(() => [component.info]);
    ecpService = TestBed.get(ErasureCodeProfileService);
    spyOn(ecpService, 'list').and.callFake(() => [component.ecProfiles]);
    router = TestBed.get(Router);
    spyOn(router, 'navigate').and.stub();
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });

  describe('redirect not allowed users', () => {
    let poolPermissions: Permission;
    let authStorageService: AuthStorageService;

    const testForRedirect = (times: number) => {
      component.authenticate();
开发者ID:ceph,项目名称:ceph,代码行数:67,代码来源:pool-form.component.spec.ts

示例9: beforeEach

    beforeEach(() => {

        TestBed.configureTestingModule({
            declarations: [HomeComponent, InventurComponent, InventarComponent, BilanzComponent],
            providers: [
                InventurService,
                LoggerService,
                {
                    provide: QueryGatewayService,
                    useValue: jasmine.createSpyObj('QueryGatewayService', ['send'])
                }
            ],
            imports: [NgReduxModule, HttpClientTestingModule, CommandGatewayModule, RouterTestingModule.withRoutes(DEMO_APP_ROUTES)],
            schemas: [NO_ERRORS_SCHEMA]
        });
    });
开发者ID:haschi,项目名称:dominium,代码行数:16,代码来源:inventur.service.spec.ts

示例10: async

 async(() => {
   TestBed.configureTestingModule({
     imports: [AppModule, RouterTestingModule.withRoutes(routes)]
   }).compileComponents()
 })
开发者ID:KHP-Informatics,项目名称:RADAR-frontend,代码行数:5,代码来源:app.component.spec.ts


注:本文中的@angular/router/testing.RouterTestingModule.withRoutes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。