Initial application generated by JHipster-5.8.2
This commit is contained in:
.editorconfig.gitattributes.gitignore.huskyrc.prettierignore.prettierrc.yo-rc.jsonREADME.mdangular.jsonbuild.gradlegradle.propertiestsconfig-aot.jsontsconfig.jsontslint.json
gradle
gradlewgradlew.batpackage-lock.jsonpackage.jsonpostcss.config.jsproxy.conf.jsonsettings.gradlesrc
main
docker
java
org
hostsharing
hsadminng
ApplicationWebXml.javaHsadminNgApp.java
aop
logging
config
ApplicationProperties.javaAsyncConfiguration.javaCacheConfiguration.javaCloudDatabaseConfiguration.javaConstants.javaDatabaseConfiguration.javaDateTimeFormatConfiguration.javaDefaultProfileUtil.javaJacksonConfiguration.javaLiquibaseConfiguration.javaLocaleConfiguration.javaLoggingAspectConfiguration.javaLoggingConfiguration.javaSecurityConfiguration.javaWebConfigurer.java
audit
package-info.javadomain
repository
AuthorityRepository.javaCustomAuditEventRepository.javaPersistenceAuditEventRepository.javaUserRepository.javapackage-info.java
security
AuthoritiesConstants.javaDomainUserDetailsService.javaSecurityUtils.javaSpringSecurityAuditorAware.javaUserNotActivatedException.java
jwt
package-info.javaservice
web
rest
AccountResource.javaAuditResource.javaLogsResource.javaUserJWTController.javaUserResource.java
errors
BadRequestAlertException.javaCustomParameterizedException.javaEmailAlreadyUsedException.javaEmailNotFoundException.javaErrorConstants.javaExceptionTranslator.javaFieldErrorVM.javaInternalServerErrorException.javaInvalidPasswordException.javaLoginAlreadyUsedException.javapackage-info.java
package-info.javautil
vm
jib
resources
.h2.server.propertiesbanner.txt
config
i18n
logback-spring.xmlswagger
templates
webapp
404.htmlvendor.tsfavicon.icoindex.htmlmanifest.webapprobots.txt
app
account
account.module.tsaccount.route.ts
activate
index.tspassword-reset
finish
password-reset-finish.component.htmlpassword-reset-finish.component.tspassword-reset-finish.route.tspassword-reset-finish.service.ts
init
password
password-strength-bar.component.tspassword-strength-bar.csspassword.component.htmlpassword.component.tspassword.route.tspassword.service.ts
register
settings
admin
admin.module.tsadmin.route.ts
app-routing.module.tsapp.constants.tsapp.main.tsapp.module.tsaudits
audit-data.model.tsaudit.model.tsaudits.component.htmlaudits.component.tsaudits.route.tsaudits.service.ts
configuration
configuration.component.htmlconfiguration.component.tsconfiguration.route.tsconfiguration.service.ts
docs
health
health-modal.component.htmlhealth-modal.component.tshealth.component.htmlhealth.component.tshealth.route.tshealth.service.ts
index.tslogs
metrics
user-management
user-management-delete-dialog.component.htmluser-management-delete-dialog.component.tsuser-management-detail.component.htmluser-management-detail.component.tsuser-management-update.component.htmluser-management-update.component.tsuser-management.component.htmluser-management.component.tsuser-management.route.ts
blocks
config
interceptor
core
auth
account.service.tsauth-jwt.service.tscsrf.service.tsstate-storage.service.tsuser-route-access-service.ts
core.module.tsindex.tslanguage
login
user
entities
home
layouts
polyfills.tsshared
alert
auth
constants
index.tslanguage
login
shared-common.module.tsshared-libs.module.tsshared.module.tsutil
content
css
images
jhipster_family_member_0.svgjhipster_family_member_0_head-192.pngjhipster_family_member_0_head-256.pngjhipster_family_member_0_head-384.pngjhipster_family_member_0_head-512.pngjhipster_family_member_1.svgjhipster_family_member_1_head-192.pngjhipster_family_member_1_head-256.pngjhipster_family_member_1_head-384.pngjhipster_family_member_1_head-512.pngjhipster_family_member_2.svgjhipster_family_member_2_head-192.pngjhipster_family_member_2_head-256.pngjhipster_family_member_2_head-384.pngjhipster_family_member_2_head-512.pngjhipster_family_member_3.svgjhipster_family_member_3_head-192.pngjhipster_family_member_3_head-256.pngjhipster_family_member_3_head-384.pngjhipster_family_member_3_head-512.pnglogo-jhipster.png
i18n
de
activate.jsonaudits.jsonconfiguration.jsonerror.jsonglobal.jsonhealth.jsonhome.jsonlogin.jsonlogs.jsonmetrics.jsonpassword.jsonregister.jsonreset.jsonsessions.jsonsettings.jsonuser-management.json
en
swagger-ui
test
features
java
org
hostsharing
hsadminng
config
cucumber
repository
security
service
web
javascript
jest-global-mocks.tsjest.conf.jsjest.ts
spec
app
account
activate
password-reset
password
register
settings
admin
audits
configuration
health
logs
metrics
user-management
core
shared
helpers
mock-account.service.tsmock-active-modal.service.tsmock-alert.service.tsmock-event-manager.service.tsmock-language.service.tsmock-login.service.tsmock-route.service.tsmock-state-storage.service.tsspyobject.ts
test.module.tsresources
webpack
x@@ -0,0 +1,72 @@
|
||||
import { TestBed, async, tick, fakeAsync, inject } from '@angular/core/testing';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { Observable, of, throwError } from 'rxjs';
|
||||
|
||||
import { HsadminNgTestModule } from '../../../test.module';
|
||||
import { MockActivatedRoute } from '../../../helpers/mock-route.service';
|
||||
import { ActivateService } from 'app/account/activate/activate.service';
|
||||
import { ActivateComponent } from 'app/account/activate/activate.component';
|
||||
|
||||
describe('Component Tests', () => {
|
||||
describe('ActivateComponent', () => {
|
||||
let comp: ActivateComponent;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [HsadminNgTestModule],
|
||||
declarations: [ActivateComponent],
|
||||
providers: [
|
||||
{
|
||||
provide: ActivatedRoute,
|
||||
useValue: new MockActivatedRoute({ key: 'ABC123' })
|
||||
}
|
||||
]
|
||||
})
|
||||
.overrideTemplate(ActivateComponent, '')
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
const fixture = TestBed.createComponent(ActivateComponent);
|
||||
comp = fixture.componentInstance;
|
||||
});
|
||||
|
||||
it('calls activate.get with the key from params', inject(
|
||||
[ActivateService],
|
||||
fakeAsync((service: ActivateService) => {
|
||||
spyOn(service, 'get').and.returnValue(of());
|
||||
|
||||
comp.ngOnInit();
|
||||
tick();
|
||||
|
||||
expect(service.get).toHaveBeenCalledWith('ABC123');
|
||||
})
|
||||
));
|
||||
|
||||
it('should set set success to OK upon successful activation', inject(
|
||||
[ActivateService],
|
||||
fakeAsync((service: ActivateService) => {
|
||||
spyOn(service, 'get').and.returnValue(of({}));
|
||||
|
||||
comp.ngOnInit();
|
||||
tick();
|
||||
|
||||
expect(comp.error).toBe(null);
|
||||
expect(comp.success).toEqual('OK');
|
||||
})
|
||||
));
|
||||
|
||||
it('should set set error to ERROR upon activation failure', inject(
|
||||
[ActivateService],
|
||||
fakeAsync((service: ActivateService) => {
|
||||
spyOn(service, 'get').and.returnValue(throwError('ERROR'));
|
||||
|
||||
comp.ngOnInit();
|
||||
tick();
|
||||
|
||||
expect(comp.error).toBe('ERROR');
|
||||
expect(comp.success).toEqual(null);
|
||||
})
|
||||
));
|
||||
});
|
||||
});
|
119
src/test/javascript/spec/app/account/password-reset/finish/password-reset-finish.component.spec.ts
Normal file
119
src/test/javascript/spec/app/account/password-reset/finish/password-reset-finish.component.spec.ts
Normal file
@@ -0,0 +1,119 @@
|
||||
import { ComponentFixture, TestBed, inject, tick, fakeAsync } from '@angular/core/testing';
|
||||
import { Observable, of, throwError } from 'rxjs';
|
||||
import { Renderer, ElementRef } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
|
||||
import { HsadminNgTestModule } from '../../../../test.module';
|
||||
import { PasswordResetFinishComponent } from 'app/account/password-reset/finish/password-reset-finish.component';
|
||||
import { PasswordResetFinishService } from 'app/account/password-reset/finish/password-reset-finish.service';
|
||||
import { MockActivatedRoute } from '../../../../helpers/mock-route.service';
|
||||
|
||||
describe('Component Tests', () => {
|
||||
describe('PasswordResetFinishComponent', () => {
|
||||
let fixture: ComponentFixture<PasswordResetFinishComponent>;
|
||||
let comp: PasswordResetFinishComponent;
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.configureTestingModule({
|
||||
imports: [HsadminNgTestModule],
|
||||
declarations: [PasswordResetFinishComponent],
|
||||
providers: [
|
||||
{
|
||||
provide: ActivatedRoute,
|
||||
useValue: new MockActivatedRoute({ key: 'XYZPDQ' })
|
||||
},
|
||||
{
|
||||
provide: Renderer,
|
||||
useValue: {
|
||||
invokeElementMethod(renderElement: any, methodName: string, args?: any[]) {}
|
||||
}
|
||||
},
|
||||
{
|
||||
provide: ElementRef,
|
||||
useValue: new ElementRef(null)
|
||||
}
|
||||
]
|
||||
})
|
||||
.overrideTemplate(PasswordResetFinishComponent, '')
|
||||
.createComponent(PasswordResetFinishComponent);
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(PasswordResetFinishComponent);
|
||||
comp = fixture.componentInstance;
|
||||
comp.ngOnInit();
|
||||
});
|
||||
|
||||
it('should define its initial state', () => {
|
||||
comp.ngOnInit();
|
||||
|
||||
expect(comp.keyMissing).toBeFalsy();
|
||||
expect(comp.key).toEqual('XYZPDQ');
|
||||
expect(comp.resetAccount).toEqual({});
|
||||
});
|
||||
|
||||
it('sets focus after the view has been initialized', inject([ElementRef], (elementRef: ElementRef) => {
|
||||
const element = fixture.nativeElement;
|
||||
const node = {
|
||||
focus() {}
|
||||
};
|
||||
|
||||
elementRef.nativeElement = element;
|
||||
spyOn(element, 'querySelector').and.returnValue(node);
|
||||
spyOn(node, 'focus');
|
||||
|
||||
comp.ngAfterViewInit();
|
||||
|
||||
expect(element.querySelector).toHaveBeenCalledWith('#password');
|
||||
expect(node.focus).toHaveBeenCalled();
|
||||
}));
|
||||
|
||||
it('should ensure the two passwords entered match', () => {
|
||||
comp.resetAccount.password = 'password';
|
||||
comp.confirmPassword = 'non-matching';
|
||||
|
||||
comp.finishReset();
|
||||
|
||||
expect(comp.doNotMatch).toEqual('ERROR');
|
||||
});
|
||||
|
||||
it('should update success to OK after resetting password', inject(
|
||||
[PasswordResetFinishService],
|
||||
fakeAsync((service: PasswordResetFinishService) => {
|
||||
spyOn(service, 'save').and.returnValue(of({}));
|
||||
|
||||
comp.resetAccount.password = 'password';
|
||||
comp.confirmPassword = 'password';
|
||||
|
||||
comp.finishReset();
|
||||
tick();
|
||||
|
||||
expect(service.save).toHaveBeenCalledWith({
|
||||
key: 'XYZPDQ',
|
||||
newPassword: 'password'
|
||||
});
|
||||
expect(comp.success).toEqual('OK');
|
||||
})
|
||||
));
|
||||
|
||||
it('should notify of generic error', inject(
|
||||
[PasswordResetFinishService],
|
||||
fakeAsync((service: PasswordResetFinishService) => {
|
||||
spyOn(service, 'save').and.returnValue(throwError('ERROR'));
|
||||
|
||||
comp.resetAccount.password = 'password';
|
||||
comp.confirmPassword = 'password';
|
||||
|
||||
comp.finishReset();
|
||||
tick();
|
||||
|
||||
expect(service.save).toHaveBeenCalledWith({
|
||||
key: 'XYZPDQ',
|
||||
newPassword: 'password'
|
||||
});
|
||||
expect(comp.success).toBeNull();
|
||||
expect(comp.error).toEqual('ERROR');
|
||||
})
|
||||
));
|
||||
});
|
||||
});
|
110
src/test/javascript/spec/app/account/password-reset/init/password-reset-init.component.spec.ts
Normal file
110
src/test/javascript/spec/app/account/password-reset/init/password-reset-init.component.spec.ts
Normal file
@@ -0,0 +1,110 @@
|
||||
import { ComponentFixture, TestBed, inject } from '@angular/core/testing';
|
||||
import { Renderer, ElementRef } from '@angular/core';
|
||||
import { Observable, of, throwError } from 'rxjs';
|
||||
|
||||
import { HsadminNgTestModule } from '../../../../test.module';
|
||||
import { PasswordResetInitComponent } from 'app/account/password-reset/init/password-reset-init.component';
|
||||
import { PasswordResetInitService } from 'app/account/password-reset/init/password-reset-init.service';
|
||||
import { EMAIL_NOT_FOUND_TYPE } from 'app/shared';
|
||||
|
||||
describe('Component Tests', () => {
|
||||
describe('PasswordResetInitComponent', () => {
|
||||
let fixture: ComponentFixture<PasswordResetInitComponent>;
|
||||
let comp: PasswordResetInitComponent;
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.configureTestingModule({
|
||||
imports: [HsadminNgTestModule],
|
||||
declarations: [PasswordResetInitComponent],
|
||||
providers: [
|
||||
{
|
||||
provide: Renderer,
|
||||
useValue: {
|
||||
invokeElementMethod(renderElement: any, methodName: string, args?: any[]) {}
|
||||
}
|
||||
},
|
||||
{
|
||||
provide: ElementRef,
|
||||
useValue: new ElementRef(null)
|
||||
}
|
||||
]
|
||||
})
|
||||
.overrideTemplate(PasswordResetInitComponent, '')
|
||||
.createComponent(PasswordResetInitComponent);
|
||||
comp = fixture.componentInstance;
|
||||
comp.ngOnInit();
|
||||
});
|
||||
|
||||
it('should define its initial state', () => {
|
||||
expect(comp.success).toBeUndefined();
|
||||
expect(comp.error).toBeUndefined();
|
||||
expect(comp.errorEmailNotExists).toBeUndefined();
|
||||
expect(comp.resetAccount).toEqual({});
|
||||
});
|
||||
|
||||
it('sets focus after the view has been initialized', inject([ElementRef], (elementRef: ElementRef) => {
|
||||
const element = fixture.nativeElement;
|
||||
const node = {
|
||||
focus() {}
|
||||
};
|
||||
|
||||
elementRef.nativeElement = element;
|
||||
spyOn(element, 'querySelector').and.returnValue(node);
|
||||
spyOn(node, 'focus');
|
||||
|
||||
comp.ngAfterViewInit();
|
||||
|
||||
expect(element.querySelector).toHaveBeenCalledWith('#email');
|
||||
expect(node.focus).toHaveBeenCalled();
|
||||
}));
|
||||
|
||||
it('notifies of success upon successful requestReset', inject([PasswordResetInitService], (service: PasswordResetInitService) => {
|
||||
spyOn(service, 'save').and.returnValue(of({}));
|
||||
comp.resetAccount.email = 'user@domain.com';
|
||||
|
||||
comp.requestReset();
|
||||
|
||||
expect(service.save).toHaveBeenCalledWith('user@domain.com');
|
||||
expect(comp.success).toEqual('OK');
|
||||
expect(comp.error).toBeNull();
|
||||
expect(comp.errorEmailNotExists).toBeNull();
|
||||
}));
|
||||
|
||||
it('notifies of unknown email upon email address not registered/400', inject(
|
||||
[PasswordResetInitService],
|
||||
(service: PasswordResetInitService) => {
|
||||
spyOn(service, 'save').and.returnValue(
|
||||
throwError({
|
||||
status: 400,
|
||||
error: { type: EMAIL_NOT_FOUND_TYPE }
|
||||
})
|
||||
);
|
||||
comp.resetAccount.email = 'user@domain.com';
|
||||
|
||||
comp.requestReset();
|
||||
|
||||
expect(service.save).toHaveBeenCalledWith('user@domain.com');
|
||||
expect(comp.success).toBeNull();
|
||||
expect(comp.error).toBeNull();
|
||||
expect(comp.errorEmailNotExists).toEqual('ERROR');
|
||||
}
|
||||
));
|
||||
|
||||
it('notifies of error upon error response', inject([PasswordResetInitService], (service: PasswordResetInitService) => {
|
||||
spyOn(service, 'save').and.returnValue(
|
||||
throwError({
|
||||
status: 503,
|
||||
data: 'something else'
|
||||
})
|
||||
);
|
||||
comp.resetAccount.email = 'user@domain.com';
|
||||
|
||||
comp.requestReset();
|
||||
|
||||
expect(service.save).toHaveBeenCalledWith('user@domain.com');
|
||||
expect(comp.success).toBeNull();
|
||||
expect(comp.errorEmailNotExists).toBeNull();
|
||||
expect(comp.error).toEqual('ERROR');
|
||||
}));
|
||||
});
|
||||
});
|
48
src/test/javascript/spec/app/account/password/password-strength-bar.component.spec.ts
Normal file
48
src/test/javascript/spec/app/account/password/password-strength-bar.component.spec.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
||||
|
||||
import { PasswordStrengthBarComponent } from 'app/account/password/password-strength-bar.component';
|
||||
|
||||
describe('Component Tests', () => {
|
||||
describe('PasswordStrengthBarComponent', () => {
|
||||
let comp: PasswordStrengthBarComponent;
|
||||
let fixture: ComponentFixture<PasswordStrengthBarComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [PasswordStrengthBarComponent]
|
||||
})
|
||||
.overrideTemplate(PasswordStrengthBarComponent, '')
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(PasswordStrengthBarComponent);
|
||||
comp = fixture.componentInstance;
|
||||
});
|
||||
|
||||
describe('PasswordStrengthBarComponents', () => {
|
||||
it('should initialize with default values', () => {
|
||||
expect(comp.measureStrength('')).toBe(0);
|
||||
expect(comp.colors).toEqual(['#F00', '#F90', '#FF0', '#9F0', '#0F0']);
|
||||
expect(comp.getColor(0).idx).toBe(1);
|
||||
expect(comp.getColor(0).col).toBe(comp.colors[0]);
|
||||
});
|
||||
|
||||
it('should increase strength upon password value change', () => {
|
||||
expect(comp.measureStrength('')).toBe(0);
|
||||
expect(comp.measureStrength('aa')).toBeGreaterThanOrEqual(comp.measureStrength(''));
|
||||
expect(comp.measureStrength('aa^6')).toBeGreaterThanOrEqual(comp.measureStrength('aa'));
|
||||
expect(comp.measureStrength('Aa090(**)')).toBeGreaterThanOrEqual(comp.measureStrength('aa^6'));
|
||||
expect(comp.measureStrength('Aa090(**)+-07365')).toBeGreaterThanOrEqual(comp.measureStrength('Aa090(**)'));
|
||||
});
|
||||
|
||||
it('should change the color based on strength', () => {
|
||||
expect(comp.getColor(0).col).toBe(comp.colors[0]);
|
||||
expect(comp.getColor(11).col).toBe(comp.colors[1]);
|
||||
expect(comp.getColor(22).col).toBe(comp.colors[2]);
|
||||
expect(comp.getColor(33).col).toBe(comp.colors[3]);
|
||||
expect(comp.getColor(44).col).toBe(comp.colors[4]);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@@ -0,0 +1,89 @@
|
||||
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
||||
import { HttpResponse } from '@angular/common/http';
|
||||
import { Observable, of, throwError } from 'rxjs';
|
||||
|
||||
import { HsadminNgTestModule } from '../../../test.module';
|
||||
import { PasswordComponent } from 'app/account/password/password.component';
|
||||
import { PasswordService } from 'app/account/password/password.service';
|
||||
|
||||
describe('Component Tests', () => {
|
||||
describe('PasswordComponent', () => {
|
||||
let comp: PasswordComponent;
|
||||
let fixture: ComponentFixture<PasswordComponent>;
|
||||
let service: PasswordService;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [HsadminNgTestModule],
|
||||
declarations: [PasswordComponent],
|
||||
providers: []
|
||||
})
|
||||
.overrideTemplate(PasswordComponent, '')
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(PasswordComponent);
|
||||
comp = fixture.componentInstance;
|
||||
service = fixture.debugElement.injector.get(PasswordService);
|
||||
});
|
||||
|
||||
it('should show error if passwords do not match', () => {
|
||||
// GIVEN
|
||||
comp.newPassword = 'password1';
|
||||
comp.confirmPassword = 'password2';
|
||||
// WHEN
|
||||
comp.changePassword();
|
||||
// THEN
|
||||
expect(comp.doNotMatch).toBe('ERROR');
|
||||
expect(comp.error).toBeNull();
|
||||
expect(comp.success).toBeNull();
|
||||
});
|
||||
|
||||
it('should call Auth.changePassword when passwords match', () => {
|
||||
// GIVEN
|
||||
const passwordValues = {
|
||||
currentPassword: 'oldPassword',
|
||||
newPassword: 'myPassword'
|
||||
};
|
||||
|
||||
spyOn(service, 'save').and.returnValue(of(new HttpResponse({ body: true })));
|
||||
comp.currentPassword = passwordValues.currentPassword;
|
||||
comp.newPassword = comp.confirmPassword = passwordValues.newPassword;
|
||||
|
||||
// WHEN
|
||||
comp.changePassword();
|
||||
|
||||
// THEN
|
||||
expect(service.save).toHaveBeenCalledWith(passwordValues.newPassword, passwordValues.currentPassword);
|
||||
});
|
||||
|
||||
it('should set success to OK upon success', function() {
|
||||
// GIVEN
|
||||
spyOn(service, 'save').and.returnValue(of(new HttpResponse({ body: true })));
|
||||
comp.newPassword = comp.confirmPassword = 'myPassword';
|
||||
|
||||
// WHEN
|
||||
comp.changePassword();
|
||||
|
||||
// THEN
|
||||
expect(comp.doNotMatch).toBeNull();
|
||||
expect(comp.error).toBeNull();
|
||||
expect(comp.success).toBe('OK');
|
||||
});
|
||||
|
||||
it('should notify of error if change password fails', function() {
|
||||
// GIVEN
|
||||
spyOn(service, 'save').and.returnValue(throwError('ERROR'));
|
||||
comp.newPassword = comp.confirmPassword = 'myPassword';
|
||||
|
||||
// WHEN
|
||||
comp.changePassword();
|
||||
|
||||
// THEN
|
||||
expect(comp.doNotMatch).toBeNull();
|
||||
expect(comp.success).toBeNull();
|
||||
expect(comp.error).toBe('ERROR');
|
||||
});
|
||||
});
|
||||
});
|
@@ -0,0 +1,121 @@
|
||||
import { ComponentFixture, TestBed, async, inject, tick, fakeAsync } from '@angular/core/testing';
|
||||
import { Observable, of, throwError } from 'rxjs';
|
||||
|
||||
import { JhiLanguageService } from 'ng-jhipster';
|
||||
import { MockLanguageService } from '../../../helpers/mock-language.service';
|
||||
import { HsadminNgTestModule } from '../../../test.module';
|
||||
import { EMAIL_ALREADY_USED_TYPE, LOGIN_ALREADY_USED_TYPE } from 'app/shared';
|
||||
import { Register } from 'app/account/register/register.service';
|
||||
import { RegisterComponent } from 'app/account/register/register.component';
|
||||
|
||||
describe('Component Tests', () => {
|
||||
describe('RegisterComponent', () => {
|
||||
let fixture: ComponentFixture<RegisterComponent>;
|
||||
let comp: RegisterComponent;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [HsadminNgTestModule],
|
||||
declarations: [RegisterComponent]
|
||||
})
|
||||
.overrideTemplate(RegisterComponent, '')
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(RegisterComponent);
|
||||
comp = fixture.componentInstance;
|
||||
comp.ngOnInit();
|
||||
});
|
||||
|
||||
it('should ensure the two passwords entered match', () => {
|
||||
comp.registerAccount.password = 'password';
|
||||
comp.confirmPassword = 'non-matching';
|
||||
|
||||
comp.register();
|
||||
|
||||
expect(comp.doNotMatch).toEqual('ERROR');
|
||||
});
|
||||
|
||||
it('should update success to OK after creating an account', inject(
|
||||
[Register, JhiLanguageService],
|
||||
fakeAsync((service: Register, mockTranslate: MockLanguageService) => {
|
||||
spyOn(service, 'save').and.returnValue(of({}));
|
||||
comp.registerAccount.password = comp.confirmPassword = 'password';
|
||||
|
||||
comp.register();
|
||||
tick();
|
||||
|
||||
expect(service.save).toHaveBeenCalledWith({
|
||||
password: 'password',
|
||||
langKey: 'de'
|
||||
});
|
||||
expect(comp.success).toEqual(true);
|
||||
expect(comp.registerAccount.langKey).toEqual('de');
|
||||
expect(mockTranslate.getCurrentSpy).toHaveBeenCalled();
|
||||
expect(comp.errorUserExists).toBeNull();
|
||||
expect(comp.errorEmailExists).toBeNull();
|
||||
expect(comp.error).toBeNull();
|
||||
})
|
||||
));
|
||||
|
||||
it('should notify of user existence upon 400/login already in use', inject(
|
||||
[Register],
|
||||
fakeAsync((service: Register) => {
|
||||
spyOn(service, 'save').and.returnValue(
|
||||
throwError({
|
||||
status: 400,
|
||||
error: { type: LOGIN_ALREADY_USED_TYPE }
|
||||
})
|
||||
);
|
||||
comp.registerAccount.password = comp.confirmPassword = 'password';
|
||||
|
||||
comp.register();
|
||||
tick();
|
||||
|
||||
expect(comp.errorUserExists).toEqual('ERROR');
|
||||
expect(comp.errorEmailExists).toBeNull();
|
||||
expect(comp.error).toBeNull();
|
||||
})
|
||||
));
|
||||
|
||||
it('should notify of email existence upon 400/email address already in use', inject(
|
||||
[Register],
|
||||
fakeAsync((service: Register) => {
|
||||
spyOn(service, 'save').and.returnValue(
|
||||
throwError({
|
||||
status: 400,
|
||||
error: { type: EMAIL_ALREADY_USED_TYPE }
|
||||
})
|
||||
);
|
||||
comp.registerAccount.password = comp.confirmPassword = 'password';
|
||||
|
||||
comp.register();
|
||||
tick();
|
||||
|
||||
expect(comp.errorEmailExists).toEqual('ERROR');
|
||||
expect(comp.errorUserExists).toBeNull();
|
||||
expect(comp.error).toBeNull();
|
||||
})
|
||||
));
|
||||
|
||||
it('should notify of generic error', inject(
|
||||
[Register],
|
||||
fakeAsync((service: Register) => {
|
||||
spyOn(service, 'save').and.returnValue(
|
||||
throwError({
|
||||
status: 503
|
||||
})
|
||||
);
|
||||
comp.registerAccount.password = comp.confirmPassword = 'password';
|
||||
|
||||
comp.register();
|
||||
tick();
|
||||
|
||||
expect(comp.errorUserExists).toBeNull();
|
||||
expect(comp.errorEmailExists).toBeNull();
|
||||
expect(comp.error).toEqual('ERROR');
|
||||
})
|
||||
));
|
||||
});
|
||||
});
|
@@ -0,0 +1,81 @@
|
||||
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
||||
import { Observable, throwError } from 'rxjs';
|
||||
|
||||
import { HsadminNgTestModule } from '../../../test.module';
|
||||
import { AccountService } from 'app/core';
|
||||
import { SettingsComponent } from 'app/account/settings/settings.component';
|
||||
|
||||
describe('Component Tests', () => {
|
||||
describe('SettingsComponent', () => {
|
||||
let comp: SettingsComponent;
|
||||
let fixture: ComponentFixture<SettingsComponent>;
|
||||
let mockAuth: any;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [HsadminNgTestModule],
|
||||
declarations: [SettingsComponent],
|
||||
providers: []
|
||||
})
|
||||
.overrideTemplate(SettingsComponent, '')
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(SettingsComponent);
|
||||
comp = fixture.componentInstance;
|
||||
mockAuth = fixture.debugElement.injector.get(AccountService);
|
||||
});
|
||||
|
||||
it('should send the current identity upon save', () => {
|
||||
// GIVEN
|
||||
const accountValues = {
|
||||
firstName: 'John',
|
||||
lastName: 'Doe',
|
||||
|
||||
activated: true,
|
||||
email: 'john.doe@mail.com',
|
||||
langKey: 'de',
|
||||
login: 'john'
|
||||
};
|
||||
mockAuth.setIdentityResponse(accountValues);
|
||||
|
||||
// WHEN
|
||||
comp.settingsAccount = accountValues;
|
||||
comp.save();
|
||||
|
||||
// THEN
|
||||
expect(mockAuth.identitySpy).toHaveBeenCalled();
|
||||
expect(mockAuth.saveSpy).toHaveBeenCalledWith(accountValues);
|
||||
expect(comp.settingsAccount).toEqual(accountValues);
|
||||
});
|
||||
|
||||
it('should notify of success upon successful save', () => {
|
||||
// GIVEN
|
||||
const accountValues = {
|
||||
firstName: 'John',
|
||||
lastName: 'Doe'
|
||||
};
|
||||
mockAuth.setIdentityResponse(accountValues);
|
||||
|
||||
// WHEN
|
||||
comp.save();
|
||||
|
||||
// THEN
|
||||
expect(comp.error).toBeNull();
|
||||
expect(comp.success).toBe('OK');
|
||||
});
|
||||
|
||||
it('should notify of error upon failed save', () => {
|
||||
// GIVEN
|
||||
mockAuth.saveSpy.and.returnValue(throwError('ERROR'));
|
||||
|
||||
// WHEN
|
||||
comp.save();
|
||||
|
||||
// THEN
|
||||
expect(comp.error).toEqual('ERROR');
|
||||
expect(comp.success).toBeNull();
|
||||
});
|
||||
});
|
||||
});
|
@@ -0,0 +1,133 @@
|
||||
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { HttpHeaders, HttpResponse } from '@angular/common/http';
|
||||
|
||||
import { HsadminNgTestModule } from '../../../test.module';
|
||||
import { AuditsComponent } from 'app/admin/audits/audits.component';
|
||||
import { AuditsService } from 'app/admin/audits/audits.service';
|
||||
import { Audit } from 'app/admin/audits/audit.model';
|
||||
import { ITEMS_PER_PAGE } from 'app/shared';
|
||||
|
||||
function build2DigitsDatePart(datePart: number) {
|
||||
return `0${datePart}`.slice(-2);
|
||||
}
|
||||
|
||||
function getDate(isToday = true) {
|
||||
let date: Date = new Date();
|
||||
if (isToday) {
|
||||
// Today + 1 day - needed if the current day must be included
|
||||
date.setDate(date.getDate() + 1);
|
||||
} else {
|
||||
// get last month
|
||||
if (date.getMonth() === 0) {
|
||||
date = new Date(date.getFullYear() - 1, 11, date.getDate());
|
||||
} else {
|
||||
date = new Date(date.getFullYear(), date.getMonth() - 1, date.getDate());
|
||||
}
|
||||
}
|
||||
const monthString = build2DigitsDatePart(date.getMonth() + 1);
|
||||
const dateString = build2DigitsDatePart(date.getDate());
|
||||
return `${date.getFullYear()}-${monthString}-${dateString}`;
|
||||
}
|
||||
|
||||
describe('Component Tests', () => {
|
||||
describe('AuditsComponent', () => {
|
||||
let comp: AuditsComponent;
|
||||
let fixture: ComponentFixture<AuditsComponent>;
|
||||
let service: AuditsService;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [HsadminNgTestModule],
|
||||
declarations: [AuditsComponent],
|
||||
providers: [AuditsService]
|
||||
})
|
||||
.overrideTemplate(AuditsComponent, '')
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(AuditsComponent);
|
||||
comp = fixture.componentInstance;
|
||||
service = fixture.debugElement.injector.get(AuditsService);
|
||||
});
|
||||
|
||||
describe('today function ', () => {
|
||||
it('should set toDate to current date', () => {
|
||||
comp.today();
|
||||
expect(comp.toDate).toBe(getDate());
|
||||
});
|
||||
});
|
||||
|
||||
describe('previousMonth function ', () => {
|
||||
it('should set fromDate to current date', () => {
|
||||
comp.previousMonth();
|
||||
expect(comp.fromDate).toBe(getDate(false));
|
||||
});
|
||||
});
|
||||
|
||||
describe('By default, on init', () => {
|
||||
it('should set all default values correctly', () => {
|
||||
fixture.detectChanges();
|
||||
expect(comp.toDate).toBe(getDate());
|
||||
expect(comp.fromDate).toBe(getDate(false));
|
||||
expect(comp.itemsPerPage).toBe(ITEMS_PER_PAGE);
|
||||
expect(comp.page).toBe(10);
|
||||
expect(comp.reverse).toBeFalsy();
|
||||
expect(comp.predicate).toBe('id');
|
||||
});
|
||||
});
|
||||
|
||||
describe('OnInit', () => {
|
||||
it('Should call load all on init', () => {
|
||||
// GIVEN
|
||||
const headers = new HttpHeaders().append('link', 'link;link');
|
||||
const audit = new Audit({ remoteAddress: '127.0.0.1', sessionId: '123' }, 'user', '20140101', 'AUTHENTICATION_SUCCESS');
|
||||
spyOn(service, 'query').and.returnValue(
|
||||
of(
|
||||
new HttpResponse({
|
||||
body: [audit],
|
||||
headers
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
// WHEN
|
||||
comp.ngOnInit();
|
||||
|
||||
// THEN
|
||||
expect(service.query).toHaveBeenCalled();
|
||||
expect(comp.audits[0]).toEqual(jasmine.objectContaining(audit));
|
||||
});
|
||||
});
|
||||
|
||||
describe('Create sort object', () => {
|
||||
it('Should sort only by id asc', () => {
|
||||
// GIVEN
|
||||
comp.predicate = 'id';
|
||||
comp.reverse = false;
|
||||
|
||||
// WHEN
|
||||
const sort = comp.sort();
|
||||
|
||||
// THEN
|
||||
expect(sort.length).toEqual(1);
|
||||
expect(sort[0]).toEqual('id,desc');
|
||||
});
|
||||
|
||||
it('Should sort by timestamp asc then by id', () => {
|
||||
// GIVEN
|
||||
comp.predicate = 'timestamp';
|
||||
comp.reverse = true;
|
||||
|
||||
// WHEN
|
||||
const sort = comp.sort();
|
||||
|
||||
// THEN
|
||||
expect(sort.length).toEqual(2);
|
||||
expect(sort[0]).toEqual('timestamp,asc');
|
||||
expect(sort[1]).toEqual('id');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@@ -0,0 +1,59 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { AuditsService } from 'app/admin/audits/audits.service';
|
||||
import { Audit } from 'app/admin/audits/audit.model';
|
||||
import { SERVER_API_URL } from 'app/app.constants';
|
||||
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
|
||||
|
||||
describe('Service Tests', () => {
|
||||
describe('Audits Service', () => {
|
||||
let service: AuditsService;
|
||||
let httpMock;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [HttpClientTestingModule]
|
||||
});
|
||||
|
||||
service = TestBed.get(AuditsService);
|
||||
httpMock = TestBed.get(HttpTestingController);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
httpMock.verify();
|
||||
});
|
||||
|
||||
describe('Service methods', () => {
|
||||
it('should call correct URL', () => {
|
||||
service.query({}).subscribe(() => {});
|
||||
|
||||
const req = httpMock.expectOne({ method: 'GET' });
|
||||
const resourceUrl = SERVER_API_URL + 'management/audits';
|
||||
expect(req.request.url).toEqual(resourceUrl);
|
||||
});
|
||||
|
||||
it('should return Audits', () => {
|
||||
const audit = new Audit({ remoteAddress: '127.0.0.1', sessionId: '123' }, 'user', '20140101', 'AUTHENTICATION_SUCCESS');
|
||||
|
||||
service.query({}).subscribe(received => {
|
||||
expect(received.body[0]).toEqual(audit);
|
||||
});
|
||||
|
||||
const req = httpMock.expectOne({ method: 'GET' });
|
||||
req.flush([audit]);
|
||||
});
|
||||
|
||||
it('should propagate not found response', () => {
|
||||
service.query({}).subscribe(null, (_error: any) => {
|
||||
expect(_error.status).toEqual(404);
|
||||
});
|
||||
|
||||
const req = httpMock.expectOne({ method: 'GET' });
|
||||
req.flush('Invalid request parameters', {
|
||||
status: 404,
|
||||
statusText: 'Bad Request'
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@@ -0,0 +1,71 @@
|
||||
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
||||
import { of } from 'rxjs';
|
||||
import { HttpHeaders, HttpResponse } from '@angular/common/http';
|
||||
|
||||
import { HsadminNgTestModule } from '../../../test.module';
|
||||
import { JhiConfigurationComponent } from 'app/admin/configuration/configuration.component';
|
||||
import { JhiConfigurationService } from 'app/admin/configuration/configuration.service';
|
||||
import { ITEMS_PER_PAGE } from 'app/shared';
|
||||
import { Log } from 'app/admin';
|
||||
|
||||
describe('Component Tests', () => {
|
||||
describe('JhiConfigurationComponent', () => {
|
||||
let comp: JhiConfigurationComponent;
|
||||
let fixture: ComponentFixture<JhiConfigurationComponent>;
|
||||
let service: JhiConfigurationService;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [HsadminNgTestModule],
|
||||
declarations: [JhiConfigurationComponent],
|
||||
providers: [JhiConfigurationService]
|
||||
})
|
||||
.overrideTemplate(JhiConfigurationComponent, '')
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(JhiConfigurationComponent);
|
||||
comp = fixture.componentInstance;
|
||||
service = fixture.debugElement.injector.get(JhiConfigurationService);
|
||||
});
|
||||
|
||||
describe('OnInit', () => {
|
||||
it('should set all default values correctly', () => {
|
||||
expect(comp.configKeys).toEqual([]);
|
||||
expect(comp.filter).toBe('');
|
||||
expect(comp.orderProp).toBe('prefix');
|
||||
expect(comp.reverse).toBe(false);
|
||||
});
|
||||
it('Should call load all on init', () => {
|
||||
// GIVEN
|
||||
const body = [{ config: 'test', properties: 'test' }, { config: 'test2' }];
|
||||
const envConfig = { envConfig: 'test' };
|
||||
spyOn(service, 'get').and.returnValue(of(body));
|
||||
spyOn(service, 'getEnv').and.returnValue(of(envConfig));
|
||||
|
||||
// WHEN
|
||||
comp.ngOnInit();
|
||||
|
||||
// THEN
|
||||
expect(service.get).toHaveBeenCalled();
|
||||
expect(service.getEnv).toHaveBeenCalled();
|
||||
expect(comp.configKeys).toEqual([['0', '1', '2', '3']]);
|
||||
expect(comp.allConfiguration).toEqual(envConfig);
|
||||
});
|
||||
});
|
||||
describe('keys method', () => {
|
||||
it('should return the keys of an Object', () => {
|
||||
// GIVEN
|
||||
const data = {
|
||||
key1: 'test',
|
||||
key2: 'test2'
|
||||
};
|
||||
|
||||
// THEN
|
||||
expect(comp.keys(data)).toEqual(['key1', 'key2']);
|
||||
expect(comp.keys(undefined)).toEqual([]);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@@ -0,0 +1,64 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { JhiConfigurationService } from 'app/admin/configuration/configuration.service';
|
||||
import { SERVER_API_URL } from 'app/app.constants';
|
||||
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
|
||||
import { HttpResponse } from '@angular/common/http';
|
||||
|
||||
describe('Service Tests', () => {
|
||||
describe('Logs Service', () => {
|
||||
let service: JhiConfigurationService;
|
||||
let httpMock;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [HttpClientTestingModule]
|
||||
});
|
||||
|
||||
service = TestBed.get(JhiConfigurationService);
|
||||
httpMock = TestBed.get(HttpTestingController);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
httpMock.verify();
|
||||
});
|
||||
|
||||
describe('Service methods', () => {
|
||||
it('should call correct URL', () => {
|
||||
service.get().subscribe(() => {});
|
||||
|
||||
const req = httpMock.expectOne({ method: 'GET' });
|
||||
const resourceUrl = SERVER_API_URL + 'management/configprops';
|
||||
expect(req.request.url).toEqual(resourceUrl);
|
||||
});
|
||||
|
||||
it('should get the config', () => {
|
||||
const angularConfig = {
|
||||
contexts: {
|
||||
angular: {
|
||||
beans: ['test2']
|
||||
}
|
||||
}
|
||||
};
|
||||
service.get().subscribe(received => {
|
||||
expect(received.body[0]).toEqual(angularConfig);
|
||||
});
|
||||
|
||||
const req = httpMock.expectOne({ method: 'GET' });
|
||||
req.flush(angularConfig);
|
||||
});
|
||||
|
||||
it('should get the env', () => {
|
||||
const propertySources = new HttpResponse({
|
||||
body: [{ name: 'test1', properties: 'test1' }, { name: 'test2', properties: 'test2' }]
|
||||
});
|
||||
service.get().subscribe(received => {
|
||||
expect(received.body[0]).toEqual(propertySources);
|
||||
});
|
||||
|
||||
const req = httpMock.expectOne({ method: 'GET' });
|
||||
req.flush(propertySources);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@@ -0,0 +1,321 @@
|
||||
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
||||
import { HttpResponse, HttpErrorResponse } from '@angular/common/http';
|
||||
import { of, throwError } from 'rxjs';
|
||||
|
||||
import { HsadminNgTestModule } from '../../../test.module';
|
||||
import { JhiHealthCheckComponent } from 'app/admin/health/health.component';
|
||||
import { JhiHealthService } from 'app/admin/health/health.service';
|
||||
|
||||
describe('Component Tests', () => {
|
||||
describe('JhiHealthCheckComponent', () => {
|
||||
let comp: JhiHealthCheckComponent;
|
||||
let fixture: ComponentFixture<JhiHealthCheckComponent>;
|
||||
let service: JhiHealthService;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [HsadminNgTestModule],
|
||||
declarations: [JhiHealthCheckComponent]
|
||||
})
|
||||
.overrideTemplate(JhiHealthCheckComponent, '')
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(JhiHealthCheckComponent);
|
||||
comp = fixture.componentInstance;
|
||||
service = fixture.debugElement.injector.get(JhiHealthService);
|
||||
});
|
||||
|
||||
describe('baseName and subSystemName', () => {
|
||||
it('should return the basename when it has no sub system', () => {
|
||||
expect(comp.baseName('base')).toBe('base');
|
||||
});
|
||||
|
||||
it('should return the basename when it has sub systems', () => {
|
||||
expect(comp.baseName('base.subsystem.system')).toBe('base');
|
||||
});
|
||||
|
||||
it('should return the sub system name', () => {
|
||||
expect(comp.subSystemName('subsystem')).toBe('');
|
||||
});
|
||||
|
||||
it('should return the subsystem when it has multiple keys', () => {
|
||||
expect(comp.subSystemName('subsystem.subsystem.system')).toBe(' - subsystem.system');
|
||||
});
|
||||
});
|
||||
|
||||
describe('transformHealthData', () => {
|
||||
it('should flatten empty health data', () => {
|
||||
const data = {};
|
||||
const expected = [];
|
||||
expect(service.transformHealthData(data)).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should flatten health data with no subsystems', () => {
|
||||
const data = {
|
||||
details: {
|
||||
status: 'UP',
|
||||
db: {
|
||||
status: 'UP',
|
||||
database: 'H2',
|
||||
hello: '1'
|
||||
},
|
||||
mail: {
|
||||
status: 'UP',
|
||||
error: 'mail.a.b.c'
|
||||
}
|
||||
}
|
||||
};
|
||||
const expected = [
|
||||
{
|
||||
name: 'db',
|
||||
status: 'UP',
|
||||
details: {
|
||||
database: 'H2',
|
||||
hello: '1'
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'mail',
|
||||
error: 'mail.a.b.c',
|
||||
status: 'UP'
|
||||
}
|
||||
];
|
||||
expect(service.transformHealthData(data)).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should flatten health data with subsystems at level 1, main system has no additional information', () => {
|
||||
const data = {
|
||||
details: {
|
||||
status: 'UP',
|
||||
db: {
|
||||
status: 'UP',
|
||||
database: 'H2',
|
||||
hello: '1'
|
||||
},
|
||||
mail: {
|
||||
status: 'UP',
|
||||
error: 'mail.a.b.c'
|
||||
},
|
||||
system: {
|
||||
status: 'DOWN',
|
||||
subsystem1: {
|
||||
status: 'UP',
|
||||
property1: 'system.subsystem1.property1'
|
||||
},
|
||||
subsystem2: {
|
||||
status: 'DOWN',
|
||||
error: 'system.subsystem1.error',
|
||||
property2: 'system.subsystem2.property2'
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
const expected = [
|
||||
{
|
||||
name: 'db',
|
||||
status: 'UP',
|
||||
details: {
|
||||
database: 'H2',
|
||||
hello: '1'
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'mail',
|
||||
error: 'mail.a.b.c',
|
||||
status: 'UP'
|
||||
},
|
||||
{
|
||||
name: 'system.subsystem1',
|
||||
status: 'UP',
|
||||
details: {
|
||||
property1: 'system.subsystem1.property1'
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'system.subsystem2',
|
||||
error: 'system.subsystem1.error',
|
||||
status: 'DOWN',
|
||||
details: {
|
||||
property2: 'system.subsystem2.property2'
|
||||
}
|
||||
}
|
||||
];
|
||||
expect(service.transformHealthData(data)).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should flatten health data with subsystems at level 1, main system has additional information', () => {
|
||||
const data = {
|
||||
details: {
|
||||
status: 'UP',
|
||||
db: {
|
||||
status: 'UP',
|
||||
database: 'H2',
|
||||
hello: '1'
|
||||
},
|
||||
mail: {
|
||||
status: 'UP',
|
||||
error: 'mail.a.b.c'
|
||||
},
|
||||
system: {
|
||||
status: 'DOWN',
|
||||
property1: 'system.property1',
|
||||
subsystem1: {
|
||||
status: 'UP',
|
||||
property1: 'system.subsystem1.property1'
|
||||
},
|
||||
subsystem2: {
|
||||
status: 'DOWN',
|
||||
error: 'system.subsystem1.error',
|
||||
property2: 'system.subsystem2.property2'
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
const expected = [
|
||||
{
|
||||
name: 'db',
|
||||
status: 'UP',
|
||||
details: {
|
||||
database: 'H2',
|
||||
hello: '1'
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'mail',
|
||||
error: 'mail.a.b.c',
|
||||
status: 'UP'
|
||||
},
|
||||
{
|
||||
name: 'system',
|
||||
status: 'DOWN',
|
||||
details: {
|
||||
property1: 'system.property1'
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'system.subsystem1',
|
||||
status: 'UP',
|
||||
details: {
|
||||
property1: 'system.subsystem1.property1'
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'system.subsystem2',
|
||||
error: 'system.subsystem1.error',
|
||||
status: 'DOWN',
|
||||
details: {
|
||||
property2: 'system.subsystem2.property2'
|
||||
}
|
||||
}
|
||||
];
|
||||
expect(service.transformHealthData(data)).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should flatten health data with subsystems at level 1, main system has additional error', () => {
|
||||
const data = {
|
||||
details: {
|
||||
status: 'UP',
|
||||
db: {
|
||||
status: 'UP',
|
||||
database: 'H2',
|
||||
hello: '1'
|
||||
},
|
||||
mail: {
|
||||
status: 'UP',
|
||||
error: 'mail.a.b.c'
|
||||
},
|
||||
system: {
|
||||
status: 'DOWN',
|
||||
error: 'show me',
|
||||
subsystem1: {
|
||||
status: 'UP',
|
||||
property1: 'system.subsystem1.property1'
|
||||
},
|
||||
subsystem2: {
|
||||
status: 'DOWN',
|
||||
error: 'system.subsystem1.error',
|
||||
property2: 'system.subsystem2.property2'
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
const expected = [
|
||||
{
|
||||
name: 'db',
|
||||
status: 'UP',
|
||||
details: {
|
||||
database: 'H2',
|
||||
hello: '1'
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'mail',
|
||||
error: 'mail.a.b.c',
|
||||
status: 'UP'
|
||||
},
|
||||
{
|
||||
name: 'system',
|
||||
error: 'show me',
|
||||
status: 'DOWN'
|
||||
},
|
||||
{
|
||||
name: 'system.subsystem1',
|
||||
status: 'UP',
|
||||
details: {
|
||||
property1: 'system.subsystem1.property1'
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'system.subsystem2',
|
||||
error: 'system.subsystem1.error',
|
||||
status: 'DOWN',
|
||||
details: {
|
||||
property2: 'system.subsystem2.property2'
|
||||
}
|
||||
}
|
||||
];
|
||||
expect(service.transformHealthData(data)).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getBadgeClass', () => {
|
||||
it('should get badge class', () => {
|
||||
const upBadgeClass = comp.getBadgeClass('UP');
|
||||
const downBadgeClass = comp.getBadgeClass('DOWN');
|
||||
expect(upBadgeClass).toEqual('badge-success');
|
||||
expect(downBadgeClass).toEqual('badge-danger');
|
||||
});
|
||||
});
|
||||
|
||||
describe('refresh', () => {
|
||||
it('should call refresh on init', () => {
|
||||
// GIVEN
|
||||
spyOn(service, 'checkHealth').and.returnValue(of(new HttpResponse()));
|
||||
spyOn(service, 'transformHealthData').and.returnValue(of({ data: 'test' }));
|
||||
|
||||
// WHEN
|
||||
comp.ngOnInit();
|
||||
|
||||
// THEN
|
||||
expect(service.checkHealth).toHaveBeenCalled();
|
||||
expect(service.transformHealthData).toHaveBeenCalled();
|
||||
expect(comp.healthData.value).toEqual({ data: 'test' });
|
||||
});
|
||||
it('should handle a 503 on refreshing health data', () => {
|
||||
// GIVEN
|
||||
spyOn(service, 'checkHealth').and.returnValue(throwError(new HttpErrorResponse({ status: 503, error: 'Mail down' })));
|
||||
spyOn(service, 'transformHealthData').and.returnValue(of({ health: 'down' }));
|
||||
|
||||
// WHEN
|
||||
comp.refresh();
|
||||
|
||||
// THEN
|
||||
expect(service.checkHealth).toHaveBeenCalled();
|
||||
expect(service.transformHealthData).toHaveBeenCalled();
|
||||
expect(comp.healthData.value).toEqual({ health: 'down' });
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@@ -0,0 +1,77 @@
|
||||
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
||||
import { of } from 'rxjs';
|
||||
import { HttpHeaders, HttpResponse } from '@angular/common/http';
|
||||
|
||||
import { HsadminNgTestModule } from '../../../test.module';
|
||||
import { LogsComponent } from 'app/admin/logs/logs.component';
|
||||
import { LogsService } from 'app/admin/logs/logs.service';
|
||||
import { ITEMS_PER_PAGE } from 'app/shared';
|
||||
import { Log } from 'app/admin';
|
||||
|
||||
describe('Component Tests', () => {
|
||||
describe('LogsComponent', () => {
|
||||
let comp: LogsComponent;
|
||||
let fixture: ComponentFixture<LogsComponent>;
|
||||
let service: LogsService;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [HsadminNgTestModule],
|
||||
declarations: [LogsComponent],
|
||||
providers: [LogsService]
|
||||
})
|
||||
.overrideTemplate(LogsComponent, '')
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(LogsComponent);
|
||||
comp = fixture.componentInstance;
|
||||
service = fixture.debugElement.injector.get(LogsService);
|
||||
});
|
||||
|
||||
describe('OnInit', () => {
|
||||
it('should set all default values correctly', () => {
|
||||
expect(comp.filter).toBe('');
|
||||
expect(comp.orderProp).toBe('name');
|
||||
expect(comp.reverse).toBe(false);
|
||||
});
|
||||
it('Should call load all on init', () => {
|
||||
// GIVEN
|
||||
const headers = new HttpHeaders().append('link', 'link;link');
|
||||
const log = new Log('main', 'WARN');
|
||||
spyOn(service, 'findAll').and.returnValue(
|
||||
of(
|
||||
new HttpResponse({
|
||||
body: [log],
|
||||
headers
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
// WHEN
|
||||
comp.ngOnInit();
|
||||
|
||||
// THEN
|
||||
expect(service.findAll).toHaveBeenCalled();
|
||||
expect(comp.loggers[0]).toEqual(jasmine.objectContaining(log));
|
||||
});
|
||||
});
|
||||
describe('change log level', () => {
|
||||
it('should change log level correctly', () => {
|
||||
// GIVEN
|
||||
const log = new Log('main', 'ERROR');
|
||||
spyOn(service, 'changeLevel').and.returnValue(of(new HttpResponse()));
|
||||
spyOn(service, 'findAll').and.returnValue(of(new HttpResponse({ body: [log] })));
|
||||
|
||||
// WHEN
|
||||
comp.changeLevel('main', 'ERROR');
|
||||
|
||||
// THEN
|
||||
expect(service.changeLevel).toHaveBeenCalled();
|
||||
expect(service.findAll).toHaveBeenCalled();
|
||||
expect(comp.loggers[0]).toEqual(jasmine.objectContaining(log));
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
58
src/test/javascript/spec/app/admin/logs/logs.service.spec.ts
Normal file
58
src/test/javascript/spec/app/admin/logs/logs.service.spec.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { LogsService } from 'app/admin/logs/logs.service';
|
||||
import { Log } from 'app/admin/logs/log.model';
|
||||
import { SERVER_API_URL } from 'app/app.constants';
|
||||
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
|
||||
|
||||
describe('Service Tests', () => {
|
||||
describe('Logs Service', () => {
|
||||
let service: LogsService;
|
||||
let httpMock;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [HttpClientTestingModule]
|
||||
});
|
||||
|
||||
service = TestBed.get(LogsService);
|
||||
httpMock = TestBed.get(HttpTestingController);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
httpMock.verify();
|
||||
});
|
||||
|
||||
describe('Service methods', () => {
|
||||
it('should call correct URL', () => {
|
||||
service.findAll().subscribe(() => {});
|
||||
|
||||
const req = httpMock.expectOne({ method: 'GET' });
|
||||
const resourceUrl = SERVER_API_URL + 'management/logs';
|
||||
expect(req.request.url).toEqual(resourceUrl);
|
||||
});
|
||||
|
||||
it('should return Logs', () => {
|
||||
const log = new Log('main', 'ERROR');
|
||||
|
||||
service.findAll().subscribe(received => {
|
||||
expect(received.body[0]).toEqual(log);
|
||||
});
|
||||
|
||||
const req = httpMock.expectOne({ method: 'GET' });
|
||||
req.flush([log]);
|
||||
});
|
||||
|
||||
it('should change log level', () => {
|
||||
const log = new Log('main', 'ERROR');
|
||||
|
||||
service.changeLevel(log).subscribe(received => {
|
||||
expect(received.body[0]).toEqual(log);
|
||||
});
|
||||
|
||||
const req = httpMock.expectOne({ method: 'PUT' });
|
||||
req.flush([log]);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@@ -0,0 +1,55 @@
|
||||
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
||||
import { HttpResponse, HttpErrorResponse } from '@angular/common/http';
|
||||
import { of, throwError } from 'rxjs';
|
||||
|
||||
import { HsadminNgTestModule } from '../../../test.module';
|
||||
import { JhiMetricsMonitoringComponent } from 'app/admin/metrics/metrics.component';
|
||||
import { JhiMetricsService } from 'app/admin/metrics/metrics.service';
|
||||
|
||||
describe('Component Tests', () => {
|
||||
describe('JhiMetricsMonitoringComponent', () => {
|
||||
let comp: JhiMetricsMonitoringComponent;
|
||||
let fixture: ComponentFixture<JhiMetricsMonitoringComponent>;
|
||||
let service: JhiMetricsService;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [HsadminNgTestModule],
|
||||
declarations: [JhiMetricsMonitoringComponent]
|
||||
})
|
||||
.overrideTemplate(JhiMetricsMonitoringComponent, '')
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(JhiMetricsMonitoringComponent);
|
||||
comp = fixture.componentInstance;
|
||||
service = fixture.debugElement.injector.get(JhiMetricsService);
|
||||
});
|
||||
|
||||
describe('refresh', () => {
|
||||
it('should call refresh on init', () => {
|
||||
// GIVEN
|
||||
const response = {
|
||||
timers: {
|
||||
service: 'test',
|
||||
unrelatedKey: 'test'
|
||||
},
|
||||
gauges: {
|
||||
'jcache.statistics': {
|
||||
value: 2
|
||||
},
|
||||
unrelatedKey: 'test'
|
||||
}
|
||||
};
|
||||
spyOn(service, 'getMetrics').and.returnValue(of(response));
|
||||
|
||||
// WHEN
|
||||
comp.ngOnInit();
|
||||
|
||||
// THEN
|
||||
expect(service.getMetrics).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@@ -0,0 +1,57 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { JhiMetricsService } from 'app/admin/metrics/metrics.service';
|
||||
import { SERVER_API_URL } from 'app/app.constants';
|
||||
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
|
||||
|
||||
describe('Service Tests', () => {
|
||||
describe('Logs Service', () => {
|
||||
let service: JhiMetricsService;
|
||||
let httpMock;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [HttpClientTestingModule]
|
||||
});
|
||||
|
||||
service = TestBed.get(JhiMetricsService);
|
||||
httpMock = TestBed.get(HttpTestingController);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
httpMock.verify();
|
||||
});
|
||||
|
||||
describe('Service methods', () => {
|
||||
it('should call correct URL', () => {
|
||||
service.getMetrics().subscribe(() => {});
|
||||
|
||||
const req = httpMock.expectOne({ method: 'GET' });
|
||||
const resourceUrl = SERVER_API_URL + 'management/jhi-metrics';
|
||||
expect(req.request.url).toEqual(resourceUrl);
|
||||
});
|
||||
|
||||
it('should return Metrics', () => {
|
||||
const metrics = [];
|
||||
|
||||
service.getMetrics().subscribe(received => {
|
||||
expect(received.body[0]).toEqual(metrics);
|
||||
});
|
||||
|
||||
const req = httpMock.expectOne({ method: 'GET' });
|
||||
req.flush([metrics]);
|
||||
});
|
||||
|
||||
it('should return Thread Dump', () => {
|
||||
const dump = [{ name: 'test1', threadState: 'RUNNABLE' }];
|
||||
|
||||
service.threadDump().subscribe(received => {
|
||||
expect(received.body[0]).toEqual(dump);
|
||||
});
|
||||
|
||||
const req = httpMock.expectOne({ method: 'GET' });
|
||||
req.flush([dump]);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
54
src/test/javascript/spec/app/admin/user-management/user-management-delete-dialog.component.spec.ts
Normal file
54
src/test/javascript/spec/app/admin/user-management/user-management-delete-dialog.component.spec.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import { ComponentFixture, TestBed, async, inject, fakeAsync, tick } from '@angular/core/testing';
|
||||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { JhiEventManager } from 'ng-jhipster';
|
||||
|
||||
import { HsadminNgTestModule } from '../../../test.module';
|
||||
import { UserMgmtDeleteDialogComponent } from 'app/admin/user-management/user-management-delete-dialog.component';
|
||||
import { UserService } from 'app/core';
|
||||
|
||||
describe('Component Tests', () => {
|
||||
describe('User Management Delete Component', () => {
|
||||
let comp: UserMgmtDeleteDialogComponent;
|
||||
let fixture: ComponentFixture<UserMgmtDeleteDialogComponent>;
|
||||
let service: UserService;
|
||||
let mockEventManager: any;
|
||||
let mockActiveModal: any;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [HsadminNgTestModule],
|
||||
declarations: [UserMgmtDeleteDialogComponent]
|
||||
})
|
||||
.overrideTemplate(UserMgmtDeleteDialogComponent, '')
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(UserMgmtDeleteDialogComponent);
|
||||
comp = fixture.componentInstance;
|
||||
service = fixture.debugElement.injector.get(UserService);
|
||||
mockEventManager = fixture.debugElement.injector.get(JhiEventManager);
|
||||
mockActiveModal = fixture.debugElement.injector.get(NgbActiveModal);
|
||||
});
|
||||
|
||||
describe('confirmDelete', () => {
|
||||
it('Should call delete service on confirmDelete', inject(
|
||||
[],
|
||||
fakeAsync(() => {
|
||||
// GIVEN
|
||||
spyOn(service, 'delete').and.returnValue(of({}));
|
||||
|
||||
// WHEN
|
||||
comp.confirmDelete('user');
|
||||
tick();
|
||||
|
||||
// THEN
|
||||
expect(service.delete).toHaveBeenCalledWith('user');
|
||||
expect(mockActiveModal.dismissSpy).toHaveBeenCalled();
|
||||
expect(mockEventManager.broadcastSpy).toHaveBeenCalled();
|
||||
})
|
||||
));
|
||||
});
|
||||
});
|
||||
});
|
65
src/test/javascript/spec/app/admin/user-management/user-management-detail.component.spec.ts
Normal file
65
src/test/javascript/spec/app/admin/user-management/user-management-detail.component.spec.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { of } from 'rxjs';
|
||||
|
||||
import { HsadminNgTestModule } from '../../../test.module';
|
||||
import { UserMgmtDetailComponent } from 'app/admin/user-management/user-management-detail.component';
|
||||
import { User } from 'app/core';
|
||||
|
||||
describe('Component Tests', () => {
|
||||
describe('User Management Detail Component', () => {
|
||||
let comp: UserMgmtDetailComponent;
|
||||
let fixture: ComponentFixture<UserMgmtDetailComponent>;
|
||||
const route = ({
|
||||
data: of({ user: new User(1, 'user', 'first', 'last', 'first@last.com', true, 'en', ['ROLE_USER'], 'admin', null, null, null) })
|
||||
} as any) as ActivatedRoute;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [HsadminNgTestModule],
|
||||
declarations: [UserMgmtDetailComponent],
|
||||
providers: [
|
||||
{
|
||||
provide: ActivatedRoute,
|
||||
useValue: route
|
||||
}
|
||||
]
|
||||
})
|
||||
.overrideTemplate(UserMgmtDetailComponent, '')
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(UserMgmtDetailComponent);
|
||||
comp = fixture.componentInstance;
|
||||
});
|
||||
|
||||
describe('OnInit', () => {
|
||||
it('Should call load all on init', () => {
|
||||
// GIVEN
|
||||
|
||||
// WHEN
|
||||
comp.ngOnInit();
|
||||
|
||||
// THEN
|
||||
expect(comp.user).toEqual(
|
||||
jasmine.objectContaining({
|
||||
id: 1,
|
||||
login: 'user',
|
||||
firstName: 'first',
|
||||
lastName: 'last',
|
||||
email: 'first@last.com',
|
||||
activated: true,
|
||||
langKey: 'en',
|
||||
authorities: ['ROLE_USER'],
|
||||
createdBy: 'admin',
|
||||
createdDate: null,
|
||||
lastModifiedBy: null,
|
||||
lastModifiedDate: null,
|
||||
password: null
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
102
src/test/javascript/spec/app/admin/user-management/user-management-update.component.spec.ts
Normal file
102
src/test/javascript/spec/app/admin/user-management/user-management-update.component.spec.ts
Normal file
@@ -0,0 +1,102 @@
|
||||
import { ComponentFixture, TestBed, async, inject, fakeAsync, tick } from '@angular/core/testing';
|
||||
import { HttpResponse } from '@angular/common/http';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { Observable, of } from 'rxjs';
|
||||
|
||||
import { HsadminNgTestModule } from '../../../test.module';
|
||||
import { UserMgmtUpdateComponent } from 'app/admin/user-management/user-management-update.component';
|
||||
import { UserService, User, JhiLanguageHelper } from 'app/core';
|
||||
|
||||
describe('Component Tests', () => {
|
||||
describe('User Management Update Component', () => {
|
||||
let comp: UserMgmtUpdateComponent;
|
||||
let fixture: ComponentFixture<UserMgmtUpdateComponent>;
|
||||
let service: UserService;
|
||||
let mockLanguageHelper: any;
|
||||
const route = ({
|
||||
data: of({ user: new User(1, 'user', 'first', 'last', 'first@last.com', true, 'en', ['ROLE_USER'], 'admin', null, null, null) })
|
||||
} as any) as ActivatedRoute;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [HsadminNgTestModule],
|
||||
declarations: [UserMgmtUpdateComponent],
|
||||
providers: [
|
||||
{
|
||||
provide: ActivatedRoute,
|
||||
useValue: route
|
||||
}
|
||||
]
|
||||
})
|
||||
.overrideTemplate(UserMgmtUpdateComponent, '')
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(UserMgmtUpdateComponent);
|
||||
comp = fixture.componentInstance;
|
||||
service = fixture.debugElement.injector.get(UserService);
|
||||
mockLanguageHelper = fixture.debugElement.injector.get(JhiLanguageHelper);
|
||||
});
|
||||
|
||||
describe('OnInit', () => {
|
||||
it('Should load authorities and language on init', inject(
|
||||
[],
|
||||
fakeAsync(() => {
|
||||
// GIVEN
|
||||
spyOn(service, 'authorities').and.returnValue(of(['USER']));
|
||||
|
||||
// WHEN
|
||||
comp.ngOnInit();
|
||||
|
||||
// THEN
|
||||
expect(service.authorities).toHaveBeenCalled();
|
||||
expect(comp.authorities).toEqual(['USER']);
|
||||
expect(mockLanguageHelper.getAllSpy).toHaveBeenCalled();
|
||||
})
|
||||
));
|
||||
});
|
||||
|
||||
describe('save', () => {
|
||||
it('Should call update service on save for existing user', inject(
|
||||
[],
|
||||
fakeAsync(() => {
|
||||
// GIVEN
|
||||
const entity = new User(123);
|
||||
spyOn(service, 'update').and.returnValue(
|
||||
of(
|
||||
new HttpResponse({
|
||||
body: entity
|
||||
})
|
||||
)
|
||||
);
|
||||
comp.user = entity;
|
||||
// WHEN
|
||||
comp.save();
|
||||
tick(); // simulate async
|
||||
|
||||
// THEN
|
||||
expect(service.update).toHaveBeenCalledWith(entity);
|
||||
expect(comp.isSaving).toEqual(false);
|
||||
})
|
||||
));
|
||||
|
||||
it('Should call create service on save for new user', inject(
|
||||
[],
|
||||
fakeAsync(() => {
|
||||
// GIVEN
|
||||
const entity = new User();
|
||||
spyOn(service, 'create').and.returnValue(of(new HttpResponse({ body: entity })));
|
||||
comp.user = entity;
|
||||
// WHEN
|
||||
comp.save();
|
||||
tick(); // simulate async
|
||||
|
||||
// THEN
|
||||
expect(service.create).toHaveBeenCalledWith(entity);
|
||||
expect(comp.isSaving).toEqual(false);
|
||||
})
|
||||
));
|
||||
});
|
||||
});
|
||||
});
|
@@ -0,0 +1,85 @@
|
||||
import { ComponentFixture, TestBed, async, inject, fakeAsync, tick } from '@angular/core/testing';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { HttpHeaders, HttpResponse } from '@angular/common/http';
|
||||
|
||||
import { HsadminNgTestModule } from '../../../test.module';
|
||||
import { UserMgmtComponent } from 'app/admin/user-management/user-management.component';
|
||||
import { UserService, User } from 'app/core';
|
||||
|
||||
describe('Component Tests', () => {
|
||||
describe('User Management Component', () => {
|
||||
let comp: UserMgmtComponent;
|
||||
let fixture: ComponentFixture<UserMgmtComponent>;
|
||||
let service: UserService;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [HsadminNgTestModule],
|
||||
declarations: [UserMgmtComponent]
|
||||
})
|
||||
.overrideTemplate(UserMgmtComponent, '')
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(UserMgmtComponent);
|
||||
comp = fixture.componentInstance;
|
||||
service = fixture.debugElement.injector.get(UserService);
|
||||
});
|
||||
|
||||
describe('OnInit', () => {
|
||||
it('Should call load all on init', inject(
|
||||
[],
|
||||
fakeAsync(() => {
|
||||
// GIVEN
|
||||
const headers = new HttpHeaders().append('link', 'link;link');
|
||||
spyOn(service, 'query').and.returnValue(
|
||||
of(
|
||||
new HttpResponse({
|
||||
body: [new User(123)],
|
||||
headers
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
// WHEN
|
||||
comp.ngOnInit();
|
||||
tick(); // simulate async
|
||||
|
||||
// THEN
|
||||
expect(service.query).toHaveBeenCalled();
|
||||
expect(comp.users[0]).toEqual(jasmine.objectContaining({ id: 123 }));
|
||||
})
|
||||
));
|
||||
});
|
||||
|
||||
describe('setActive', () => {
|
||||
it('Should update user and call load all', inject(
|
||||
[],
|
||||
fakeAsync(() => {
|
||||
// GIVEN
|
||||
const headers = new HttpHeaders().append('link', 'link;link');
|
||||
const user = new User(123);
|
||||
spyOn(service, 'query').and.returnValue(
|
||||
of(
|
||||
new HttpResponse({
|
||||
body: [user],
|
||||
headers
|
||||
})
|
||||
)
|
||||
);
|
||||
spyOn(service, 'update').and.returnValue(of(new HttpResponse({ status: 200 })));
|
||||
|
||||
// WHEN
|
||||
comp.setActive(user, true);
|
||||
tick(); // simulate async
|
||||
|
||||
// THEN
|
||||
expect(service.update).toHaveBeenCalledWith(user);
|
||||
expect(service.query).toHaveBeenCalled();
|
||||
expect(comp.users[0]).toEqual(jasmine.objectContaining({ id: 123 }));
|
||||
})
|
||||
));
|
||||
});
|
||||
});
|
||||
});
|
110
src/test/javascript/spec/app/core/user/account.service.spec.ts
Normal file
110
src/test/javascript/spec/app/core/user/account.service.spec.ts
Normal file
@@ -0,0 +1,110 @@
|
||||
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { SERVER_API_URL } from 'app/app.constants';
|
||||
import { AccountService } from 'app/core';
|
||||
import { JhiDateUtils, JhiLanguageService } from 'ng-jhipster';
|
||||
import { SessionStorageService } from 'ngx-webstorage';
|
||||
import { MockLanguageService } from '../../../helpers/mock-language.service';
|
||||
|
||||
describe('Service Tests', () => {
|
||||
describe('Account Service', () => {
|
||||
let service: AccountService;
|
||||
let httpMock;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [HttpClientTestingModule],
|
||||
providers: [
|
||||
JhiDateUtils,
|
||||
SessionStorageService,
|
||||
{
|
||||
provide: JhiLanguageService,
|
||||
useClass: MockLanguageService
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
service = TestBed.get(AccountService);
|
||||
httpMock = TestBed.get(HttpTestingController);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
httpMock.verify();
|
||||
});
|
||||
|
||||
describe('Service methods', () => {
|
||||
it('should call /account if user is undefined', () => {
|
||||
service.identity().then(() => {});
|
||||
const req = httpMock.expectOne({ method: 'GET' });
|
||||
const resourceUrl = SERVER_API_URL + 'api/account';
|
||||
|
||||
expect(req.request.url).toEqual(`${resourceUrl}`);
|
||||
});
|
||||
|
||||
it('should call /account only once', () => {
|
||||
service.identity().then(() => service.identity().then(() => {}));
|
||||
const req = httpMock.expectOne({ method: 'GET' });
|
||||
const resourceUrl = SERVER_API_URL + 'api/account';
|
||||
|
||||
expect(req.request.url).toEqual(`${resourceUrl}`);
|
||||
req.flush({
|
||||
firstName: 'John'
|
||||
});
|
||||
});
|
||||
|
||||
describe('hasAuthority', () => {
|
||||
it('should return false if user is not logged', async () => {
|
||||
const hasAuthority = await service.hasAuthority('ROLE_USER');
|
||||
expect(hasAuthority).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should return false if user is logged and has not authority', async () => {
|
||||
service.authenticate({
|
||||
authorities: ['ROLE_USER']
|
||||
});
|
||||
|
||||
const hasAuthority = await service.hasAuthority('ROLE_ADMIN');
|
||||
|
||||
expect(hasAuthority).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should return true if user is logged and has authority', async () => {
|
||||
service.authenticate({
|
||||
authorities: ['ROLE_USER']
|
||||
});
|
||||
|
||||
const hasAuthority = await service.hasAuthority('ROLE_USER');
|
||||
|
||||
expect(hasAuthority).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('hasAnyAuthority', () => {
|
||||
it('should return false if user is not logged', async () => {
|
||||
const hasAuthority = await service.hasAnyAuthority(['ROLE_USER']);
|
||||
expect(hasAuthority).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should return false if user is logged and has not authority', async () => {
|
||||
service.authenticate({
|
||||
authorities: ['ROLE_USER']
|
||||
});
|
||||
|
||||
const hasAuthority = await service.hasAnyAuthority(['ROLE_ADMIN']);
|
||||
|
||||
expect(hasAuthority).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should return true if user is logged and has authority', async () => {
|
||||
service.authenticate({
|
||||
authorities: ['ROLE_USER']
|
||||
});
|
||||
|
||||
const hasAuthority = await service.hasAnyAuthority(['ROLE_USER', 'ROLE_ADMIN']);
|
||||
|
||||
expect(hasAuthority).toBeTruthy();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
66
src/test/javascript/spec/app/core/user/user.service.spec.ts
Normal file
66
src/test/javascript/spec/app/core/user/user.service.spec.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { JhiDateUtils } from 'ng-jhipster';
|
||||
|
||||
import { UserService, User } from 'app/core';
|
||||
import { SERVER_API_URL } from 'app/app.constants';
|
||||
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
|
||||
|
||||
describe('Service Tests', () => {
|
||||
describe('User Service', () => {
|
||||
let service: UserService;
|
||||
let httpMock;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [HttpClientTestingModule],
|
||||
providers: [JhiDateUtils]
|
||||
});
|
||||
|
||||
service = TestBed.get(UserService);
|
||||
httpMock = TestBed.get(HttpTestingController);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
httpMock.verify();
|
||||
});
|
||||
|
||||
describe('Service methods', () => {
|
||||
it('should call correct URL', () => {
|
||||
service.find('user').subscribe(() => {});
|
||||
|
||||
const req = httpMock.expectOne({ method: 'GET' });
|
||||
const resourceUrl = SERVER_API_URL + 'api/users';
|
||||
expect(req.request.url).toEqual(`${resourceUrl}/user`);
|
||||
});
|
||||
it('should return User', () => {
|
||||
service.find('user').subscribe(received => {
|
||||
expect(received.body.login).toEqual('user');
|
||||
});
|
||||
|
||||
const req = httpMock.expectOne({ method: 'GET' });
|
||||
req.flush(new User(1, 'user'));
|
||||
});
|
||||
|
||||
it('should return Authorities', () => {
|
||||
service.authorities().subscribe(_authorities => {
|
||||
expect(_authorities).toEqual(['ROLE_USER', 'ROLE_ADMIN']);
|
||||
});
|
||||
const req = httpMock.expectOne({ method: 'GET' });
|
||||
|
||||
req.flush(['ROLE_USER', 'ROLE_ADMIN']);
|
||||
});
|
||||
|
||||
it('should propagate not found response', () => {
|
||||
service.find('user').subscribe(null, (_error: any) => {
|
||||
expect(_error.status).toEqual(404);
|
||||
});
|
||||
|
||||
const req = httpMock.expectOne({ method: 'GET' });
|
||||
req.flush('Invalid request parameters', {
|
||||
status: 404,
|
||||
statusText: 'Bad Request'
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@@ -0,0 +1,135 @@
|
||||
import { ComponentFixture, TestBed, async, inject, fakeAsync, tick } from '@angular/core/testing';
|
||||
import { HttpErrorResponse, HttpHeaders } from '@angular/common/http';
|
||||
import { JhiAlertService, JhiEventManager } from 'ng-jhipster';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
import { HsadminNgTestModule } from '../../../test.module';
|
||||
import { JhiAlertErrorComponent } from 'app/shared/alert/alert-error.component';
|
||||
import { MockAlertService } from '../../../helpers/mock-alert.service';
|
||||
|
||||
describe('Component Tests', () => {
|
||||
describe('Alert Error Component', () => {
|
||||
let comp: JhiAlertErrorComponent;
|
||||
let fixture: ComponentFixture<JhiAlertErrorComponent>;
|
||||
let eventManager: JhiEventManager;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [HsadminNgTestModule, TranslateModule.forRoot()],
|
||||
declarations: [JhiAlertErrorComponent],
|
||||
providers: [
|
||||
JhiEventManager,
|
||||
{
|
||||
provide: JhiAlertService,
|
||||
useClass: MockAlertService
|
||||
}
|
||||
]
|
||||
})
|
||||
.overrideTemplate(JhiAlertErrorComponent, '')
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(JhiAlertErrorComponent);
|
||||
comp = fixture.componentInstance;
|
||||
eventManager = fixture.debugElement.injector.get(JhiEventManager);
|
||||
});
|
||||
|
||||
describe('Error Handling', () => {
|
||||
it('Should display an alert on status 0', () => {
|
||||
// GIVEN
|
||||
eventManager.broadcast({ name: 'hsadminNgApp.httpError', content: { status: 0 } });
|
||||
// THEN
|
||||
expect(comp.alerts.length).toBe(1);
|
||||
expect(comp.alerts[0].msg).toBe('error.server.not.reachable');
|
||||
});
|
||||
it('Should display an alert on status 404', () => {
|
||||
// GIVEN
|
||||
eventManager.broadcast({ name: 'hsadminNgApp.httpError', content: { status: 404 } });
|
||||
// THEN
|
||||
expect(comp.alerts.length).toBe(1);
|
||||
expect(comp.alerts[0].msg).toBe('error.url.not.found');
|
||||
});
|
||||
it('Should display an alert on generic error', () => {
|
||||
// GIVEN
|
||||
eventManager.broadcast({ name: 'hsadminNgApp.httpError', content: { error: { message: 'Error Message' } } });
|
||||
eventManager.broadcast({ name: 'hsadminNgApp.httpError', content: { error: 'Second Error Message' } });
|
||||
// THEN
|
||||
expect(comp.alerts.length).toBe(2);
|
||||
expect(comp.alerts[0].msg).toBe('Error Message');
|
||||
expect(comp.alerts[1].msg).toBe('Second Error Message');
|
||||
});
|
||||
it('Should display an alert on status 400 for generic error', () => {
|
||||
// GIVEN
|
||||
const response = new HttpErrorResponse({
|
||||
url: 'http://localhost:8080/api/foos',
|
||||
headers: new HttpHeaders(),
|
||||
status: 400,
|
||||
statusText: 'Bad Request',
|
||||
error: {
|
||||
type: 'https://www.jhipster.tech/problem/constraint-violation',
|
||||
title: 'Bad Request',
|
||||
status: 400,
|
||||
path: '/api/foos',
|
||||
message: 'error.validation'
|
||||
}
|
||||
});
|
||||
eventManager.broadcast({ name: 'hsadminNgApp.httpError', content: response });
|
||||
// THEN
|
||||
expect(comp.alerts.length).toBe(1);
|
||||
expect(comp.alerts[0].msg).toBe('error.validation');
|
||||
});
|
||||
it('Should display an alert on status 400 for generic error without message', () => {
|
||||
// GIVEN
|
||||
const response = new HttpErrorResponse({
|
||||
url: 'http://localhost:8080/api/foos',
|
||||
headers: new HttpHeaders(),
|
||||
status: 400,
|
||||
error: 'Bad Request'
|
||||
});
|
||||
eventManager.broadcast({ name: 'hsadminNgApp.httpError', content: response });
|
||||
// THEN
|
||||
expect(comp.alerts.length).toBe(1);
|
||||
expect(comp.alerts[0].msg).toBe('Bad Request');
|
||||
});
|
||||
it('Should display an alert on status 400 for invalid parameters', () => {
|
||||
// GIVEN
|
||||
const response = new HttpErrorResponse({
|
||||
url: 'http://localhost:8080/api/foos',
|
||||
headers: new HttpHeaders(),
|
||||
status: 400,
|
||||
statusText: 'Bad Request',
|
||||
error: {
|
||||
type: 'https://www.jhipster.tech/problem/constraint-violation',
|
||||
title: 'Method argument not valid',
|
||||
status: 400,
|
||||
path: '/api/foos',
|
||||
message: 'error.validation',
|
||||
fieldErrors: [{ objectName: 'foo', field: 'minField', message: 'Min' }]
|
||||
}
|
||||
});
|
||||
eventManager.broadcast({ name: 'hsadminNgApp.httpError', content: response });
|
||||
// THEN
|
||||
expect(comp.alerts.length).toBe(1);
|
||||
expect(comp.alerts[0].msg).toBe('error.Size');
|
||||
});
|
||||
it('Should display an alert on status 400 for error headers', () => {
|
||||
// GIVEN
|
||||
const response = new HttpErrorResponse({
|
||||
url: 'http://localhost:8080/api/foos',
|
||||
headers: new HttpHeaders().append('app-error', 'Error Message').append('app-params', 'foo'),
|
||||
status: 400,
|
||||
statusText: 'Bad Request',
|
||||
error: {
|
||||
status: 400,
|
||||
message: 'error.validation'
|
||||
}
|
||||
});
|
||||
eventManager.broadcast({ name: 'hsadminNgApp.httpError', content: response });
|
||||
// THEN
|
||||
expect(comp.alerts.length).toBe(1);
|
||||
expect(comp.alerts[0].msg).toBe('Error Message');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@@ -0,0 +1,157 @@
|
||||
import { ComponentFixture, TestBed, async, inject, fakeAsync, tick } from '@angular/core/testing';
|
||||
import { Router } from '@angular/router';
|
||||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
|
||||
import { JhiEventManager } from 'ng-jhipster';
|
||||
|
||||
import { LoginService } from 'app/core/login/login.service';
|
||||
import { JhiLoginModalComponent } from 'app/shared/login/login.component';
|
||||
import { StateStorageService } from 'app/core/auth/state-storage.service';
|
||||
import { HsadminNgTestModule } from '../../../test.module';
|
||||
import { MockLoginService } from '../../../helpers/mock-login.service';
|
||||
import { MockStateStorageService } from '../../../helpers/mock-state-storage.service';
|
||||
|
||||
describe('Component Tests', () => {
|
||||
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: [HsadminNgTestModule],
|
||||
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();
|
||||
})
|
||||
));
|
||||
|
||||
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');
|
||||
});
|
||||
|
||||
it('should redirect user when register', () => {
|
||||
// WHEN
|
||||
comp.register();
|
||||
|
||||
// THEN
|
||||
expect(mockActiveModal.dismissSpy).toHaveBeenCalledWith('to state register');
|
||||
expect(mockRouter.navigateSpy).toHaveBeenCalledWith(['/register']);
|
||||
});
|
||||
|
||||
it('should redirect user when request password', () => {
|
||||
// WHEN
|
||||
comp.requestResetPassword();
|
||||
|
||||
// THEN
|
||||
expect(mockActiveModal.dismissSpy).toHaveBeenCalledWith('to state requestReset');
|
||||
expect(mockRouter.navigateSpy).toHaveBeenCalledWith(['/reset', 'request']);
|
||||
});
|
||||
});
|
||||
});
|
35
src/test/javascript/spec/helpers/mock-account.service.ts
Normal file
35
src/test/javascript/spec/helpers/mock-account.service.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { SpyObject } from './spyobject';
|
||||
import { AccountService } from 'app/core/auth/account.service';
|
||||
import Spy = jasmine.Spy;
|
||||
|
||||
export class MockAccountService extends SpyObject {
|
||||
getSpy: Spy;
|
||||
saveSpy: Spy;
|
||||
fakeResponse: any;
|
||||
identitySpy: Spy;
|
||||
|
||||
constructor() {
|
||||
super(AccountService);
|
||||
|
||||
this.fakeResponse = null;
|
||||
this.getSpy = this.spy('get').andReturn(this);
|
||||
this.saveSpy = this.spy('save').andReturn(this);
|
||||
this.setIdentitySpy({});
|
||||
}
|
||||
|
||||
subscribe(callback: any) {
|
||||
callback(this.fakeResponse);
|
||||
}
|
||||
|
||||
setResponse(json: any): void {
|
||||
this.fakeResponse = json;
|
||||
}
|
||||
|
||||
setIdentitySpy(json: any): any {
|
||||
this.identitySpy = this.spy('identity').andReturn(Promise.resolve(json));
|
||||
}
|
||||
|
||||
setIdentityResponse(json: any): void {
|
||||
this.setIdentitySpy(json);
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
import { SpyObject } from './spyobject';
|
||||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
|
||||
import Spy = jasmine.Spy;
|
||||
|
||||
export class MockActiveModal extends SpyObject {
|
||||
dismissSpy: Spy;
|
||||
|
||||
constructor() {
|
||||
super(NgbActiveModal);
|
||||
this.dismissSpy = this.spy('dismiss').andReturn(this);
|
||||
}
|
||||
}
|
11
src/test/javascript/spec/helpers/mock-alert.service.ts
Normal file
11
src/test/javascript/spec/helpers/mock-alert.service.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { SpyObject } from './spyobject';
|
||||
import { JhiAlertService, JhiAlert } from 'ng-jhipster';
|
||||
|
||||
export class MockAlertService extends SpyObject {
|
||||
constructor() {
|
||||
super(JhiAlertService);
|
||||
}
|
||||
addAlert(alertOptions: JhiAlert) {
|
||||
return alertOptions;
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
import { SpyObject } from './spyobject';
|
||||
import { JhiEventManager } from 'ng-jhipster';
|
||||
import Spy = jasmine.Spy;
|
||||
|
||||
export class MockEventManager extends SpyObject {
|
||||
broadcastSpy: Spy;
|
||||
|
||||
constructor() {
|
||||
super(JhiEventManager);
|
||||
this.broadcastSpy = this.spy('broadcast').andReturn(this);
|
||||
}
|
||||
}
|
36
src/test/javascript/spec/helpers/mock-language.service.ts
Normal file
36
src/test/javascript/spec/helpers/mock-language.service.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { SpyObject } from './spyobject';
|
||||
import { JhiLanguageService } from 'ng-jhipster';
|
||||
import { JhiLanguageHelper } from 'app/core/language/language.helper';
|
||||
import Spy = jasmine.Spy;
|
||||
|
||||
export class MockLanguageService extends SpyObject {
|
||||
getCurrentSpy: Spy;
|
||||
fakeResponse: any;
|
||||
|
||||
constructor() {
|
||||
super(JhiLanguageService);
|
||||
|
||||
this.fakeResponse = 'de';
|
||||
this.getCurrentSpy = this.spy('getCurrent').andReturn(Promise.resolve(this.fakeResponse));
|
||||
}
|
||||
|
||||
init() {}
|
||||
|
||||
changeLanguage(languageKey: string) {}
|
||||
|
||||
setLocations(locations: string[]) {}
|
||||
|
||||
addLocation(location: string) {}
|
||||
|
||||
reload() {}
|
||||
}
|
||||
|
||||
export class MockLanguageHelper extends SpyObject {
|
||||
getAllSpy: Spy;
|
||||
|
||||
constructor() {
|
||||
super(JhiLanguageHelper);
|
||||
|
||||
this.getAllSpy = this.spy('getAll').andReturn(Promise.resolve(['en', 'fr']));
|
||||
}
|
||||
}
|
29
src/test/javascript/spec/helpers/mock-login.service.ts
Normal file
29
src/test/javascript/spec/helpers/mock-login.service.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { SpyObject } from './spyobject';
|
||||
import { LoginService } from 'app/core/login/login.service';
|
||||
import Spy = jasmine.Spy;
|
||||
|
||||
export class MockLoginService extends SpyObject {
|
||||
loginSpy: Spy;
|
||||
logoutSpy: Spy;
|
||||
registerSpy: Spy;
|
||||
requestResetPasswordSpy: Spy;
|
||||
cancelSpy: Spy;
|
||||
|
||||
constructor() {
|
||||
super(LoginService);
|
||||
|
||||
this.setLoginSpy({});
|
||||
this.logoutSpy = this.spy('logout').andReturn(this);
|
||||
this.registerSpy = this.spy('register').andReturn(this);
|
||||
this.requestResetPasswordSpy = this.spy('requestResetPassword').andReturn(this);
|
||||
this.cancelSpy = this.spy('cancel').andReturn(this);
|
||||
}
|
||||
|
||||
setLoginSpy(json: any) {
|
||||
this.loginSpy = this.spy('login').andReturn(Promise.resolve(json));
|
||||
}
|
||||
|
||||
setResponse(json: any): void {
|
||||
this.setLoginSpy(json);
|
||||
}
|
||||
}
|
29
src/test/javascript/spec/helpers/mock-route.service.ts
Normal file
29
src/test/javascript/spec/helpers/mock-route.service.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { SpyObject } from './spyobject';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import Spy = jasmine.Spy;
|
||||
|
||||
export class MockActivatedRoute extends ActivatedRoute {
|
||||
constructor(parameters?: any) {
|
||||
super();
|
||||
this.queryParams = of(parameters);
|
||||
this.params = of(parameters);
|
||||
this.data = of({
|
||||
...parameters,
|
||||
pagingParams: {
|
||||
page: 10,
|
||||
ascending: false,
|
||||
predicate: 'id'
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export class MockRouter extends SpyObject {
|
||||
navigateSpy: Spy;
|
||||
|
||||
constructor() {
|
||||
super(Router);
|
||||
this.navigateSpy = this.spy('navigate');
|
||||
}
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
import { SpyObject } from './spyobject';
|
||||
import { StateStorageService } from 'app/core/auth/state-storage.service';
|
||||
import Spy = jasmine.Spy;
|
||||
|
||||
export class MockStateStorageService extends SpyObject {
|
||||
getUrlSpy: Spy;
|
||||
storeUrlSpy: Spy;
|
||||
|
||||
constructor() {
|
||||
super(StateStorageService);
|
||||
this.setUrlSpy({});
|
||||
this.storeUrlSpy = this.spy('storeUrl').andReturn(this);
|
||||
}
|
||||
|
||||
setUrlSpy(json) {
|
||||
this.getUrlSpy = this.spy('getUrl').andReturn(json);
|
||||
}
|
||||
|
||||
setResponse(json: any): void {
|
||||
this.setUrlSpy(json);
|
||||
}
|
||||
}
|
69
src/test/javascript/spec/helpers/spyobject.ts
Normal file
69
src/test/javascript/spec/helpers/spyobject.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
export interface GuinessCompatibleSpy extends jasmine.Spy {
|
||||
/** By chaining the spy with and.returnValue, all calls to the function will return a specific
|
||||
* value. */
|
||||
andReturn(val: any): void;
|
||||
/** By chaining the spy with and.callFake, all calls to the spy will delegate to the supplied
|
||||
* function. */
|
||||
andCallFake(fn: Function): GuinessCompatibleSpy;
|
||||
/** removes all recorded calls */
|
||||
reset();
|
||||
}
|
||||
|
||||
export class SpyObject {
|
||||
static stub(object = null, config = null, overrides = null) {
|
||||
if (!(object instanceof SpyObject)) {
|
||||
overrides = config;
|
||||
config = object;
|
||||
object = new SpyObject();
|
||||
}
|
||||
|
||||
const m = {};
|
||||
Object.keys(config).forEach(key => (m[key] = config[key]));
|
||||
Object.keys(overrides).forEach(key => (m[key] = overrides[key]));
|
||||
Object.keys(m).forEach(key => {
|
||||
object.spy(key).andReturn(m[key]);
|
||||
});
|
||||
return object;
|
||||
}
|
||||
|
||||
constructor(type = null) {
|
||||
if (type) {
|
||||
Object.keys(type.prototype).forEach(prop => {
|
||||
let m = null;
|
||||
try {
|
||||
m = type.prototype[prop];
|
||||
} catch (e) {
|
||||
// As we are creating spys for abstract classes,
|
||||
// these classes might have getters that throw when they are accessed.
|
||||
// As we are only auto creating spys for methods, this
|
||||
// should not matter.
|
||||
}
|
||||
if (typeof m === 'function') {
|
||||
this.spy(prop);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
spy(name) {
|
||||
if (!this[name]) {
|
||||
this[name] = this._createGuinnessCompatibleSpy(name);
|
||||
}
|
||||
return this[name];
|
||||
}
|
||||
|
||||
prop(name, value) {
|
||||
this[name] = value;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
_createGuinnessCompatibleSpy(name): GuinessCompatibleSpy {
|
||||
const newSpy: GuinessCompatibleSpy = <any>jasmine.createSpy(name);
|
||||
newSpy.andCallFake = <any>newSpy.and.callFake;
|
||||
newSpy.andReturn = <any>newSpy.and.returnValue;
|
||||
newSpy.reset = <any>newSpy.calls.reset;
|
||||
// revisit return null here (previously needed for rtts_assert).
|
||||
newSpy.and.returnValue(null);
|
||||
return newSpy;
|
||||
}
|
||||
}
|
72
src/test/javascript/spec/test.module.ts
Normal file
72
src/test/javascript/spec/test.module.ts
Normal file
@@ -0,0 +1,72 @@
|
||||
import { DatePipe } from '@angular/common';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { NgModule, ElementRef, Renderer } from '@angular/core';
|
||||
import { HttpClientTestingModule } from '@angular/common/http/testing';
|
||||
import { NgbActiveModal, NgbModal } from '@ng-bootstrap/ng-bootstrap';
|
||||
import { JhiLanguageService, JhiDataUtils, JhiDateUtils, JhiEventManager, JhiAlertService, JhiParseLinks } from 'ng-jhipster';
|
||||
|
||||
import { MockLanguageService, MockLanguageHelper } from './helpers/mock-language.service';
|
||||
import { JhiLanguageHelper, AccountService, LoginModalService } from 'app/core';
|
||||
import { MockAccountService } from './helpers/mock-account.service';
|
||||
import { MockActivatedRoute, MockRouter } from './helpers/mock-route.service';
|
||||
import { MockActiveModal } from './helpers/mock-active-modal.service';
|
||||
import { MockEventManager } from './helpers/mock-event-manager.service';
|
||||
|
||||
@NgModule({
|
||||
providers: [
|
||||
DatePipe,
|
||||
JhiDataUtils,
|
||||
JhiDateUtils,
|
||||
JhiParseLinks,
|
||||
{
|
||||
provide: JhiLanguageService,
|
||||
useClass: MockLanguageService
|
||||
},
|
||||
{
|
||||
provide: JhiLanguageHelper,
|
||||
useClass: MockLanguageHelper
|
||||
},
|
||||
{
|
||||
provide: JhiEventManager,
|
||||
useClass: MockEventManager
|
||||
},
|
||||
{
|
||||
provide: NgbActiveModal,
|
||||
useClass: MockActiveModal
|
||||
},
|
||||
{
|
||||
provide: ActivatedRoute,
|
||||
useValue: new MockActivatedRoute({ id: 123 })
|
||||
},
|
||||
{
|
||||
provide: Router,
|
||||
useClass: MockRouter
|
||||
},
|
||||
{
|
||||
provide: AccountService,
|
||||
useClass: MockAccountService
|
||||
},
|
||||
{
|
||||
provide: LoginModalService,
|
||||
useValue: null
|
||||
},
|
||||
{
|
||||
provide: ElementRef,
|
||||
useValue: null
|
||||
},
|
||||
{
|
||||
provide: Renderer,
|
||||
useValue: null
|
||||
},
|
||||
{
|
||||
provide: JhiAlertService,
|
||||
useValue: null
|
||||
},
|
||||
{
|
||||
provide: NgbModal,
|
||||
useValue: null
|
||||
}
|
||||
],
|
||||
imports: [HttpClientTestingModule]
|
||||
})
|
||||
export class HsadminNgTestModule {}
|
Reference in New Issue
Block a user