1
0
Files
yel-dspace-angular/src/app/profile-page/profile-page.component.spec.ts
Kristof De Langhe 20f8f913cf 69432: Tests
2020-03-12 10:18:49 +01:00

130 lines
4.5 KiB
TypeScript

import { ProfilePageComponent } from './profile-page.component';
import { async, ComponentFixture, inject, TestBed } from '@angular/core/testing';
import { VarDirective } from '../shared/utils/var.directive';
import { TranslateModule } from '@ngx-translate/core';
import { RouterTestingModule } from '@angular/router/testing';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { EPerson } from '../core/eperson/models/eperson.model';
import { createPaginatedList, createSuccessfulRemoteDataObject$ } from '../shared/testing/utils';
import { Store, StoreModule } from '@ngrx/store';
import { AppState } from '../app.reducer';
import { AuthTokenInfo } from '../core/auth/models/auth-token-info.model';
import { EPersonDataService } from '../core/eperson/eperson-data.service';
import { NotificationsService } from '../shared/notifications/notifications.service';
import { authReducer } from '../core/auth/auth.reducer';
describe('ProfilePageComponent', () => {
let component: ProfilePageComponent;
let fixture: ComponentFixture<ProfilePageComponent>;
const user = Object.assign(new EPerson(), {
groups: createSuccessfulRemoteDataObject$(createPaginatedList([]))
});
const authState = {
authenticated: true,
loaded: true,
loading: false,
authToken: new AuthTokenInfo('test_token'),
user: user
};
const epersonService = jasmine.createSpyObj('epersonService', {
findById: createSuccessfulRemoteDataObject$(user)
});
const notificationsService = jasmine.createSpyObj('notificationsService', {
success: {},
error: {},
warning: {}
});
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ProfilePageComponent, VarDirective],
imports: [StoreModule.forRoot(authReducer), TranslateModule.forRoot(), RouterTestingModule.withRoutes([])],
providers: [
{ provide: EPersonDataService, useValue: epersonService },
{ provide: NotificationsService, useValue: notificationsService }
],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();
}));
beforeEach(inject([Store], (store: Store<AppState>) => {
store
.subscribe((state) => {
(state as any).core = Object.create({});
(state as any).core.auth = authState;
});
fixture = TestBed.createComponent(ProfilePageComponent);
component = fixture.componentInstance;
fixture.detectChanges();
}));
describe('updateProfile', () => {
describe('when the metadata form returns false and the security form returns true', () => {
beforeEach(() => {
component.metadataForm = jasmine.createSpyObj('metadataForm', {
updateProfile: false
});
component.securityForm = jasmine.createSpyObj('securityForm', {
updateSecurity: true
});
component.updateProfile();
});
it('should not display a warning', () => {
expect(notificationsService.warning).not.toHaveBeenCalled();
});
});
describe('when the metadata form returns true and the security form returns false', () => {
beforeEach(() => {
component.metadataForm = jasmine.createSpyObj('metadataForm', {
updateProfile: true
});
component.securityForm = jasmine.createSpyObj('securityForm', {
updateSecurity: false
});
component.updateProfile();
});
it('should not display a warning', () => {
expect(notificationsService.warning).not.toHaveBeenCalled();
});
});
describe('when the metadata form returns true and the security form returns true', () => {
beforeEach(() => {
component.metadataForm = jasmine.createSpyObj('metadataForm', {
updateProfile: true
});
component.securityForm = jasmine.createSpyObj('securityForm', {
updateSecurity: true
});
component.updateProfile();
});
it('should not display a warning', () => {
expect(notificationsService.warning).not.toHaveBeenCalled();
});
});
describe('when the metadata form returns false and the security form returns false', () => {
beforeEach(() => {
component.metadataForm = jasmine.createSpyObj('metadataForm', {
updateProfile: false
});
component.securityForm = jasmine.createSpyObj('securityForm', {
updateSecurity: false
});
component.updateProfile();
});
it('should display a warning', () => {
expect(notificationsService.warning).toHaveBeenCalled();
});
});
});
});