-
Kristof De Langhe authoredd9e6d25d
profile-page-security-form.component.spec.ts 3.34 KiB
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { EPerson } from '../../core/eperson/models/eperson.model';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { VarDirective } from '../../shared/utils/var.directive';
import { TranslateModule } from '@ngx-translate/core';
import { RouterTestingModule } from '@angular/router/testing';
import { EPersonDataService } from '../../core/eperson/eperson-data.service';
import { NotificationsService } from '../../shared/notifications/notifications.service';
import { FormBuilderService } from '../../shared/form/builder/form-builder.service';
import { ProfilePageSecurityFormComponent } from './profile-page-security-form.component';
describe('ProfilePageSecurityFormComponent', () => {
let component: ProfilePageSecurityFormComponent;
let fixture: ComponentFixture<ProfilePageSecurityFormComponent>;
const user = Object.assign(new EPerson(), {
_links: {
self: { href: 'user-selflink' }
}
});
const epersonService = jasmine.createSpyObj('epersonService', {
patch: {}
});
const notificationsService = jasmine.createSpyObj('notificationsService', {
success: {},
error: {},
warning: {}
});
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ProfilePageSecurityFormComponent, VarDirective],
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([])],
providers: [
{ provide: EPersonDataService, useValue: epersonService },
{ provide: NotificationsService, useValue: notificationsService },
FormBuilderService
],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ProfilePageSecurityFormComponent);
component = fixture.componentInstance;
component.user = user;
fixture.detectChanges();
});
describe('updateSecurity', () => {
describe('when no values changed', () => {
let result;
beforeEach(() => {
result = component.updateSecurity();
});
it('should return false', () => {
expect(result).toEqual(false);
});
it('should not call epersonService.patch', () => {
expect(epersonService.patch).not.toHaveBeenCalled();
});
});
describe('when password is filled in, but the confirm field is empty', () => {
let result;