@@ -59,6 +59,13 @@ import { startMockCorsServer } from './startMockCorsServer.js'
5959const filename = fileURLToPath ( import . meta. url )
6060const dirname = path . dirname ( filename )
6161
62+ /**
63+ * Regex matcher for date cache tags.
64+ *
65+ * @example it will match `?2022-01-01T00%3A00%3A00.000Z` (`?2022-01-01T00:00:00.000Z` encoded)
66+ */
67+ const cacheTagPattern = / \? \d { 4 } - \d { 2 } - \d { 2 } T \d { 2 } % 3 A \d { 2 } % 3 A \d { 2 } \. \d { 3 } Z /
68+
6269const { afterAll, beforeAll, beforeEach, describe } = test
6370
6471let payload : PayloadTestSDK < Config >
@@ -640,7 +647,7 @@ describe('Uploads', () => {
640647 const genericUploadImage = page . locator ( 'tr.row-1 .thumbnail img' )
641648 await expect ( genericUploadImage ) . toHaveAttribute (
642649 'src' ,
643- ' https:/ /raw.githubusercontent.com/payloadcms/website/refs/heads/main/public/images/universal-truth.jpg' ,
650+ / ^ h t t p s : \/ \ /r a w \ .g i t h u b u s e r c o n t e n t \ .c o m \ /p a y l o a d c m s \ /w e b s i t e \ /r e f s \ /h e a d s \ /m a i n \ /p u b l i c \ /i m a g e s \ /u n i v e r s a l - t r u t h \ .j p g ( \? . * ) ? $ / ,
644651 )
645652 } )
646653
@@ -671,17 +678,14 @@ describe('Uploads', () => {
671678 await page . goto ( mediaWithoutCacheTagsSlugURL . edit ( imageDoc ! . id ) )
672679
673680 const genericUploadImage = page . locator ( '.file-details .thumbnail img' )
681+ await expect ( genericUploadImage ) . not . toHaveAttribute ( 'src' , cacheTagPattern )
682+ } )
674683
675- const src = await genericUploadImage . getAttribute ( 'src' )
676-
677- /**
678- * Regex matcher for date cache tags.
679- *
680- * @example it will match `?2022-01-01T00%3A00%3A00.000Z` (`?2022-01-01T00:00:00.000Z` encoded)
681- */
682- const cacheTagPattern = / \? \d { 4 } - \d { 2 } - \d { 2 } T \d { 2 } % 3 A \d { 2 } % 3 A \d { 2 } \. \d { 3 } Z /
684+ test ( 'should render adminThumbnail without the additional cache tag in upload collection list' , async ( ) => {
685+ await page . goto ( mediaWithoutCacheTagsSlugURL . list )
683686
684- expect ( src ) . not . toMatch ( cacheTagPattern )
687+ const genericUploadImage = page . locator ( 'tr.row-1 .thumbnail img' )
688+ await expect ( genericUploadImage ) . not . toHaveAttribute ( 'src' , cacheTagPattern )
685689 } )
686690
687691 test ( 'should render adminThumbnail with the cache tag by default' , async ( ) => {
@@ -701,17 +705,37 @@ describe('Uploads', () => {
701705 await page . goto ( adminThumbnailFunctionURL . edit ( imageDoc ! . id ) )
702706
703707 const genericUploadImage = page . locator ( '.file-details .thumbnail img' )
708+ await expect ( genericUploadImage ) . toHaveAttribute ( 'src' , cacheTagPattern )
709+ } )
704710
705- const src = await genericUploadImage . getAttribute ( 'src' )
711+ test ( 'should render adminThumbnail with the cache tag in upload collection list by default' , async ( ) => {
712+ await page . goto ( adminThumbnailFunctionURL . list )
713+
714+ const genericUploadImage = page . locator ( 'tr.row-1 .thumbnail img' )
715+ await expect ( genericUploadImage ) . toHaveAttribute ( 'src' , cacheTagPattern )
716+ } )
717+
718+ test ( 'should render adminThumbnail with the cache tag in relation list by default' , async ( ) => {
719+ await page . goto ( relationPreviewURL . list )
720+
721+ const relationPreview1 = page . locator ( '.cell-imageWithPreview1 img' )
722+ await expect ( relationPreview1 ) . toHaveAttribute ( 'src' , cacheTagPattern )
723+ } )
724+
725+ test ( 'should render adminThumbnail with the cache tag in upload field by default' , async ( ) => {
726+ const relationPreviewDoc = (
727+ await payload . find ( {
728+ collection : relationPreviewSlug ,
729+ depth : 0 ,
730+ limit : 1 ,
731+ pagination : false ,
732+ } )
733+ ) . docs [ 0 ]
706734
707- /**
708- * Regex matcher for date cache tags.
709- *
710- * @example it will match `?2022-01-01T00%3A00%3A00.000Z` (`?2022-01-01T00:00:00.000Z` encoded)
711- */
712- const cacheTagPattern = / \? \d { 4 } - \d { 2 } - \d { 2 } T \d { 2 } % 3 A \d { 2 } % 3 A \d { 2 } \. \d { 3 } Z /
735+ await page . goto ( relationPreviewURL . edit ( relationPreviewDoc ! . id ) )
713736
714- expect ( src ) . toMatch ( cacheTagPattern )
737+ const relationPreview1 = page . locator ( '#field-imageWithPreview1 .thumbnail img' )
738+ await expect ( relationPreview1 ) . toHaveAttribute ( 'src' , cacheTagPattern )
715739 } )
716740
717741 test ( 'should render adminThumbnail when using a specific size' , async ( ) => {
@@ -1863,7 +1887,7 @@ describe('Uploads', () => {
18631887 const thumbnail = page . locator ( '#field-withAdminThumbnail div.thumbnail > img' )
18641888 await expect ( thumbnail ) . toHaveAttribute (
18651889 'src' ,
1866- ' https:/ /raw.githubusercontent.com/payloadcms/website/refs/heads/main/public/images/universal-truth.jpg' ,
1890+ / ^ h t t p s : \/ \ /r a w \ .g i t h u b u s e r c o n t e n t \ .c o m \ /p a y l o a d c m s \ /w e b s i t e \ /r e f s \ /h e a d s \ /m a i n \ /p u b l i c \ /i m a g e s \ /u n i v e r s a l - t r u t h \ .j p g ( \? . * ) ? $ / ,
18671891 )
18681892 } )
18691893
@@ -1875,7 +1899,7 @@ describe('Uploads', () => {
18751899 const thumbnail = page . locator ( '#field-withinRange div.thumbnail > img' )
18761900 await expect ( thumbnail ) . toHaveAttribute (
18771901 'src' ,
1878- / \/ a p i \/ e n l a r g e \/ f i l e \/ t e s t - i m a g e - 1 8 0 x 5 0 \. j p g $ / ,
1902+ / \/ a p i \/ e n l a r g e \/ f i l e \/ t e s t - i m a g e - 1 8 0 x 5 0 \. j p g ( \? . * ) ? $ / ,
18791903 )
18801904 } )
18811905
@@ -1887,7 +1911,7 @@ describe('Uploads', () => {
18871911 const thumbnail = page . locator ( '#field-nextSmallestOutOfRange div.thumbnail > img' )
18881912 await expect ( thumbnail ) . toHaveAttribute (
18891913 'src' ,
1890- / \/ a p i \/ f o c a l - o n l y \/ f i l e \/ t e s t - i m a g e - 4 0 0 x 3 0 0 \. j p g $ / ,
1914+ / \/ a p i \/ f o c a l - o n l y \/ f i l e \/ t e s t - i m a g e - 4 0 0 x 3 0 0 \. j p g ( \? . * ) ? $ / ,
18911915 )
18921916 } )
18931917
@@ -1897,7 +1921,7 @@ describe('Uploads', () => {
18971921 await page . setInputFiles ( 'input[type="file"]' , path . join ( dirname , 'small.png' ) )
18981922 await page . locator ( 'dialog button#action-save' ) . click ( )
18991923 const thumbnail = page . locator ( '#field-original div.thumbnail > img' )
1900- await expect ( thumbnail ) . toHaveAttribute ( 'src' , / \/ a p i \/ f o c a l - o n l y \/ f i l e \/ s m a l l \. p n g $ / )
1924+ await expect ( thumbnail ) . toHaveAttribute ( 'src' , / \/ a p i \/ f o c a l - o n l y \/ f i l e \/ s m a l l \. p n g ( \? . * ) ? $ / )
19011925 } )
19021926 } )
19031927
0 commit comments