本文整理汇总了TypeScript中app/shared/login/login.component.JhiLoginModalComponent类的典型用法代码示例。如果您正苦于以下问题:TypeScript component.JhiLoginModalComponent类的具体用法?TypeScript component.JhiLoginModalComponent怎么用?TypeScript component.JhiLoginModalComponent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了component.JhiLoginModalComponent类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: describe
describe('LoginComponent', () => {
let comp: JhiLoginModalComponent;
let fixture: ComponentFixture<JhiLoginModalComponent>;
let mockLoginService: any;
let mockStateStorageService: any;
let mockRouter: any;
let mockEventManager: any;
let mockActiveModal: any;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [TrebolTestModule],
declarations: [JhiLoginModalComponent],
providers: [
{
provide: LoginService,
useClass: MockLoginService
},
{
provide: StateStorageService,
useClass: MockStateStorageService
}
]
})
.overrideTemplate(JhiLoginModalComponent, '')
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(JhiLoginModalComponent);
comp = fixture.componentInstance;
mockLoginService = fixture.debugElement.injector.get(LoginService);
mockStateStorageService = fixture.debugElement.injector.get(StateStorageService);
mockRouter = fixture.debugElement.injector.get(Router);
mockEventManager = fixture.debugElement.injector.get(JhiEventManager);
mockActiveModal = fixture.debugElement.injector.get(NgbActiveModal);
});
it('should authenticate the user upon login when previous state was set', inject(
[],
fakeAsync(() => {
// GIVEN
const credentials = {
username: 'admin',
password: 'admin',
rememberMe: true
};
comp.username = 'admin';
comp.password = 'admin';
comp.rememberMe = true;
comp.credentials = credentials;
mockLoginService.setResponse({});
mockStateStorageService.setResponse({ redirect: 'dummy' });
// WHEN/
comp.login();
tick(); // simulate async
// THEN
expect(comp.authenticationError).toEqual(false);
expect(mockActiveModal.dismissSpy).toHaveBeenCalledWith('login success');
expect(mockEventManager.broadcastSpy).toHaveBeenCalledTimes(1);
expect(mockLoginService.loginSpy).toHaveBeenCalledWith(credentials);
expect(mockStateStorageService.getUrlSpy).toHaveBeenCalledTimes(1);
expect(mockStateStorageService.storeUrlSpy).toHaveBeenCalledWith(null);
expect(mockRouter.navigateSpy).toHaveBeenCalledWith([{ redirect: 'dummy' }]);
})
));
it('should authenticate the user upon login when previous state was not set', inject(
[],
fakeAsync(() => {
// GIVEN
const credentials = {
username: 'admin',
password: 'admin',
rememberMe: true
};
comp.username = 'admin';
comp.password = 'admin';
comp.rememberMe = true;
comp.credentials = credentials;
mockLoginService.setResponse({});
mockStateStorageService.setResponse(null);
// WHEN
comp.login();
tick(); // simulate async
// THEN
expect(comp.authenticationError).toEqual(false);
expect(mockActiveModal.dismissSpy).toHaveBeenCalledWith('login success');
expect(mockEventManager.broadcastSpy).toHaveBeenCalledTimes(1);
expect(mockLoginService.loginSpy).toHaveBeenCalledWith(credentials);
expect(mockStateStorageService.getUrlSpy).toHaveBeenCalledTimes(1);
expect(mockStateStorageService.storeUrlSpy).not.toHaveBeenCalled();
expect(mockRouter.navigateSpy).not.toHaveBeenCalled();
})
));
//.........这里部分代码省略.........
示例2: it
it('should empty the credentials upon cancel', () => {
// GIVEN
const credentials = {
username: 'admin',
password: 'admin',
rememberMe: true
};
const expected = {
username: null,
password: null,
rememberMe: true
};
comp.credentials = credentials;
// WHEN
comp.cancel();
// THEN
expect(comp.authenticationError).toEqual(false);
expect(comp.credentials).toEqual(expected);
expect(mockActiveModal.dismissSpy).toHaveBeenCalledWith('cancel');
});
示例3: it
it('should empty the credentials upon cancel', () => {
// GIVEN
comp.loginForm.patchValue({
username: 'admin',
password: 'admin'
});
const expected = {
username: '',
password: '',
rememberMe: true
};
// WHEN
comp.cancel();
// THEN
expect(comp.authenticationError).toEqual(false);
expect(comp.loginForm.get('username').value).toEqual(expected.username);
expect(comp.loginForm.get('password').value).toEqual(expected.password);
expect(comp.loginForm.get('rememberMe').value).toEqual(expected.rememberMe);
expect(mockActiveModal.dismissSpy).toHaveBeenCalledWith('cancel');
});