File tree Expand file tree Collapse file tree 6 files changed +72
-6
lines changed Expand file tree Collapse file tree 6 files changed +72
-6
lines changed Original file line number Diff line number Diff line change @@ -38,12 +38,15 @@ function preloadImage(src: string) {
38
38
} )
39
39
}
40
40
41
+ // added the version to prevent caching to make testing easier
42
+ const version = Date . now ( )
43
+
41
44
export function getImageUrlForShip (
42
45
shipName : string ,
43
46
{ size } : { size : number } ,
44
47
) {
45
- // return `/img/ships/${shipName.toLowerCase().replaceAll(' ', '-')}.webp?size=${size}`
48
+ // return `/img/ships/${shipName.toLowerCase().replaceAll(' ', '-')}.webp?size=${size}&version=${version} `
46
49
// 🧝♂️ This is just here for us to test what happens when the image fails to load
47
- const intentionalTypoUrl = `/img/typo/${ shipName . toLowerCase ( ) . replaceAll ( ' ' , '-' ) } .webp?size=${ size } `
50
+ const intentionalTypoUrl = `/img/typo/${ shipName . toLowerCase ( ) . replaceAll ( ' ' , '-' ) } .webp?size=${ size } &version= ${ version } `
48
51
return intentionalTypoUrl
49
52
}
Original file line number Diff line number Diff line change
1
+ import { expect , testStep , dtl } from '@epic-web/workshop-utils/test'
2
+ const { waitFor } = dtl
3
+
4
+ import './index.tsx'
5
+
6
+ await testStep ( 'Error boundary fallback is used for image' , async ( ) => {
7
+ await waitFor (
8
+ ( ) => {
9
+ const img = Array . from ( document . querySelectorAll ( 'img' ) ) . find ( ( img ) =>
10
+ img . getAttribute ( 'src' ) ?. includes ( 'typo' ) ,
11
+ )
12
+ expect (
13
+ img ,
14
+ '🚨 Image with typo in src should be in the document' ,
15
+ ) . toBeTruthy ( )
16
+ } ,
17
+ { timeout : 3000 } ,
18
+ )
19
+ } )
Original file line number Diff line number Diff line change @@ -38,12 +38,15 @@ function preloadImage(src: string) {
38
38
} )
39
39
}
40
40
41
+ // added the version to prevent caching to make testing easier
42
+ const version = Date . now ( )
43
+
41
44
export function getImageUrlForShip (
42
45
shipName : string ,
43
46
{ size } : { size : number } ,
44
47
) {
45
- // return `/img/ships/${shipName.toLowerCase().replaceAll(' ', '-')}.webp?size=${size}`
48
+ // return `/img/ships/${shipName.toLowerCase().replaceAll(' ', '-')}.webp?size=${size}&version=${version} `
46
49
// 🧝♂️ This is just here for us to test what happens when the image fails to load
47
- const intentionalTypoUrl = `/img/typo/${ shipName . toLowerCase ( ) . replaceAll ( ' ' , '-' ) } .webp?size=${ size } `
50
+ const intentionalTypoUrl = `/img/typo/${ shipName . toLowerCase ( ) . replaceAll ( ' ' , '-' ) } .webp?size=${ size } &version= ${ version } `
48
51
return intentionalTypoUrl
49
52
}
Original file line number Diff line number Diff line change @@ -38,9 +38,12 @@ function preloadImage(src: string) {
38
38
} )
39
39
}
40
40
41
+ // added the version to prevent caching to make testing easier
42
+ const version = Date . now ( )
43
+
41
44
export function getImageUrlForShip (
42
45
shipName : string ,
43
46
{ size } : { size : number } ,
44
47
) {
45
- return `/img/ships/${ shipName . toLowerCase ( ) . replaceAll ( ' ' , '-' ) } .webp?size=${ size } `
48
+ return `/img/ships/${ shipName . toLowerCase ( ) . replaceAll ( ' ' , '-' ) } .webp?size=${ size } &version= ${ version } `
46
49
}
Original file line number Diff line number Diff line change
1
+ import { expect , testStep , dtl } from '@epic-web/workshop-utils/test'
2
+ const { screen, waitFor, fireEvent } = dtl
3
+
4
+ import './index.tsx'
5
+
6
+ await testStep ( 'Initial ship details are loaded' , async ( ) => {
7
+ await screen . findByRole ( 'heading' , { name : / D r e a d n o u g h t / i } )
8
+ await waitFor (
9
+ ( ) => expect ( screen . queryAllByText ( 'loading' ) ) . toHaveLength ( 0 ) ,
10
+ { timeout : 3000 } ,
11
+ )
12
+ await new Promise ( ( resolve ) => {
13
+ screen
14
+ . getByAltText ( 'Dreadnought' )
15
+ . addEventListener ( 'load' , resolve , { once : true } )
16
+ } )
17
+ await new Promise ( ( resolve ) => setTimeout ( resolve , 250 ) )
18
+ } )
19
+
20
+ await testStep ( 'Click on a different ship' , async ( ) => {
21
+ fireEvent . click ( screen . getByRole ( 'button' , { name : 'Interceptor' } ) )
22
+ } )
23
+
24
+ await testStep ( 'The suspense boundary should be shown' , async ( ) => {
25
+ await waitFor (
26
+ ( ) => {
27
+ const fallbackImg = screen . getByAltText ( 'Interceptor' )
28
+ expect (
29
+ fallbackImg . getAttribute ( 'src' ) ,
30
+ '🚨 The fallback image is not shown. Make sure you add a key to the Suspense boundary.' ,
31
+ ) . toBe ( '/img/fallback-ship.png' )
32
+ } ,
33
+ { timeout : 3000 } ,
34
+ )
35
+ } )
Original file line number Diff line number Diff line change @@ -38,9 +38,12 @@ function preloadImage(src: string) {
38
38
} )
39
39
}
40
40
41
+ // added the version to prevent caching to make testing easier
42
+ const version = Date . now ( )
43
+
41
44
export function getImageUrlForShip (
42
45
shipName : string ,
43
46
{ size } : { size : number } ,
44
47
) {
45
- return `/img/ships/${ shipName . toLowerCase ( ) . replaceAll ( ' ' , '-' ) } .webp?size=${ size } `
48
+ return `/img/ships/${ shipName . toLowerCase ( ) . replaceAll ( ' ' , '-' ) } .webp?size=${ size } &version= ${ version } `
46
49
}
You can’t perform that action at this time.
0 commit comments