101289: intermediate commit for test issues

This commit is contained in:
lotte
2023-06-08 14:16:04 +02:00
parent d69adab419
commit 56cba82c2d
2 changed files with 91 additions and 80 deletions

View File

@@ -24,8 +24,7 @@ import { createPaginatedList } from '../../shared/testing/utils.test';
import { Item } from '../../core/shared/item.model'; import { Item } from '../../core/shared/item.model';
import { MetadataValueFilter } from '../../core/shared/metadata.models'; import { MetadataValueFilter } from '../../core/shared/metadata.models';
import { DSONameService } from '../../core/breadcrumbs/dso-name.service'; import { DSONameService } from '../../core/breadcrumbs/dso-name.service';
import { Bundle } from '../../core/shared/bundle.model'; import { PrimaryBitstreamService } from '../../core/data/primary-bitstream-data.service';
import { BundleDataService } from '../../core/data/bundle-data.service';
const infoNotification: INotification = new Notification('id', NotificationType.Info, 'info'); const infoNotification: INotification = new Notification('id', NotificationType.Info, 'info');
const warningNotification: INotification = new Notification('id', NotificationType.Warning, 'warning'); const warningNotification: INotification = new Notification('id', NotificationType.Warning, 'warning');
@@ -34,6 +33,7 @@ const successNotification: INotification = new Notification('id', NotificationTy
let notificationsService: NotificationsService; let notificationsService: NotificationsService;
let formService: DynamicFormService; let formService: DynamicFormService;
let bitstreamService: BitstreamDataService; let bitstreamService: BitstreamDataService;
let primaryBitstreamService: PrimaryBitstreamService;
let bitstreamFormatService: BitstreamFormatDataService; let bitstreamFormatService: BitstreamFormatDataService;
let dsoNameService: DSONameService; let dsoNameService: DSONameService;
let bitstream: Bitstream; let bitstream: Bitstream;
@@ -41,23 +41,19 @@ let bitstreamID: string;
let selectedFormat: BitstreamFormat; let selectedFormat: BitstreamFormat;
let allFormats: BitstreamFormat[]; let allFormats: BitstreamFormat[];
let router: Router; let router: Router;
let bundleDataService; let currentPrimary: string;
let bundleWithCurrentPrimary: Bundle; let differentPrimary: string;
let bundleWithDifferentPrimary: Bundle; let bundle;
let bundleWithNoPrimary: Bundle;
let comp: EditBitstreamPageComponent; let comp: EditBitstreamPageComponent;
let fixture: ComponentFixture<EditBitstreamPageComponent>; let fixture: ComponentFixture<EditBitstreamPageComponent>;
describe('EditBitstreamPageComponent', () => { fdescribe('EditBitstreamPageComponent', () => {
beforeEach(() => { beforeEach(() => {
bitstreamID = 'current-bitstream-id'; bitstreamID = 'current-bitstream-id';
bundleWithCurrentPrimary = Object.assign(new Bundle(), { 'primaryBitstreamUUID': bitstreamID }); currentPrimary = bitstreamID;
bundleWithDifferentPrimary = Object.assign(new Bundle(), { 'primaryBitstreamUUID': '12345-abcde-54321-edcba' }); differentPrimary = '12345-abcde-54321-edcba';
bundleWithNoPrimary = Object.assign(new Bundle(), { 'primaryBitstreamUUID': null });
bundleDataService = jasmine.createSpyObj('BundleDataService', ['patch']);
bundleDataService.patch.and.callFake((a, b) => createSuccessfulRemoteDataObject$(a));
allFormats = [ allFormats = [
Object.assign({ Object.assign({
id: '1', id: '1',
@@ -116,12 +112,47 @@ describe('EditBitstreamPageComponent', () => {
success: successNotification success: successNotification
} }
); );
bundle = {
_links: {
primaryBitstream: {
href: 'bundle-selflink'
}
},
item: createSuccessfulRemoteDataObject$(Object.assign(new Item(), {
uuid: 'some-uuid',
firstMetadataValue(keyOrKeys: string | string[], valueFilter?: MetadataValueFilter): string {
return undefined;
},
}))
};
const result = createSuccessfulRemoteDataObject$(bundle);
primaryBitstreamService = jasmine.createSpyObj('PrimaryBitstreamService',
{
put: result,
create: result,
delete: result,
});
}); });
describe('EditBitstreamPageComponent no IIIF fields', () => { describe('EditBitstreamPageComponent no IIIF fields', () => {
beforeEach(waitForAsync(() => { beforeEach(waitForAsync(() => {
bundle = {
_links: {
primaryBitstream: {
href: 'bundle-selflink'
}
},
item: createSuccessfulRemoteDataObject$(Object.assign(new Item(), {
uuid: 'some-uuid',
firstMetadataValue(keyOrKeys: string | string[], valueFilter?: MetadataValueFilter): string {
return undefined;
},
}))
};
const bundleName = 'ORIGINAL'; const bundleName = 'ORIGINAL';
bitstream = Object.assign(new Bitstream(), { bitstream = Object.assign(new Bitstream(), {
@@ -143,17 +174,11 @@ describe('EditBitstreamPageComponent', () => {
_links: { _links: {
self: 'bitstream-selflink' self: 'bitstream-selflink'
}, },
bundle: createSuccessfulRemoteDataObject$({ bundle: createSuccessfulRemoteDataObject$(bundle)
item: createSuccessfulRemoteDataObject$(Object.assign(new Item(), {
uuid: 'some-uuid',
firstMetadataValue(keyOrKeys: string | string[], valueFilter?: MetadataValueFilter): string {
return undefined;
},
}))
})
}); });
bitstreamService = jasmine.createSpyObj('bitstreamService', { bitstreamService = jasmine.createSpyObj('bitstreamService', {
findById: createSuccessfulRemoteDataObject$(bitstream), findById: createSuccessfulRemoteDataObject$(bitstream),
findByHref: createSuccessfulRemoteDataObject$(bitstream),
update: createSuccessfulRemoteDataObject$(bitstream), update: createSuccessfulRemoteDataObject$(bitstream),
updateFormat: createSuccessfulRemoteDataObject$(bitstream), updateFormat: createSuccessfulRemoteDataObject$(bitstream),
commitUpdates: {}, commitUpdates: {},
@@ -182,7 +207,7 @@ describe('EditBitstreamPageComponent', () => {
{ provide: BitstreamDataService, useValue: bitstreamService }, { provide: BitstreamDataService, useValue: bitstreamService },
{ provide: DSONameService, useValue: dsoNameService }, { provide: DSONameService, useValue: dsoNameService },
{ provide: BitstreamFormatDataService, useValue: bitstreamFormatService }, { provide: BitstreamFormatDataService, useValue: bitstreamFormatService },
{ provide: BundleDataService, useValue: bundleDataService }, { provide: PrimaryBitstreamService, useValue: primaryBitstreamService },
ChangeDetectorRef ChangeDetectorRef
], ],
schemas: [NO_ERRORS_SCHEMA] schemas: [NO_ERRORS_SCHEMA]
@@ -198,7 +223,7 @@ describe('EditBitstreamPageComponent', () => {
spyOn(router, 'navigate'); spyOn(router, 'navigate');
}); });
describe('on startup', () => { fdescribe('on startup', () => {
let rawForm; let rawForm;
beforeEach(() => { beforeEach(() => {
@@ -222,7 +247,7 @@ describe('EditBitstreamPageComponent', () => {
}); });
describe('when the bitstream is the primary bitstream on the bundle', () => { describe('when the bitstream is the primary bitstream on the bundle', () => {
beforeEach(() => { beforeEach(() => {
(comp as any).bundle = bundleWithCurrentPrimary; (comp as any).primaryBitstreamUUID = currentPrimary;
comp.setForm(); comp.setForm();
rawForm = comp.formGroup.getRawValue(); rawForm = comp.formGroup.getRawValue();
@@ -233,7 +258,7 @@ describe('EditBitstreamPageComponent', () => {
}); });
describe('when the bitstream is not the primary bitstream on the bundle', () => { describe('when the bitstream is not the primary bitstream on the bundle', () => {
beforeEach(() => { beforeEach(() => {
(comp as any).bundle = bundleWithDifferentPrimary; (comp as any).primaryBitstreamUUID = differentPrimary;
comp.setForm(); comp.setForm();
rawForm = comp.formGroup.getRawValue(); rawForm = comp.formGroup.getRawValue();
}); });
@@ -263,38 +288,23 @@ describe('EditBitstreamPageComponent', () => {
describe('from a different primary bitstream', () => { describe('from a different primary bitstream', () => {
beforeEach(() => { beforeEach(() => {
(comp as any).bundle = bundleWithDifferentPrimary; (comp as any).primaryBitstreamUUID = differentPrimary;
comp.onSubmit(); comp.onSubmit();
}); });
it('should call patch with a replace operation', () => { it('should call put with the correct bitstream on the PrimaryBitstreamService', () => {
expect(bundleDataService.patch).toHaveBeenCalledWith(bundleWithDifferentPrimary, [jasmine.objectContaining({ expect(primaryBitstreamService.put).toHaveBeenCalledWith(jasmine.objectContaining({uuid: currentPrimary}), bundle);
op: 'replace'
})]);
});
it('should call patch with the correct bitstream uuid', () => {
expect(bundleDataService.patch).toHaveBeenCalledWith(bundleWithDifferentPrimary, [jasmine.objectContaining({
value: bitstreamID
})]);
}); });
}); });
describe('from no primary bitstream', () => { describe('from no primary bitstream', () => {
beforeEach(() => { beforeEach(() => {
(comp as any).bundle = bundleWithNoPrimary; (comp as any).primaryBitstreamUUID = null;
comp.onSubmit(); comp.onSubmit();
}); });
it('should call patch with an add operation', () => { it('should call create with the correct bitstream on the PrimaryBitstreamService', () => {
expect(bundleDataService.patch).toHaveBeenCalledWith(bundleWithNoPrimary, [jasmine.objectContaining({ expect(primaryBitstreamService.create).toHaveBeenCalledWith(jasmine.objectContaining({uuid: currentPrimary}), bundle);
op: 'add'
})]);
});
it('should call patch with the correct bitstream uuid', () => {
expect(bundleDataService.patch).toHaveBeenCalledWith(bundleWithNoPrimary, [jasmine.objectContaining({
value: bitstreamID
})]);
}); });
}); });
}); });
@@ -306,39 +316,42 @@ describe('EditBitstreamPageComponent', () => {
describe('from the current bitstream', () => { describe('from the current bitstream', () => {
beforeEach(() => { beforeEach(() => {
(comp as any).bundle = bundleWithCurrentPrimary; (comp as any).primaryBitstreamUUID = currentPrimary;
comp.onSubmit(); comp.onSubmit();
}); });
it('should call patch with a remove operation', () => { it('should call delete on the PrimaryBitstreamService', () => {
expect(bundleDataService.patch).toHaveBeenCalledWith(bundleWithCurrentPrimary, [jasmine.objectContaining({ expect(primaryBitstreamService.delete).toHaveBeenCalledWith(jasmine.objectContaining(bundle));
op: 'remove'
})]);
}); });
}); });
}); });
}); });
describe('when the primaryBitstream did not changed', () => { describe('when the primaryBitstream did not change', () => {
describe('the current bitstream stayed the primary bitstream', () => { describe('the current bitstream stayed the primary bitstream', () => {
beforeEach(() => { beforeEach(() => {
const rawValue = Object.assign(comp.formGroup.getRawValue(), { fileNamePrimaryContainer: { primaryBitstream: true } }); const rawValue = Object.assign(comp.formGroup.getRawValue(), { fileNamePrimaryContainer: { primaryBitstream: true } });
spyOn(comp.formGroup, 'getRawValue').and.returnValue(rawValue); spyOn(comp.formGroup, 'getRawValue').and.returnValue(rawValue);
(comp as any).bundle = bundleWithCurrentPrimary; (comp as any).primaryBitstreamUUID = currentPrimary;
comp.onSubmit(); comp.onSubmit();
}); });
it('should not call patch on the bundle data service', () => { it('should not call anything on the PrimaryBitstreamService', () => {
expect(bundleDataService.patch).not.toHaveBeenCalled(); expect(primaryBitstreamService.put).not.toHaveBeenCalled();
expect(primaryBitstreamService.delete).not.toHaveBeenCalled();
expect(primaryBitstreamService.create).not.toHaveBeenCalled();
}); });
}); });
describe('the bitstream was not and did not become the primary bitstream', () => { describe('the bitstream was not and did not become the primary bitstream', () => {
beforeEach(() => { beforeEach(() => {
const rawValue = Object.assign(comp.formGroup.getRawValue(), { fileNamePrimaryContainer: { primaryBitstream: false } }); const rawValue = Object.assign(comp.formGroup.getRawValue(), { fileNamePrimaryContainer: { primaryBitstream: false } });
spyOn(comp.formGroup, 'getRawValue').and.returnValue(rawValue); spyOn(comp.formGroup, 'getRawValue').and.returnValue(rawValue);
(comp as any).bundle = bundleWithDifferentPrimary; (comp as any).primaryBitstreamUUID = differentPrimary;
comp.onSubmit(); comp.onSubmit();
}); });
it('should not call patch on the bundle data service', () => { it('should not call anything on the PrimaryBitstreamService', () => {
expect(bundleDataService.patch).not.toHaveBeenCalled(); expect(primaryBitstreamService.put).not.toHaveBeenCalled();
expect(primaryBitstreamService.delete).not.toHaveBeenCalled();
expect(primaryBitstreamService.create).not.toHaveBeenCalled();
}); });
}); });
}); });
@@ -451,6 +464,7 @@ describe('EditBitstreamPageComponent', () => {
}); });
bitstreamService = jasmine.createSpyObj('bitstreamService', { bitstreamService = jasmine.createSpyObj('bitstreamService', {
findById: createSuccessfulRemoteDataObject$(bitstream), findById: createSuccessfulRemoteDataObject$(bitstream),
findByHref: createSuccessfulRemoteDataObject$(bitstream),
update: createSuccessfulRemoteDataObject$(bitstream), update: createSuccessfulRemoteDataObject$(bitstream),
updateFormat: createSuccessfulRemoteDataObject$(bitstream), updateFormat: createSuccessfulRemoteDataObject$(bitstream),
commitUpdates: {}, commitUpdates: {},
@@ -477,7 +491,7 @@ describe('EditBitstreamPageComponent', () => {
{provide: BitstreamDataService, useValue: bitstreamService}, {provide: BitstreamDataService, useValue: bitstreamService},
{provide: DSONameService, useValue: dsoNameService}, {provide: DSONameService, useValue: dsoNameService},
{provide: BitstreamFormatDataService, useValue: bitstreamFormatService}, {provide: BitstreamFormatDataService, useValue: bitstreamFormatService},
{ provide: BundleDataService, useValue: bundleDataService }, { provide: PrimaryBitstreamService, useValue: primaryBitstreamService },
ChangeDetectorRef ChangeDetectorRef
], ],
schemas: [NO_ERRORS_SCHEMA] schemas: [NO_ERRORS_SCHEMA]
@@ -595,7 +609,7 @@ describe('EditBitstreamPageComponent', () => {
{provide: BitstreamDataService, useValue: bitstreamService}, {provide: BitstreamDataService, useValue: bitstreamService},
{provide: DSONameService, useValue: dsoNameService}, {provide: DSONameService, useValue: dsoNameService},
{provide: BitstreamFormatDataService, useValue: bitstreamFormatService}, {provide: BitstreamFormatDataService, useValue: bitstreamFormatService},
{ provide: BundleDataService, useValue: bundleDataService }, { provide: PrimaryBitstreamService, useValue: primaryBitstreamService },
ChangeDetectorRef ChangeDetectorRef
], ],
schemas: [NO_ERRORS_SCHEMA] schemas: [NO_ERRORS_SCHEMA]
@@ -617,7 +631,7 @@ describe('EditBitstreamPageComponent', () => {
rawForm = comp.formGroup.getRawValue(); rawForm = comp.formGroup.getRawValue();
}); });
it('should NOT set isIIIF to true', () => { it('should NOT set is IIIF to true', () => {
expect(comp.isIIIF).toBeFalse(); expect(comp.isIIIF).toBeFalse();
}); });
it('should put the \"IIIF Label\" input not to be shown', () => { it('should put the \"IIIF Label\" input not to be shown', () => {

View File

@@ -1,7 +1,7 @@
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnDestroy, OnInit } from '@angular/core'; import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnDestroy, OnInit } from '@angular/core';
import { Bitstream } from '../../core/shared/bitstream.model'; import { Bitstream } from '../../core/shared/bitstream.model';
import { ActivatedRoute, Router } from '@angular/router'; import { ActivatedRoute, Router } from '@angular/router';
import { map, switchMap, tap, filter } from 'rxjs/operators'; import { filter, map, switchMap, tap } from 'rxjs/operators';
import { combineLatest, combineLatest as observableCombineLatest, Observable, of as observableOf, Subscription } from 'rxjs'; import { combineLatest, combineLatest as observableCombineLatest, Observable, of as observableOf, Subscription } from 'rxjs';
import { DynamicFormControlModel, DynamicFormGroupModel, DynamicFormLayout, DynamicFormService, DynamicInputModel, DynamicSelectModel } from '@ng-dynamic-forms/core'; import { DynamicFormControlModel, DynamicFormGroupModel, DynamicFormLayout, DynamicFormService, DynamicInputModel, DynamicSelectModel } from '@ng-dynamic-forms/core';
import { UntypedFormGroup } from '@angular/forms'; import { UntypedFormGroup } from '@angular/forms';
@@ -14,7 +14,7 @@ import { NotificationsService } from '../../shared/notifications/notifications.s
import { BitstreamFormatDataService } from '../../core/data/bitstream-format-data.service'; import { BitstreamFormatDataService } from '../../core/data/bitstream-format-data.service';
import { BitstreamFormat } from '../../core/shared/bitstream-format.model'; import { BitstreamFormat } from '../../core/shared/bitstream-format.model';
import { BitstreamFormatSupportLevel } from '../../core/shared/bitstream-format-support-level'; import { BitstreamFormatSupportLevel } from '../../core/shared/bitstream-format-support-level';
import { hasValue, isEmpty, isNotEmpty, hasValueOperator } from '../../shared/empty.util'; import { hasValue, hasValueOperator, isEmpty, isNotEmpty } from '../../shared/empty.util';
import { Metadata } from '../../core/shared/metadata.utils'; import { Metadata } from '../../core/shared/metadata.utils';
import { Location } from '@angular/common'; import { Location } from '@angular/common';
import { RemoteData } from '../../core/data/remote-data'; import { RemoteData } from '../../core/data/remote-data';
@@ -25,10 +25,7 @@ import { DSONameService } from '../../core/breadcrumbs/dso-name.service';
import { Item } from '../../core/shared/item.model'; import { Item } from '../../core/shared/item.model';
import { DsDynamicInputModel } from '../../shared/form/builder/ds-dynamic-form-ui/models/ds-dynamic-input.model'; import { DsDynamicInputModel } from '../../shared/form/builder/ds-dynamic-form-ui/models/ds-dynamic-input.model';
import { DsDynamicTextAreaModel } from '../../shared/form/builder/ds-dynamic-form-ui/models/ds-dynamic-textarea.model'; import { DsDynamicTextAreaModel } from '../../shared/form/builder/ds-dynamic-form-ui/models/ds-dynamic-textarea.model';
import { BundleDataService } from '../../core/data/bundle-data.service';
import { Operation } from 'fast-json-patch';
import { PrimaryBitstreamService } from '../../core/data/primary-bitstream-data.service'; import { PrimaryBitstreamService } from '../../core/data/primary-bitstream-data.service';
import { hasSucceeded } from '../../core/data/request-entry-state.model';
@Component({ @Component({
selector: 'ds-edit-bitstream-page', selector: 'ds-edit-bitstream-page',
@@ -374,12 +371,6 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
*/ */
private bundle: Bundle; private bundle: Bundle;
/**
* Path to patch primary bitstream on the bundle
* @private
*/
private readonly primaryBitstreamPath = '/primaryBitstreamUUID';
constructor(private route: ActivatedRoute, constructor(private route: ActivatedRoute,
private router: Router, private router: Router,
private changeDetectorRef: ChangeDetectorRef, private changeDetectorRef: ChangeDetectorRef,
@@ -391,7 +382,7 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
private notificationsService: NotificationsService, private notificationsService: NotificationsService,
private bitstreamFormatService: BitstreamFormatDataService, private bitstreamFormatService: BitstreamFormatDataService,
private primaryBitstreamService: PrimaryBitstreamService, private primaryBitstreamService: PrimaryBitstreamService,
private bundleService: BundleDataService) { ) {
} }
/** /**
@@ -404,33 +395,39 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
this.itemId = this.route.snapshot.queryParams.itemId; this.itemId = this.route.snapshot.queryParams.itemId;
this.entityType = this.route.snapshot.queryParams.entityType; this.entityType = this.route.snapshot.queryParams.entityType;
this.bitstreamRD$ = this.route.data.pipe(map((data) => data.bitstream)); this.bitstreamRD$ = this.route.data.pipe(map((data: any) => data.bitstream));
this.bitstreamFormatsRD$ = this.bitstreamFormatService.findAll(this.findAllOptions); this.bitstreamFormatsRD$ = this.bitstreamFormatService.findAll(this.findAllOptions);
const bitstream$ = this.bitstreamRD$.pipe( const bitstream$ = this.bitstreamRD$.pipe(
getFirstSucceededRemoteData(), getFirstSucceededRemoteData(),
getRemoteDataPayload() getRemoteDataPayload(),
tap(t => console.log(t)),
); );
const allFormats$ = this.bitstreamFormatsRD$.pipe( const allFormats$ = this.bitstreamFormatsRD$.pipe(
getFirstSucceededRemoteData(), getFirstSucceededRemoteData(),
getRemoteDataPayload() getRemoteDataPayload(),
tap(t => console.log(t)),
); );
const bundle$ = bitstream$.pipe( const bundle$ = bitstream$.pipe(
switchMap((bitstream: Bitstream) => bitstream.bundle), switchMap((bitstream: Bitstream) => bitstream.bundle),
getFirstSucceededRemoteDataPayload(), getFirstSucceededRemoteDataPayload(),
tap(t => console.log(t)),
); );
const primaryBitstream$ = bundle$.pipe( const primaryBitstream$ = bundle$.pipe(
hasValueOperator(), hasValueOperator(),
tap(t => console.log(t._links.primaryBitstream.href)),
switchMap((bundle: Bundle) => this.bitstreamService.findByHref(bundle._links.primaryBitstream.href)), switchMap((bundle: Bundle) => this.bitstreamService.findByHref(bundle._links.primaryBitstream.href)),
getFirstSucceededRemoteDataPayload() getFirstSucceededRemoteDataPayload(),
tap(t => console.log(t)),
); );
const item$ = bundle$.pipe( const item$ = bundle$.pipe(
switchMap((bundle: Bundle) => bundle.item), switchMap((bundle: Bundle) => bundle.item),
getFirstSucceededRemoteDataPayload() getFirstSucceededRemoteDataPayload(),
tap(t => console.log(t)),
); );
this.subs.push( this.subs.push(
observableCombineLatest( observableCombineLatest(