Completed edit page and tests.

This commit is contained in:
Michael Spalti
2021-12-03 18:00:26 -08:00
parent 5865b83697
commit 9ae38f4a6c
2 changed files with 265 additions and 151 deletions

View File

@@ -30,8 +30,10 @@ const successNotification: INotification = new Notification('id', NotificationTy
let notificationsService: NotificationsService;
let formService: DynamicFormService;
let bitstreamService: BitstreamDataService;
let bitstreamServiceIIIF: BitstreamDataService;
let bitstreamFormatService: BitstreamFormatDataService;
let bitstream: Bitstream;
let bitstreamIIIFItem: Bitstream;
let selectedFormat: BitstreamFormat;
let allFormats: BitstreamFormat[];
let router: Router;
@@ -48,7 +50,7 @@ describe('EditBitstreamPageComponent', () => {
description: 'Unknown format',
supportLevel: BitstreamFormatSupportLevel.Unknown,
_links: {
self: { href: 'format-selflink-1' }
self: {href: 'format-selflink-1'}
}
}),
Object.assign({
@@ -57,7 +59,7 @@ describe('EditBitstreamPageComponent', () => {
description: 'Portable Network Graphics',
supportLevel: BitstreamFormatSupportLevel.Known,
_links: {
self: { href: 'format-selflink-2' }
self: {href: 'format-selflink-2'}
}
}),
Object.assign({
@@ -66,7 +68,7 @@ describe('EditBitstreamPageComponent', () => {
description: 'Graphics Interchange Format',
supportLevel: BitstreamFormatSupportLevel.Known,
_links: {
self: { href: 'format-selflink-3' }
self: {href: 'format-selflink-3'}
}
})
] as BitstreamFormat[];
@@ -90,6 +92,9 @@ describe('EditBitstreamPageComponent', () => {
return undefined;
}
});
describe('EditBitstreamPageComponent without IIIF fields', () => {
beforeEach(waitForAsync(() => {
bitstream = Object.assign(new Bitstream(), {
metadata: {
'dc.description': [
@@ -109,17 +114,12 @@ describe('EditBitstreamPageComponent', () => {
},
bundle: createSuccessfulRemoteDataObject$({
item: createSuccessfulRemoteDataObject$(Object.assign(new Item(), {
uuid: 'some-uuid'
uuid: 'some-uuid',
firstMetadataValue: () => '',
}))
})
});
bitstreamService = jasmine.createSpyObj('bitstreamService', {
findById: createSuccessfulRemoteDataObject$(bitstream),
update: createSuccessfulRemoteDataObject$(bitstream),
updateFormat: createSuccessfulRemoteDataObject$(bitstream),
commitUpdates: {},
patch: {}
});
bitstreamFormatService = jasmine.createSpyObj('bitstreamFormatService', {
findAll: createSuccessfulRemoteDataObject$(createPaginatedList(allFormats))
});
@@ -128,16 +128,20 @@ describe('EditBitstreamPageComponent', () => {
imports: [TranslateModule.forRoot(), RouterTestingModule],
declarations: [EditBitstreamPageComponent, FileSizePipe, VarDirective],
providers: [
{ provide: NotificationsService, useValue: notificationsService },
{ provide: DynamicFormService, useValue: formService },
{ provide: ActivatedRoute, useValue: { data: observableOf({ bitstream: createSuccessfulRemoteDataObject(bitstream) }), snapshot: { queryParams: {} } } },
{ provide: BitstreamDataService, useValue: bitstreamService },
{ provide: BitstreamFormatDataService, useValue: bitstreamFormatService },
{provide: NotificationsService, useValue: notificationsService},
{provide: DynamicFormService, useValue: formService},
{provide: ActivatedRoute,
useValue: {
data: observableOf({bitstream: createSuccessfulRemoteDataObject(bitstream)}),
snapshot: {queryParams: {}}
}
},
{provide: BitstreamDataService, useValue: bitstreamService},
{provide: BitstreamFormatDataService, useValue: bitstreamFormatService},
ChangeDetectorRef
],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();
}));
beforeEach(() => {
@@ -170,6 +174,12 @@ describe('EditBitstreamPageComponent', () => {
it('should put the \"New Format\" input on invisible', () => {
expect(comp.formLayout.newFormat.grid.host).toContain('invisible');
});
it('should put the \"IIIF Label\" input to be display: none', () => {
expect(comp.formLayout.iiifLabel.grid.host).toContain('d-none');
});
it('should set isIIIF to false', () => {
expect(comp.isIIIF).toBeFalse();
});
});
describe('when an unknown format is selected', () => {
@@ -242,4 +252,105 @@ describe('EditBitstreamPageComponent', () => {
expect(router.navigate).toHaveBeenCalledWith([getEntityEditRoute(null, 'some-uuid'), 'bitstreams']);
});
});
});
describe('EditBitstreamPageComponent with IIIF', () => {
beforeEach(waitForAsync(() => {
bitstreamService = jasmine.createSpyObj('bitstreamService', {
findById: createSuccessfulRemoteDataObject$(bitstream),
update: createSuccessfulRemoteDataObject$(bitstream),
updateFormat: createSuccessfulRemoteDataObject$(bitstream),
commitUpdates: {},
patch: {}
});
bitstreamIIIFItem = Object.assign(new Bitstream(), {
metadata: {
'dc.description': [
{
value: 'Bitstream description'
}
],
'dc.title': [
{
value: 'Bitstream title'
}
]
},
format: createSuccessfulRemoteDataObject$(selectedFormat),
_links: {
self: 'bitstream-selflink'
},
bundle: createSuccessfulRemoteDataObject$({
item: createSuccessfulRemoteDataObject$(Object.assign(new Item(), {
uuid: 'some-uuid',
firstMetadataValue: () => 'true',
metadata: {
'dspace.iiif.enabled': [
{
language: null,
value: 'true'
}
]
}
}))
})
});
bitstreamServiceIIIF = jasmine.createSpyObj('bitstreamService', {
findById: createSuccessfulRemoteDataObject$(bitstreamIIIFItem),
update: createSuccessfulRemoteDataObject$(bitstreamIIIFItem),
updateFormat: createSuccessfulRemoteDataObject$(bitstreamIIIFItem),
commitUpdates: {},
patch: {}
});
TestBed.configureTestingModule({
imports: [TranslateModule.forRoot(), RouterTestingModule],
declarations: [EditBitstreamPageComponent, FileSizePipe, VarDirective],
providers: [
{provide: NotificationsService, useValue: notificationsService},
{provide: DynamicFormService, useValue: formService},
{provide: ActivatedRoute,
useValue: {
data: observableOf({bitstream: createSuccessfulRemoteDataObject(bitstream)}),
snapshot: {queryParams: {}}
}
},
{provide: BitstreamDataService, useValue: bitstreamServiceIIIF},
{provide: BitstreamFormatDataService, useValue: bitstreamFormatService},
ChangeDetectorRef
],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(EditBitstreamPageComponent);
comp = fixture.componentInstance;
fixture.detectChanges();
router = TestBed.inject(Router);
spyOn(router, 'navigate');
});
});
describe('on startup', () => {
it('should set isIIIF to true', () => {
expect(comp.isIIIF).toBeTrue();
});
it('should put the \"IIIF Label\" input to be shown', () => {
expect(comp.formLayout.iiifLabel.grid.host).toContain('col');
});
it('should put the \"IIIF Toc\" input to be shown', () => {
expect(comp.formLayout.iiifToc.grid.host).toContain('col');
});
it('should put the \"IIIF width\" input to be shown', () => {
expect(comp.formLayout.iiifWidth.grid.host).toContain('col');
});
it('should put the \"IIIF Height\" input to be shown', () => {
expect(comp.formLayout.iiifHeight.grid.host).toContain('col');
});
});
}));
});

View File

@@ -342,7 +342,10 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
*/
entityType: string;
isIIIF: boolean;
/**
* Set to true when the parent item supports IIIF.
*/
isIIIF = false;
/**
* Array to track all subscriptions and unsubscribe them onDestroy