mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
118223: Add item-edit-bitstream-bundle component tests
This commit is contained in:
@@ -7,14 +7,19 @@ import { Bundle } from '../../../../core/shared/bundle.model';
|
|||||||
import { ResponsiveTableSizes } from '../../../../shared/responsive-table-sizes/responsive-table-sizes';
|
import { ResponsiveTableSizes } from '../../../../shared/responsive-table-sizes/responsive-table-sizes';
|
||||||
import { ResponsiveColumnSizes } from '../../../../shared/responsive-table-sizes/responsive-column-sizes';
|
import { ResponsiveColumnSizes } from '../../../../shared/responsive-table-sizes/responsive-column-sizes';
|
||||||
import { BundleDataService } from '../../../../core/data/bundle-data.service';
|
import { BundleDataService } from '../../../../core/data/bundle-data.service';
|
||||||
import { of as observableOf } from 'rxjs';
|
import { of as observableOf, of, Subject } from 'rxjs';
|
||||||
import { ObjectUpdatesService } from '../../../../core/data/object-updates/object-updates.service';
|
import { ObjectUpdatesService } from '../../../../core/data/object-updates/object-updates.service';
|
||||||
import { PaginationServiceStub } from '../../../../shared/testing/pagination-service.stub';
|
import { PaginationServiceStub } from '../../../../shared/testing/pagination-service.stub';
|
||||||
import { RequestService } from '../../../../core/data/request.service';
|
import { RequestService } from '../../../../core/data/request.service';
|
||||||
import { getMockRequestService } from '../../../../shared/mocks/request.service.mock';
|
import { getMockRequestService } from '../../../../shared/mocks/request.service.mock';
|
||||||
import { ItemBitstreamsService } from '../item-bitstreams.service';
|
import { ItemBitstreamsService, BitstreamTableEntry, SelectedBitstreamTableEntry } from '../item-bitstreams.service';
|
||||||
import { PaginationService } from '../../../../core/pagination/pagination.service';
|
import { PaginationService } from '../../../../core/pagination/pagination.service';
|
||||||
import { PaginationComponentOptions } from '../../../../shared/pagination/pagination-component-options.model';
|
import { getItemBitstreamsServiceStub, ItemBitstreamsServiceStub } from '../item-bitstreams.service.stub';
|
||||||
|
import { FieldUpdate } from '../../../../core/data/object-updates/field-update.model';
|
||||||
|
import { FieldChangeType } from '../../../../core/data/object-updates/field-change-type.model';
|
||||||
|
import { createSuccessfulRemoteDataObject$ } from '../../../../shared/remote-data.utils';
|
||||||
|
import { createPaginatedList } from '../../../../shared/testing/utils.test';
|
||||||
|
import { CdkDragDrop } from '@angular/cdk/drag-drop';
|
||||||
|
|
||||||
describe('ItemEditBitstreamBundleComponent', () => {
|
describe('ItemEditBitstreamBundleComponent', () => {
|
||||||
let comp: ItemEditBitstreamBundleComponent;
|
let comp: ItemEditBitstreamBundleComponent;
|
||||||
@@ -43,25 +48,20 @@ describe('ItemEditBitstreamBundleComponent', () => {
|
|||||||
const restEndpoint = 'fake-rest-endpoint';
|
const restEndpoint = 'fake-rest-endpoint';
|
||||||
const bundleService = jasmine.createSpyObj('bundleService', {
|
const bundleService = jasmine.createSpyObj('bundleService', {
|
||||||
getBitstreamsEndpoint: observableOf(restEndpoint),
|
getBitstreamsEndpoint: observableOf(restEndpoint),
|
||||||
getBitstreams: null,
|
getBitstreams: createSuccessfulRemoteDataObject$(createPaginatedList([])),
|
||||||
});
|
});
|
||||||
|
|
||||||
const objectUpdatesService = {
|
let objectUpdatesService: any;
|
||||||
initialize: () => {
|
let itemBitstreamsService: ItemBitstreamsServiceStub;
|
||||||
// do nothing
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const itemBitstreamsService = jasmine.createSpyObj('itemBitstreamsService', {
|
|
||||||
getInitialBitstreamsPaginationOptions: Object.assign(new PaginationComponentOptions(), {
|
|
||||||
id: 'bundles-pagination-options',
|
|
||||||
currentPage: 1,
|
|
||||||
pageSize: 9999
|
|
||||||
}),
|
|
||||||
getSelectedBitstream$: observableOf({}),
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(waitForAsync(() => {
|
beforeEach(waitForAsync(() => {
|
||||||
|
objectUpdatesService = jasmine.createSpyObj('objectUpdatesService', {
|
||||||
|
initialize: undefined,
|
||||||
|
getFieldUpdatesExclusive: of(null),
|
||||||
|
});
|
||||||
|
|
||||||
|
itemBitstreamsService = getItemBitstreamsServiceStub();
|
||||||
|
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [TranslateModule.forRoot()],
|
imports: [TranslateModule.forRoot()],
|
||||||
declarations: [ItemEditBitstreamBundleComponent],
|
declarations: [ItemEditBitstreamBundleComponent],
|
||||||
@@ -92,4 +92,270 @@ describe('ItemEditBitstreamBundleComponent', () => {
|
|||||||
it('should create an embedded view of the component', () => {
|
it('should create an embedded view of the component', () => {
|
||||||
expect(viewContainerRef.createEmbeddedView).toHaveBeenCalled();
|
expect(viewContainerRef.createEmbeddedView).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('on selected entry change', () => {
|
||||||
|
let paginationComponent: any;
|
||||||
|
let testSubject: Subject<SelectedBitstreamTableEntry> = new Subject();
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
paginationComponent = jasmine.createSpyObj('paginationComponent', {
|
||||||
|
doPageChange: undefined,
|
||||||
|
});
|
||||||
|
comp.paginationComponent = paginationComponent;
|
||||||
|
|
||||||
|
spyOn<any>(comp, 'getCurrentPageSize').and.returnValue(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should move to the page the selected entry is on if were not on that page', () => {
|
||||||
|
const selectedA: SelectedBitstreamTableEntry = {
|
||||||
|
bitstream: null,
|
||||||
|
bundle: bundle,
|
||||||
|
bundleSize: 5,
|
||||||
|
originalPosition: 1,
|
||||||
|
currentPosition: 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
const selectedB: SelectedBitstreamTableEntry = {
|
||||||
|
bitstream: null,
|
||||||
|
bundle: bundle,
|
||||||
|
bundleSize: 5,
|
||||||
|
originalPosition: 1,
|
||||||
|
currentPosition: 2,
|
||||||
|
};
|
||||||
|
|
||||||
|
comp.handleSelectedEntryChange(selectedA, selectedB);
|
||||||
|
expect(paginationComponent.doPageChange).toHaveBeenCalledWith(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not change page when we are already on the correct page', () => {
|
||||||
|
const selectedA: SelectedBitstreamTableEntry = {
|
||||||
|
bitstream: null,
|
||||||
|
bundle: bundle,
|
||||||
|
bundleSize: 5,
|
||||||
|
originalPosition: 0,
|
||||||
|
currentPosition: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
const selectedB: SelectedBitstreamTableEntry = {
|
||||||
|
bitstream: null,
|
||||||
|
bundle: bundle,
|
||||||
|
bundleSize: 5,
|
||||||
|
originalPosition: 0,
|
||||||
|
currentPosition: 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
comp.handleSelectedEntryChange(selectedA, selectedB);
|
||||||
|
expect(paginationComponent.doPageChange).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should change to the original page when cancelling', () => {
|
||||||
|
const selectedA: SelectedBitstreamTableEntry = {
|
||||||
|
bitstream: null,
|
||||||
|
bundle: bundle,
|
||||||
|
bundleSize: 5,
|
||||||
|
originalPosition: 3,
|
||||||
|
currentPosition: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
const selectedB = null;
|
||||||
|
|
||||||
|
comp.handleSelectedEntryChange(selectedA, selectedB);
|
||||||
|
expect(paginationComponent.doPageChange).toHaveBeenCalledWith(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not change page when we are already on the correct page when cancelling', () => {
|
||||||
|
const selectedA: SelectedBitstreamTableEntry = {
|
||||||
|
bitstream: null,
|
||||||
|
bundle: bundle,
|
||||||
|
bundleSize: 5,
|
||||||
|
originalPosition: 0,
|
||||||
|
currentPosition: 3,
|
||||||
|
};
|
||||||
|
|
||||||
|
const selectedB = null;
|
||||||
|
|
||||||
|
comp.handleSelectedEntryChange(selectedA, selectedB);
|
||||||
|
expect(paginationComponent.doPageChange).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('getRowClass', () => {
|
||||||
|
it('should return \'table-info\' when the bitstream is the selected bitstream', () => {
|
||||||
|
itemBitstreamsService.getSelectedBitstream.and.returnValue({
|
||||||
|
bitstream: { id: 'bitstream-id'}
|
||||||
|
});
|
||||||
|
|
||||||
|
const bitstreamEntry = {
|
||||||
|
id: 'bitstream-id',
|
||||||
|
} as BitstreamTableEntry;
|
||||||
|
|
||||||
|
expect(comp.getRowClass(undefined, bitstreamEntry)).toEqual('table-info');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return \'table-warning\' when the update is of type \'UPDATE\'', () => {
|
||||||
|
const update = {
|
||||||
|
changeType: FieldChangeType.UPDATE,
|
||||||
|
} as FieldUpdate;
|
||||||
|
|
||||||
|
expect(comp.getRowClass(update, undefined)).toEqual('table-warning');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return \'table-success\' when the update is of type \'ADD\'', () => {
|
||||||
|
const update = {
|
||||||
|
changeType: FieldChangeType.ADD,
|
||||||
|
} as FieldUpdate;
|
||||||
|
|
||||||
|
expect(comp.getRowClass(update, undefined)).toEqual('table-success');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return \'table-danger\' when the update is of type \'REMOVE\'', () => {
|
||||||
|
const update = {
|
||||||
|
changeType: FieldChangeType.REMOVE,
|
||||||
|
} as FieldUpdate;
|
||||||
|
|
||||||
|
expect(comp.getRowClass(update, undefined)).toEqual('table-danger');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return \'bg-white\' in any other case', () => {
|
||||||
|
const update = {
|
||||||
|
changeType: undefined,
|
||||||
|
} as FieldUpdate;
|
||||||
|
|
||||||
|
expect(comp.getRowClass(update, undefined)).toEqual('bg-white');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('drag', () => {
|
||||||
|
let dragTooltip;
|
||||||
|
let paginationComponent;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
dragTooltip = jasmine.createSpyObj('dragTooltip', {
|
||||||
|
open: undefined,
|
||||||
|
close: undefined,
|
||||||
|
});
|
||||||
|
comp.dragTooltip = dragTooltip;
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Start', () => {
|
||||||
|
it('should open the tooltip when there are multiple pages', () => {
|
||||||
|
paginationComponent = jasmine.createSpyObj('paginationComponent', {
|
||||||
|
doPageChange: undefined,
|
||||||
|
}, {
|
||||||
|
shouldShowBottomPager: of(true),
|
||||||
|
});
|
||||||
|
comp.paginationComponent = paginationComponent;
|
||||||
|
|
||||||
|
comp.dragStart();
|
||||||
|
expect(dragTooltip.open).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not open the tooltip when there is only a single page', () => {
|
||||||
|
paginationComponent = jasmine.createSpyObj('paginationComponent', {
|
||||||
|
doPageChange: undefined,
|
||||||
|
}, {
|
||||||
|
shouldShowBottomPager: of(false),
|
||||||
|
});
|
||||||
|
comp.paginationComponent = paginationComponent;
|
||||||
|
|
||||||
|
comp.dragStart();
|
||||||
|
expect(dragTooltip.open).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('end', () => {
|
||||||
|
it('should always close the tooltip', () => {
|
||||||
|
paginationComponent = jasmine.createSpyObj('paginationComponent', {
|
||||||
|
doPageChange: undefined,
|
||||||
|
}, {
|
||||||
|
shouldShowBottomPager: of(false),
|
||||||
|
});
|
||||||
|
comp.paginationComponent = paginationComponent;
|
||||||
|
|
||||||
|
comp.dragEnd();
|
||||||
|
expect(dragTooltip.close).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('drop', () => {
|
||||||
|
it('should correctly move the bitstream on drop', () => {
|
||||||
|
const event = {
|
||||||
|
previousIndex: 1,
|
||||||
|
currentIndex: 8,
|
||||||
|
dropPoint: { x: 100, y: 200 },
|
||||||
|
} as CdkDragDrop<any>;
|
||||||
|
|
||||||
|
comp.drop(event);
|
||||||
|
expect(itemBitstreamsService.performBitstreamMoveRequest).toHaveBeenCalledWith(jasmine.any(Bundle), 1, 8, jasmine.any(Function));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not move the bitstream if dropped in the same place', () => {
|
||||||
|
const event = {
|
||||||
|
previousIndex: 1,
|
||||||
|
currentIndex: 1,
|
||||||
|
dropPoint: { x: 100, y: 200 },
|
||||||
|
} as CdkDragDrop<any>;
|
||||||
|
|
||||||
|
comp.drop(event);
|
||||||
|
expect(itemBitstreamsService.performBitstreamMoveRequest).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should move to a different page if dropped on a page number', () => {
|
||||||
|
spyOn(document, 'elementFromPoint').and.returnValue({
|
||||||
|
textContent: '2',
|
||||||
|
classList: { contains: (token: string) => true },
|
||||||
|
} as Element);
|
||||||
|
|
||||||
|
const event = {
|
||||||
|
previousIndex: 1,
|
||||||
|
currentIndex: 1,
|
||||||
|
dropPoint: { x: 100, y: 200 },
|
||||||
|
} as CdkDragDrop<any>;
|
||||||
|
|
||||||
|
comp.drop(event);
|
||||||
|
expect(itemBitstreamsService.performBitstreamMoveRequest).toHaveBeenCalledWith(jasmine.any(Bundle), 1, 20, jasmine.any(Function));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('select', () => {
|
||||||
|
it('should select the bitstream', () => {
|
||||||
|
const event = new KeyboardEvent('keydown');
|
||||||
|
spyOnProperty(event, 'repeat', 'get').and.returnValue(false);
|
||||||
|
|
||||||
|
const entry = { } as BitstreamTableEntry;
|
||||||
|
comp.tableEntries$.next([entry]);
|
||||||
|
|
||||||
|
comp.select(event, entry);
|
||||||
|
expect(itemBitstreamsService.selectBitstreamEntry).toHaveBeenCalledWith(jasmine.objectContaining({ bitstream: entry }));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should cancel the selection if the bitstream already is selected', () => {
|
||||||
|
const event = new KeyboardEvent('keydown');
|
||||||
|
spyOnProperty(event, 'repeat', 'get').and.returnValue(false);
|
||||||
|
|
||||||
|
const entry = { } as BitstreamTableEntry;
|
||||||
|
comp.tableEntries$.next([entry]);
|
||||||
|
|
||||||
|
itemBitstreamsService.getSelectedBitstream.and.returnValue({ bitstream: entry });
|
||||||
|
|
||||||
|
comp.select(event, entry);
|
||||||
|
expect(itemBitstreamsService.selectBitstreamEntry).not.toHaveBeenCalled();
|
||||||
|
expect(itemBitstreamsService.cancelSelection).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not do anything if the user is holding down the select key', () => {
|
||||||
|
const event = new KeyboardEvent('keydown');
|
||||||
|
spyOnProperty(event, 'repeat', 'get').and.returnValue(true);
|
||||||
|
|
||||||
|
const entry = { } as BitstreamTableEntry;
|
||||||
|
comp.tableEntries$.next([entry]);
|
||||||
|
|
||||||
|
itemBitstreamsService.getSelectedBitstream.and.returnValue({ bitstream: entry });
|
||||||
|
|
||||||
|
comp.select(event, entry);
|
||||||
|
expect(itemBitstreamsService.selectBitstreamEntry).not.toHaveBeenCalled();
|
||||||
|
expect(itemBitstreamsService.cancelSelection).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -243,9 +243,8 @@ export class ItemEditBitstreamBundleComponent implements OnInit, OnDestroy {
|
|||||||
* Handles a change in selected bitstream by changing the pagination if the change happened on a different page
|
* Handles a change in selected bitstream by changing the pagination if the change happened on a different page
|
||||||
* @param previousSelectedEntry The previously selected entry
|
* @param previousSelectedEntry The previously selected entry
|
||||||
* @param currentSelectedEntry The currently selected entry
|
* @param currentSelectedEntry The currently selected entry
|
||||||
* @protected
|
|
||||||
*/
|
*/
|
||||||
protected handleSelectedEntryChange(
|
handleSelectedEntryChange(
|
||||||
previousSelectedEntry: SelectedBitstreamTableEntry,
|
previousSelectedEntry: SelectedBitstreamTableEntry,
|
||||||
currentSelectedEntry: SelectedBitstreamTableEntry
|
currentSelectedEntry: SelectedBitstreamTableEntry
|
||||||
) {
|
) {
|
||||||
|
Reference in New Issue
Block a user