@@ -26,9 +26,7 @@ import { createPaginatedList } from '../../../shared/testing/utils.test';
2626import { FieldChangeType } from '../../../core/data/object-updates/field-change-type.model' ;
2727import { BitstreamDataServiceStub } from '../../../shared/testing/bitstream-data-service.stub' ;
2828import { ItemBitstreamsService } from './item-bitstreams.service' ;
29- import { ResponsiveTableSizes } from '../../../shared/responsive-table-sizes/responsive-table-sizes' ;
30- import { ResponsiveColumnSizes } from '../../../shared/responsive-table-sizes/responsive-column-sizes' ;
31- import { PaginationComponentOptions } from '../../../shared/pagination/pagination-component-options.model' ;
29+ import { getItemBitstreamsServiceStub , ItemBitstreamsServiceStub } from './item-bitstreams.service.stub' ;
3230
3331let comp : ItemBitstreamsComponent ;
3432let fixture : ComponentFixture < ItemBitstreamsComponent > ;
@@ -80,7 +78,7 @@ let objectCache: ObjectCacheService;
8078let requestService : RequestService ;
8179let searchConfig : SearchConfigurationService ;
8280let bundleService : BundleDataService ;
83- let itemBitstreamsService : ItemBitstreamsService ;
81+ let itemBitstreamsService : ItemBitstreamsServiceStub ;
8482
8583describe ( 'ItemBitstreamsComponent' , ( ) => {
8684 beforeEach ( waitForAsync ( ( ) => {
@@ -152,18 +150,7 @@ describe('ItemBitstreamsComponent', () => {
152150 patch : createSuccessfulRemoteDataObject$ ( { } ) ,
153151 } ) ;
154152
155- itemBitstreamsService = jasmine . createSpyObj ( 'itemBitstreamsService' , {
156- getColumnSizes : new ResponsiveTableSizes ( [
157- new ResponsiveColumnSizes ( 2 , 2 , 3 , 4 , 4 ) ,
158- new ResponsiveColumnSizes ( 2 , 3 , 3 , 3 , 3 ) ,
159- new ResponsiveColumnSizes ( 2 , 2 , 2 , 2 , 2 ) ,
160- new ResponsiveColumnSizes ( 6 , 5 , 4 , 3 , 3 )
161- ] ) ,
162- getSelectedBitstream$ : observableOf ( { } ) ,
163- getInitialBundlesPaginationOptions : new PaginationComponentOptions ( ) ,
164- removeMarkedBitstreams : createSuccessfulRemoteDataObject$ ( { } ) ,
165- displayNotifications : undefined ,
166- } ) ;
153+ itemBitstreamsService = getItemBitstreamsServiceStub ( ) ;
167154
168155 TestBed . configureTestingModule ( {
169156 imports : [ TranslateModule . forRoot ( ) ] ,
@@ -218,4 +205,114 @@ describe('ItemBitstreamsComponent', () => {
218205 expect ( objectUpdatesService . reinstateFieldUpdates ) . toHaveBeenCalledWith ( bundle . self ) ;
219206 } ) ;
220207 } ) ;
208+
209+ describe ( 'moveUp' , ( ) => {
210+ it ( 'should move the selected bitstream up' , ( ) => {
211+ itemBitstreamsService . hasSelectedBitstream . and . returnValue ( true ) ;
212+
213+ const event = {
214+ preventDefault : ( ) => { /* Intentionally empty */ } ,
215+ } as KeyboardEvent ;
216+ comp . moveUp ( event ) ;
217+
218+ expect ( itemBitstreamsService . moveSelectedBitstreamUp ) . toHaveBeenCalled ( ) ;
219+ } ) ;
220+
221+ it ( 'should not do anything if no bitstream is selected' , ( ) => {
222+ itemBitstreamsService . hasSelectedBitstream . and . returnValue ( false ) ;
223+
224+ const event = {
225+ preventDefault : ( ) => { /* Intentionally empty */ } ,
226+ } as KeyboardEvent ;
227+ comp . moveUp ( event ) ;
228+
229+ expect ( itemBitstreamsService . moveSelectedBitstreamUp ) . not . toHaveBeenCalled ( ) ;
230+ } ) ;
231+ } ) ;
232+
233+ describe ( 'moveDown' , ( ) => {
234+ it ( 'should move the selected bitstream down' , ( ) => {
235+ itemBitstreamsService . hasSelectedBitstream . and . returnValue ( true ) ;
236+
237+ const event = {
238+ preventDefault : ( ) => { /* Intentionally empty */ } ,
239+ } as KeyboardEvent ;
240+ comp . moveDown ( event ) ;
241+
242+ expect ( itemBitstreamsService . moveSelectedBitstreamDown ) . toHaveBeenCalled ( ) ;
243+ } ) ;
244+
245+ it ( 'should not do anything if no bitstream is selected' , ( ) => {
246+ itemBitstreamsService . hasSelectedBitstream . and . returnValue ( false ) ;
247+
248+ const event = {
249+ preventDefault : ( ) => { /* Intentionally empty */ } ,
250+ } as KeyboardEvent ;
251+ comp . moveDown ( event ) ;
252+
253+ expect ( itemBitstreamsService . moveSelectedBitstreamDown ) . not . toHaveBeenCalled ( ) ;
254+ } ) ;
255+ } ) ;
256+
257+ describe ( 'cancelSelection' , ( ) => {
258+ it ( 'should cancel the selection' , ( ) => {
259+ itemBitstreamsService . hasSelectedBitstream . and . returnValue ( true ) ;
260+
261+ const event = {
262+ preventDefault : ( ) => { /* Intentionally empty */ } ,
263+ } as KeyboardEvent ;
264+ comp . cancelSelection ( event ) ;
265+
266+ expect ( itemBitstreamsService . cancelSelection ) . toHaveBeenCalled ( ) ;
267+ } ) ;
268+
269+ it ( 'should not do anything if no bitstream is selected' , ( ) => {
270+ itemBitstreamsService . hasSelectedBitstream . and . returnValue ( false ) ;
271+
272+ const event = {
273+ preventDefault : ( ) => { /* Intentionally empty */ } ,
274+ } as KeyboardEvent ;
275+ comp . cancelSelection ( event ) ;
276+
277+ expect ( itemBitstreamsService . cancelSelection ) . not . toHaveBeenCalled ( ) ;
278+ } ) ;
279+ } ) ;
280+
281+ describe ( 'clearSelection' , ( ) => {
282+ it ( 'should clear the selection' , ( ) => {
283+ itemBitstreamsService . hasSelectedBitstream . and . returnValue ( true ) ;
284+
285+ const event = {
286+ target : document . createElement ( 'BODY' ) ,
287+ preventDefault : ( ) => { /* Intentionally empty */ } ,
288+ } as unknown as KeyboardEvent ;
289+ comp . clearSelection ( event ) ;
290+
291+ expect ( itemBitstreamsService . clearSelection ) . toHaveBeenCalled ( ) ;
292+ } ) ;
293+
294+ it ( 'should not do anything if no bitstream is selected' , ( ) => {
295+ itemBitstreamsService . hasSelectedBitstream . and . returnValue ( false ) ;
296+
297+ const event = {
298+ target : document . createElement ( 'BODY' ) ,
299+ preventDefault : ( ) => { /* Intentionally empty */ } ,
300+ } as unknown as KeyboardEvent ;
301+ comp . clearSelection ( event ) ;
302+
303+ expect ( itemBitstreamsService . clearSelection ) . not . toHaveBeenCalled ( ) ;
304+ } ) ;
305+
306+ it ( 'should not do anything if the event target is not \'BODY\'' , ( ) => {
307+ itemBitstreamsService . hasSelectedBitstream . and . returnValue ( true ) ;
308+
309+ const event = {
310+ target : document . createElement ( 'NOT-BODY' ) ,
311+ preventDefault : ( ) => { /* Intentionally empty */ } ,
312+ } as unknown as KeyboardEvent ;
313+ comp . clearSelection ( event ) ;
314+
315+ expect ( itemBitstreamsService . clearSelection ) . not . toHaveBeenCalled ( ) ;
316+ } ) ;
317+ } ) ;
221318} ) ;
0 commit comments