@@ -219,6 +219,67 @@ test.describe( 'Gallery', () => {
219219 mediaLibrary . locator ( 'role=button[name="Create a new gallery"i]' )
220220 ) . toBeVisible ( ) ;
221221 } ) ;
222+
223+ test ( 'can randomize the image on the front end' , async ( {
224+ admin,
225+ editor,
226+ page,
227+ } ) => {
228+ const numbers = Array . from ( { length : 10 } , ( _ , i ) => i + 1 ) ;
229+ await admin . createNewPost ( ) ;
230+ await editor . insertBlock ( {
231+ name : 'core/gallery' ,
232+ attributes : {
233+ randomOrder : true ,
234+ } ,
235+ innerBlocks : numbers . map ( ( i ) => ( {
236+ name : 'core/image' ,
237+ attributes : {
238+ id : uploadedMedia . id ,
239+ alt : i . toString ( ) ,
240+ url : uploadedMedia . source_url ,
241+ } ,
242+ } ) ) ,
243+ } ) ;
244+ const postId = await editor . publishPost ( ) ;
245+ await page . goto ( `/?p=${ postId } ` ) ;
246+ const imageElements = page . locator ( '.wp-block-gallery img' ) ;
247+ const imageAltTexts = await imageElements . evaluateAll ( ( imgs ) =>
248+ imgs . map ( ( img ) => parseInt ( img . alt , 10 ) )
249+ ) ;
250+ expect ( numbers ) . not . toEqual ( imageAltTexts ) ;
251+ } ) ;
252+
253+ test ( 'can randomize the image with a lightbox effect on the front end' , async ( {
254+ admin,
255+ editor,
256+ page,
257+ } ) => {
258+ const numbers = Array . from ( { length : 10 } , ( _ , i ) => i + 1 ) ;
259+ await admin . createNewPost ( ) ;
260+ await editor . insertBlock ( {
261+ name : 'core/gallery' ,
262+ attributes : {
263+ randomOrder : true ,
264+ } ,
265+ innerBlocks : numbers . map ( ( i ) => ( {
266+ name : 'core/image' ,
267+ attributes : {
268+ id : uploadedMedia . id ,
269+ alt : i . toString ( ) ,
270+ url : uploadedMedia . source_url ,
271+ lightbox : { enabled : true } ,
272+ } ,
273+ } ) ) ,
274+ } ) ;
275+ const postId = await editor . publishPost ( ) ;
276+ await page . goto ( `/?p=${ postId } ` ) ;
277+ const imageElements = page . locator ( '.wp-block-gallery img' ) ;
278+ const imageAltTexts = await imageElements . evaluateAll ( ( imgs ) =>
279+ imgs . map ( ( img ) => parseInt ( img . alt , 10 ) )
280+ ) ;
281+ expect ( numbers ) . not . toEqual ( imageAltTexts ) ;
282+ } ) ;
222283} ) ;
223284
224285class GalleryBlockUtils {
0 commit comments