77 TestBed ,
88 waitForAsync ,
99} from '@angular/core/testing' ;
10+ import { BrowserAnimationsModule } from '@angular/platform-browser/animations' ;
1011import {
1112 ActivatedRoute ,
1213 Router ,
@@ -15,7 +16,6 @@ import { TranslateModule } from '@ngx-translate/core';
1516import { of as observableOf } from 'rxjs' ;
1617
1718import { ObjectCacheService } from '../../../core/cache/object-cache.service' ;
18- import { RestResponse } from '../../../core/cache/response.models' ;
1919import { BitstreamDataService } from '../../../core/data/bitstream-data.service' ;
2020import { BundleDataService } from '../../../core/data/bundle-data.service' ;
2121import { ItemDataService } from '../../../core/data/item-data.service' ;
@@ -44,8 +44,12 @@ import { createPaginatedList } from '../../../shared/testing/utils.test';
4444import { ObjectValuesPipe } from '../../../shared/utils/object-values-pipe' ;
4545import { VarDirective } from '../../../shared/utils/var.directive' ;
4646import { ItemBitstreamsComponent } from './item-bitstreams.component' ;
47+ import { ItemBitstreamsService } from './item-bitstreams.service' ;
48+ import {
49+ getItemBitstreamsServiceStub ,
50+ ItemBitstreamsServiceStub ,
51+ } from './item-bitstreams.service.stub' ;
4752import { ItemEditBitstreamBundleComponent } from './item-edit-bitstream-bundle/item-edit-bitstream-bundle.component' ;
48- import { ItemEditBitstreamDragHandleComponent } from './item-edit-bitstream-drag-handle/item-edit-bitstream-drag-handle.component' ;
4953
5054let comp : ItemBitstreamsComponent ;
5155let fixture : ComponentFixture < ItemBitstreamsComponent > ;
@@ -97,6 +101,7 @@ let objectCache: ObjectCacheService;
97101let requestService : RequestService ;
98102let searchConfig : SearchConfigurationService ;
99103let bundleService : BundleDataService ;
104+ let itemBitstreamsService : ItemBitstreamsServiceStub ;
100105
101106describe ( 'ItemBitstreamsComponent' , ( ) => {
102107 beforeEach ( waitForAsync ( ( ) => {
@@ -165,11 +170,19 @@ describe('ItemBitstreamsComponent', () => {
165170 url : url ,
166171 } ) ;
167172 bundleService = jasmine . createSpyObj ( 'bundleService' , {
168- patch : observableOf ( new RestResponse ( true , 200 , 'OK' ) ) ,
173+ patch : createSuccessfulRemoteDataObject$ ( { } ) ,
169174 } ) ;
170175
176+ itemBitstreamsService = getItemBitstreamsServiceStub ( ) ;
177+
171178 TestBed . configureTestingModule ( {
172- imports : [ TranslateModule . forRoot ( ) , ItemBitstreamsComponent , ObjectValuesPipe , VarDirective ] ,
179+ imports : [
180+ TranslateModule . forRoot ( ) ,
181+ ItemBitstreamsComponent ,
182+ ObjectValuesPipe ,
183+ VarDirective ,
184+ BrowserAnimationsModule ,
185+ ] ,
173186 providers : [
174187 { provide : ItemDataService , useValue : itemService } ,
175188 { provide : ObjectUpdatesService , useValue : objectUpdatesService } ,
@@ -181,6 +194,7 @@ describe('ItemBitstreamsComponent', () => {
181194 { provide : RequestService , useValue : requestService } ,
182195 { provide : SearchConfigurationService , useValue : searchConfig } ,
183196 { provide : BundleDataService , useValue : bundleService } ,
197+ { provide : ItemBitstreamsService , useValue : itemBitstreamsService } ,
184198 ChangeDetectorRef ,
185199 ] , schemas : [
186200 NO_ERRORS_SCHEMA ,
@@ -189,7 +203,6 @@ describe('ItemBitstreamsComponent', () => {
189203 . overrideComponent ( ItemBitstreamsComponent , {
190204 remove : {
191205 imports : [ ItemEditBitstreamBundleComponent ,
192- ItemEditBitstreamDragHandleComponent ,
193206 ThemedLoadingComponent ] ,
194207 } ,
195208 } )
@@ -209,28 +222,8 @@ describe('ItemBitstreamsComponent', () => {
209222 comp . submit ( ) ;
210223 } ) ;
211224
212- it ( 'should call removeMultiple on the bitstreamService for the marked field' , ( ) => {
213- expect ( bitstreamService . removeMultiple ) . toHaveBeenCalledWith ( [ bitstream2 ] ) ;
214- } ) ;
215-
216- it ( 'should not call removeMultiple on the bitstreamService for the unmarked field' , ( ) => {
217- expect ( bitstreamService . removeMultiple ) . not . toHaveBeenCalledWith ( [ bitstream1 ] ) ;
218- } ) ;
219- } ) ;
220-
221- describe ( 'when dropBitstream is called' , ( ) => {
222- beforeEach ( ( done ) => {
223- comp . dropBitstream ( bundle , {
224- fromIndex : 0 ,
225- toIndex : 50 ,
226- finish : ( ) => {
227- done ( ) ;
228- } ,
229- } ) ;
230- } ) ;
231-
232- it ( 'should send out a patch for the move operation' , ( ) => {
233- expect ( bundleService . patch ) . toHaveBeenCalled ( ) ;
225+ it ( 'should call removeMarkedBitstreams on the itemBitstreamsService' , ( ) => {
226+ expect ( itemBitstreamsService . removeMarkedBitstreams ) . toHaveBeenCalled ( ) ;
234227 } ) ;
235228 } ) ;
236229
@@ -247,4 +240,114 @@ describe('ItemBitstreamsComponent', () => {
247240 expect ( objectUpdatesService . reinstateFieldUpdates ) . toHaveBeenCalledWith ( bundle . self ) ;
248241 } ) ;
249242 } ) ;
243+
244+ describe ( 'moveUp' , ( ) => {
245+ it ( 'should move the selected bitstream up' , ( ) => {
246+ itemBitstreamsService . hasSelectedBitstream . and . returnValue ( true ) ;
247+
248+ const event = {
249+ preventDefault : ( ) => { /* Intentionally empty */ } ,
250+ } as KeyboardEvent ;
251+ comp . moveUp ( event ) ;
252+
253+ expect ( itemBitstreamsService . moveSelectedBitstreamUp ) . toHaveBeenCalled ( ) ;
254+ } ) ;
255+
256+ it ( 'should not do anything if no bitstream is selected' , ( ) => {
257+ itemBitstreamsService . hasSelectedBitstream . and . returnValue ( false ) ;
258+
259+ const event = {
260+ preventDefault : ( ) => { /* Intentionally empty */ } ,
261+ } as KeyboardEvent ;
262+ comp . moveUp ( event ) ;
263+
264+ expect ( itemBitstreamsService . moveSelectedBitstreamUp ) . not . toHaveBeenCalled ( ) ;
265+ } ) ;
266+ } ) ;
267+
268+ describe ( 'moveDown' , ( ) => {
269+ it ( 'should move the selected bitstream down' , ( ) => {
270+ itemBitstreamsService . hasSelectedBitstream . and . returnValue ( true ) ;
271+
272+ const event = {
273+ preventDefault : ( ) => { /* Intentionally empty */ } ,
274+ } as KeyboardEvent ;
275+ comp . moveDown ( event ) ;
276+
277+ expect ( itemBitstreamsService . moveSelectedBitstreamDown ) . toHaveBeenCalled ( ) ;
278+ } ) ;
279+
280+ it ( 'should not do anything if no bitstream is selected' , ( ) => {
281+ itemBitstreamsService . hasSelectedBitstream . and . returnValue ( false ) ;
282+
283+ const event = {
284+ preventDefault : ( ) => { /* Intentionally empty */ } ,
285+ } as KeyboardEvent ;
286+ comp . moveDown ( event ) ;
287+
288+ expect ( itemBitstreamsService . moveSelectedBitstreamDown ) . not . toHaveBeenCalled ( ) ;
289+ } ) ;
290+ } ) ;
291+
292+ describe ( 'cancelSelection' , ( ) => {
293+ it ( 'should cancel the selection' , ( ) => {
294+ itemBitstreamsService . hasSelectedBitstream . and . returnValue ( true ) ;
295+
296+ const event = {
297+ preventDefault : ( ) => { /* Intentionally empty */ } ,
298+ } as KeyboardEvent ;
299+ comp . cancelSelection ( event ) ;
300+
301+ expect ( itemBitstreamsService . cancelSelection ) . toHaveBeenCalled ( ) ;
302+ } ) ;
303+
304+ it ( 'should not do anything if no bitstream is selected' , ( ) => {
305+ itemBitstreamsService . hasSelectedBitstream . and . returnValue ( false ) ;
306+
307+ const event = {
308+ preventDefault : ( ) => { /* Intentionally empty */ } ,
309+ } as KeyboardEvent ;
310+ comp . cancelSelection ( event ) ;
311+
312+ expect ( itemBitstreamsService . cancelSelection ) . not . toHaveBeenCalled ( ) ;
313+ } ) ;
314+ } ) ;
315+
316+ describe ( 'clearSelection' , ( ) => {
317+ it ( 'should clear the selection' , ( ) => {
318+ itemBitstreamsService . hasSelectedBitstream . and . returnValue ( true ) ;
319+
320+ const event = {
321+ target : document . createElement ( 'BODY' ) ,
322+ preventDefault : ( ) => { /* Intentionally empty */ } ,
323+ } as unknown as KeyboardEvent ;
324+ comp . clearSelection ( event ) ;
325+
326+ expect ( itemBitstreamsService . clearSelection ) . toHaveBeenCalled ( ) ;
327+ } ) ;
328+
329+ it ( 'should not do anything if no bitstream is selected' , ( ) => {
330+ itemBitstreamsService . hasSelectedBitstream . and . returnValue ( false ) ;
331+
332+ const event = {
333+ target : document . createElement ( 'BODY' ) ,
334+ preventDefault : ( ) => { /* Intentionally empty */ } ,
335+ } as unknown as KeyboardEvent ;
336+ comp . clearSelection ( event ) ;
337+
338+ expect ( itemBitstreamsService . clearSelection ) . not . toHaveBeenCalled ( ) ;
339+ } ) ;
340+
341+ it ( 'should not do anything if the event target is not \'BODY\'' , ( ) => {
342+ itemBitstreamsService . hasSelectedBitstream . and . returnValue ( true ) ;
343+
344+ const event = {
345+ target : document . createElement ( 'NOT-BODY' ) ,
346+ preventDefault : ( ) => { /* Intentionally empty */ } ,
347+ } as unknown as KeyboardEvent ;
348+ comp . clearSelection ( event ) ;
349+
350+ expect ( itemBitstreamsService . clearSelection ) . not . toHaveBeenCalled ( ) ;
351+ } ) ;
352+ } ) ;
250353} ) ;
0 commit comments