mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-15 22:13:02 +00:00
118223: Add item-bitstreams component tests
This commit is contained in:
@@ -26,9 +26,7 @@ import { createPaginatedList } from '../../../shared/testing/utils.test';
|
||||
import { FieldChangeType } from '../../../core/data/object-updates/field-change-type.model';
|
||||
import { BitstreamDataServiceStub } from '../../../shared/testing/bitstream-data-service.stub';
|
||||
import { ItemBitstreamsService } from './item-bitstreams.service';
|
||||
import { ResponsiveTableSizes } from '../../../shared/responsive-table-sizes/responsive-table-sizes';
|
||||
import { ResponsiveColumnSizes } from '../../../shared/responsive-table-sizes/responsive-column-sizes';
|
||||
import { PaginationComponentOptions } from '../../../shared/pagination/pagination-component-options.model';
|
||||
import { getItemBitstreamsServiceStub, ItemBitstreamsServiceStub } from './item-bitstreams.service.stub';
|
||||
|
||||
let comp: ItemBitstreamsComponent;
|
||||
let fixture: ComponentFixture<ItemBitstreamsComponent>;
|
||||
@@ -80,7 +78,7 @@ let objectCache: ObjectCacheService;
|
||||
let requestService: RequestService;
|
||||
let searchConfig: SearchConfigurationService;
|
||||
let bundleService: BundleDataService;
|
||||
let itemBitstreamsService: ItemBitstreamsService;
|
||||
let itemBitstreamsService: ItemBitstreamsServiceStub;
|
||||
|
||||
describe('ItemBitstreamsComponent', () => {
|
||||
beforeEach(waitForAsync(() => {
|
||||
@@ -152,18 +150,7 @@ describe('ItemBitstreamsComponent', () => {
|
||||
patch: createSuccessfulRemoteDataObject$({}),
|
||||
});
|
||||
|
||||
itemBitstreamsService = jasmine.createSpyObj('itemBitstreamsService', {
|
||||
getColumnSizes: new ResponsiveTableSizes([
|
||||
new ResponsiveColumnSizes(2, 2, 3, 4, 4),
|
||||
new ResponsiveColumnSizes(2, 3, 3, 3, 3),
|
||||
new ResponsiveColumnSizes(2, 2, 2, 2, 2),
|
||||
new ResponsiveColumnSizes(6, 5, 4, 3, 3)
|
||||
]),
|
||||
getSelectedBitstream$: observableOf({}),
|
||||
getInitialBundlesPaginationOptions: new PaginationComponentOptions(),
|
||||
removeMarkedBitstreams: createSuccessfulRemoteDataObject$({}),
|
||||
displayNotifications: undefined,
|
||||
});
|
||||
itemBitstreamsService = getItemBitstreamsServiceStub();
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot()],
|
||||
@@ -218,4 +205,114 @@ describe('ItemBitstreamsComponent', () => {
|
||||
expect(objectUpdatesService.reinstateFieldUpdates).toHaveBeenCalledWith(bundle.self);
|
||||
});
|
||||
});
|
||||
|
||||
describe('moveUp', () => {
|
||||
it('should move the selected bitstream up', () => {
|
||||
itemBitstreamsService.hasSelectedBitstream.and.returnValue(true);
|
||||
|
||||
const event = {
|
||||
preventDefault: () => {/* Intentionally empty */},
|
||||
} as KeyboardEvent;
|
||||
comp.moveUp(event);
|
||||
|
||||
expect(itemBitstreamsService.moveSelectedBitstreamUp).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not do anything if no bitstream is selected', () => {
|
||||
itemBitstreamsService.hasSelectedBitstream.and.returnValue(false);
|
||||
|
||||
const event = {
|
||||
preventDefault: () => {/* Intentionally empty */},
|
||||
} as KeyboardEvent;
|
||||
comp.moveUp(event);
|
||||
|
||||
expect(itemBitstreamsService.moveSelectedBitstreamUp).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('moveDown', () => {
|
||||
it('should move the selected bitstream down', () => {
|
||||
itemBitstreamsService.hasSelectedBitstream.and.returnValue(true);
|
||||
|
||||
const event = {
|
||||
preventDefault: () => {/* Intentionally empty */},
|
||||
} as KeyboardEvent;
|
||||
comp.moveDown(event);
|
||||
|
||||
expect(itemBitstreamsService.moveSelectedBitstreamDown).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not do anything if no bitstream is selected', () => {
|
||||
itemBitstreamsService.hasSelectedBitstream.and.returnValue(false);
|
||||
|
||||
const event = {
|
||||
preventDefault: () => {/* Intentionally empty */},
|
||||
} as KeyboardEvent;
|
||||
comp.moveDown(event);
|
||||
|
||||
expect(itemBitstreamsService.moveSelectedBitstreamDown).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('cancelSelection', () => {
|
||||
it('should cancel the selection', () => {
|
||||
itemBitstreamsService.hasSelectedBitstream.and.returnValue(true);
|
||||
|
||||
const event = {
|
||||
preventDefault: () => {/* Intentionally empty */},
|
||||
} as KeyboardEvent;
|
||||
comp.cancelSelection(event);
|
||||
|
||||
expect(itemBitstreamsService.cancelSelection).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not do anything if no bitstream is selected', () => {
|
||||
itemBitstreamsService.hasSelectedBitstream.and.returnValue(false);
|
||||
|
||||
const event = {
|
||||
preventDefault: () => {/* Intentionally empty */},
|
||||
} as KeyboardEvent;
|
||||
comp.cancelSelection(event);
|
||||
|
||||
expect(itemBitstreamsService.cancelSelection).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('clearSelection', () => {
|
||||
it('should clear the selection', () => {
|
||||
itemBitstreamsService.hasSelectedBitstream.and.returnValue(true);
|
||||
|
||||
const event = {
|
||||
target: document.createElement('BODY'),
|
||||
preventDefault: () => {/* Intentionally empty */},
|
||||
} as unknown as KeyboardEvent;
|
||||
comp.clearSelection(event);
|
||||
|
||||
expect(itemBitstreamsService.clearSelection).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not do anything if no bitstream is selected', () => {
|
||||
itemBitstreamsService.hasSelectedBitstream.and.returnValue(false);
|
||||
|
||||
const event = {
|
||||
target: document.createElement('BODY'),
|
||||
preventDefault: () => {/* Intentionally empty */},
|
||||
} as unknown as KeyboardEvent;
|
||||
comp.clearSelection(event);
|
||||
|
||||
expect(itemBitstreamsService.clearSelection).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not do anything if the event target is not \'BODY\'', () => {
|
||||
itemBitstreamsService.hasSelectedBitstream.and.returnValue(true);
|
||||
|
||||
const event = {
|
||||
target: document.createElement('NOT-BODY'),
|
||||
preventDefault: () => {/* Intentionally empty */},
|
||||
} as unknown as KeyboardEvent;
|
||||
comp.clearSelection(event);
|
||||
|
||||
expect(itemBitstreamsService.clearSelection).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user