@@ -5,6 +5,7 @@ import React from 'react';
55import { renderInEntry } from 'support' ;
66import { screen } from '@testing-library/react' ;
77import '@testing-library/jest-dom/extend-expect' ;
8+ import { features } from 'pageflow/frontend' ;
89
910describe ( 'ExternalLink' , ( ) => {
1011 it ( 'renders link with href' , ( ) => {
@@ -237,6 +238,29 @@ describe('ExternalLink', () => {
237238 expect ( getByRole ( 'img' ) ) . toHaveAttribute ( 'src' , expect . stringContaining ( 'medium' ) ) ;
238239 } ) ;
239240
241+ it ( 'falls back to linkThumbnailLarge for large linkWidth when image_srcset disabled' , ( ) => {
242+ const { getByRole} = renderInEntry (
243+ < ExternalLink configuration = { { } }
244+ url = ""
245+ loadImages = { true }
246+ thumbnail = { 5 }
247+ linkWidth = "xxl" /> ,
248+ {
249+ seed : {
250+ imageFiles : [ { permaId : 5 } ] ,
251+ imageFileUrlTemplates : {
252+ linkThumbnailLarge : ':id_partition/linkThumbnailLarge/image.jpg' ,
253+ medium : ':id_partition/medium/image.jpg' ,
254+ large : ':id_partition/large/image.jpg'
255+ } ,
256+ }
257+ }
258+ )
259+
260+ expect ( getByRole ( 'img' ) ) . toHaveAttribute ( 'src' , expect . stringContaining ( 'linkThumbnailLarge' ) ) ;
261+ expect ( getByRole ( 'img' ) ) . not . toHaveAttribute ( 'srcset' ) ;
262+ } ) ;
263+
240264 it ( 'uses medium image as thumbnail with thumbnail fit contain' , ( ) => {
241265 const { getByRole} = renderInEntry (
242266 < ExternalLink configuration = { { } }
@@ -257,6 +281,86 @@ describe('ExternalLink', () => {
257281
258282 expect ( getByRole ( 'img' ) ) . toHaveAttribute ( 'src' , expect . stringContaining ( 'medium' ) ) ;
259283 } ) ;
284+
285+ describe ( 'srcset' , ( ) => {
286+ beforeEach ( ( ) => features . enable ( 'frontend' , [ 'image_srcset' ] ) ) ;
287+ afterEach ( ( ) => features . enabledFeatureNames = [ ] ) ;
288+
289+ it ( 'uses medium and large srcset for linkWidth m' , ( ) => {
290+ const { getByRole} = renderInEntry (
291+ < ExternalLink configuration = { { } }
292+ url = ""
293+ loadImages = { true }
294+ thumbnail = { 5 }
295+ linkWidth = "m" /> ,
296+ {
297+ seed : {
298+ imageFiles : [ { permaId : 5 , id : 1 , width : 4000 , height : 3000 } ] ,
299+ imageFileUrlTemplates : {
300+ linkThumbnailLarge : ':id_partition/linkThumbnailLarge/image.jpg' ,
301+ medium : ':id_partition/medium/image.jpg' ,
302+ large : ':id_partition/large/image.jpg'
303+ } ,
304+ }
305+ }
306+ )
307+
308+ expect ( getByRole ( 'img' ) ) . toHaveAttribute ( 'srcset' ,
309+ '000/000/001/medium/image.jpg 1024w, 000/000/001/large/image.jpg 1920w' ) ;
310+ expect ( getByRole ( 'img' ) ) . toHaveAttribute ( 'sizes' ,
311+ '(min-width: 950px) 50vw, 100vw' ) ;
312+ } ) ;
313+
314+ it ( 'uses medium, large and ultra srcset for linkWidth xxl' , ( ) => {
315+ const { getByRole} = renderInEntry (
316+ < ExternalLink configuration = { { } }
317+ url = ""
318+ loadImages = { true }
319+ thumbnail = { 5 }
320+ linkWidth = "xxl" /> ,
321+ {
322+ seed : {
323+ imageFiles : [ { permaId : 5 , id : 1 , width : 4000 , height : 3000 } ] ,
324+ imageFileUrlTemplates : {
325+ linkThumbnailLarge : ':id_partition/linkThumbnailLarge/image.jpg' ,
326+ medium : ':id_partition/medium/image.jpg' ,
327+ large : ':id_partition/large/image.jpg' ,
328+ ultra : ':id_partition/ultra/image.jpg'
329+ } ,
330+ }
331+ }
332+ )
333+
334+ expect ( getByRole ( 'img' ) ) . toHaveAttribute ( 'srcset' ,
335+ '000/000/001/medium/image.jpg 1024w, ' +
336+ '000/000/001/large/image.jpg 1920w, ' +
337+ '000/000/001/ultra/image.jpg 3840w' ) ;
338+ expect ( getByRole ( 'img' ) ) . toHaveAttribute ( 'sizes' , '100vw' ) ;
339+ } ) ;
340+
341+ it ( 'still uses linkThumbnailLarge for small linkWidth' , ( ) => {
342+ const { getByRole} = renderInEntry (
343+ < ExternalLink configuration = { { } }
344+ url = ""
345+ loadImages = { true }
346+ thumbnail = { 5 }
347+ linkWidth = "s" /> ,
348+ {
349+ seed : {
350+ imageFiles : [ { permaId : 5 , id : 1 , width : 4000 , height : 3000 } ] ,
351+ imageFileUrlTemplates : {
352+ linkThumbnailLarge : ':id_partition/linkThumbnailLarge/image.jpg' ,
353+ medium : ':id_partition/medium/image.jpg' ,
354+ large : ':id_partition/large/image.jpg'
355+ } ,
356+ }
357+ }
358+ )
359+
360+ expect ( getByRole ( 'img' ) ) . toHaveAttribute ( 'src' , expect . stringContaining ( 'linkThumbnailLarge' ) ) ;
361+ expect ( getByRole ( 'img' ) ) . not . toHaveAttribute ( 'srcset' ) ;
362+ } ) ;
363+ } ) ;
260364} ) ;
261365
262366function value ( text ) {
0 commit comments