@@ -217,6 +217,7 @@ YUI.add('ez-trashview-tests', function (Y) {
217217 this . view = new Y . eZ . TrashView ( {
218218 trashBar : new Y . View ( ) ,
219219 trashItems : this . trashItems ,
220+ container : '.container' ,
220221 } ) ;
221222 } ,
222223
@@ -269,6 +270,125 @@ YUI.add('ez-trashview-tests', function (Y) {
269270
270271 this . view . fire ( 'whatever:restoreTrashItemsAction' ) ;
271272 } ,
273+
274+ "Should run the UDW when clicking on the restore a single item button" : function ( ) {
275+ var itemId = '/trash/item/42' ,
276+ udwStarted = false ;
277+
278+ this . trashItems . push ( this . _createItem ( itemId ) ) ;
279+
280+ this . view . on ( 'contentDiscover' , Y . bind ( function ( e ) {
281+ this . resume ( function ( ) {
282+ udwStarted = true ;
283+ } ) ;
284+ } , this ) ) ;
285+
286+ this . view . render ( ) ;
287+
288+ this . view . get ( 'container' ) . one ( '.ez-trashitem-restore' ) . simulateGesture ( 'tap' ) ;
289+ this . wait ( ) ;
290+
291+ Assert . isTrue (
292+ udwStarted ,
293+ "UDW should have been started"
294+ ) ;
295+ } ,
296+
297+ _testIsSelectable : function ( isContainer ) {
298+ var itemId = '/trash/item/42' ;
299+
300+ this . trashItems . push ( this . _createItem ( itemId ) ) ;
301+
302+ this . view . on ( 'contentDiscover' , Y . bind ( function ( e ) {
303+ this . resume ( function ( ) {
304+ var contentTypeMock = new Mock ( ) ;
305+
306+ Mock . expect ( contentTypeMock , {
307+ method : 'get' ,
308+ args : [ 'isContainer' ] ,
309+ returns : isContainer
310+ } ) ;
311+
312+ Assert . areSame (
313+ isContainer ,
314+ e . config . isSelectable . call ( this , { contentType : contentTypeMock } ) ,
315+ "The isSelectable method should the value of isContainer"
316+ ) ;
317+ } ) ;
318+ } , this ) ) ;
319+
320+ this . view . render ( ) ;
321+
322+ this . view . get ( 'container' ) . one ( '.ez-trashitem-restore' ) . simulateGesture ( 'tap' ) ;
323+ this . wait ( ) ;
324+ } ,
325+
326+ "Should allow to pick an element which is a container" : function ( ) {
327+ this . _testIsSelectable ( true ) ;
328+ } ,
329+
330+ "Should not allow to pick an element which is not a container" : function ( ) {
331+ this . _testIsSelectable ( false ) ;
332+ } ,
333+
334+ "Should fire `restoreItems` with destination when restoring a single item" : function ( ) {
335+ var locationMock = new Mock ( ) ,
336+ fakeEventFacade = { selection : { location : locationMock } } ,
337+ destinationId = '/my/destination/42' ,
338+ itemId = '/trash/item/42' ;
339+
340+ Mock . expect ( locationMock , {
341+ method : 'get' ,
342+ args : [ 'id' ] ,
343+ returns : destinationId
344+ } ) ;
345+
346+ this . trashItems . push ( this . _createItem ( itemId ) ) ;
347+
348+ this . view . on ( '*:restoreItems' , Y . bind ( function ( e ) {
349+ Assert . areSame (
350+ 1 ,
351+ e . trashItems . length ,
352+ "The clicked item should be provided"
353+ ) ;
354+
355+ Assert . areSame (
356+ itemId ,
357+ e . trashItems [ 0 ] . get ( 'id' ) ,
358+ "Item 1 should be the same"
359+ ) ;
360+
361+ Assert . areSame (
362+ destinationId ,
363+ e . destination ,
364+ "Destination should be provided"
365+ ) ;
366+ } , this ) ) ;
367+
368+ this . view . on ( 'contentDiscover' , Y . bind ( function ( e ) {
369+ this . resume ( function ( ) {
370+ var contentTypeMock = new Mock ( ) ;
371+
372+ Mock . expect ( contentTypeMock , {
373+ method : 'get' ,
374+ args : [ 'isContainer' ] ,
375+ returns : true
376+ } ) ;
377+
378+ Assert . isTrue (
379+ e . config . isSelectable . call ( this , { contentType : contentTypeMock } ) ,
380+ "The isSelectable method should the value of isContainer"
381+ ) ;
382+
383+ e . config . contentDiscoveredHandler . call ( this , fakeEventFacade ) ;
384+ } ) ;
385+ } , this ) ) ;
386+
387+ this . view . render ( ) ;
388+
389+ this . view . get ( 'container' ) . one ( '.ez-trashitem-restore' ) . simulateGesture ( 'tap' ) ;
390+ this . wait ( ) ;
391+ } ,
272392 } ) ;
273393
274394 attributesTest = new Y . Test . Case ( {
0 commit comments