@@ -6,59 +6,39 @@ test.describe('Download Functionality', () => {
66 test ( 'should download profile picture with Palestine border in all browsers' , async ( {
77 page,
88 } ) => {
9- // Navigate to the app
109 await page . goto ( '/' ) ;
11-
12- // Wait for the page to load
1310 await expect ( page . locator ( 'h1' ) ) . toContainText ( 'Show Solidarity' ) ;
1411
15- // Create a test image file
1612 const testImagePath = path . join ( __dirname , 'test-image.png' ) ;
17-
18- // Use a data URL for a simple test image (1x1 red pixel PNG)
1913 const testImageDataUrl =
2014 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8DwHwAFBQIAX8jx0gAAAABJRU5ErkJggg==' ;
2115
22- // Create a temporary file for testing
2316 if ( ! fs . existsSync ( testImagePath ) ) {
2417 const base64Data = testImageDataUrl . split ( ',' ) [ 1 ] ;
2518 const buffer = Buffer . from ( base64Data , 'base64' ) ;
2619 fs . writeFileSync ( testImagePath , buffer ) ;
2720 }
2821
29- // Upload the image
3022 const fileInput = page . locator ( 'input[type="file"]' ) ;
3123 await fileInput . setInputFiles ( testImagePath ) ;
32-
33- // Wait for the image to be processed
3424 await page . waitForTimeout ( 1000 ) ;
3525
36- // Verify the download button is visible
3726 const downloadButton = page . getByRole ( 'button' , { name : / d o w n l o a d i m a g e / i } ) ;
3827 await expect ( downloadButton ) . toBeVisible ( ) ;
3928
40- // Set up download promise before clicking
4129 const downloadPromise = page . waitForEvent ( 'download' ) ;
42-
43- // Click the download button
4430 await downloadButton . click ( ) ;
45-
46- // Wait for the download to start
4731 const download = await downloadPromise ;
4832
49- // Verify download properties
5033 expect ( download . suggestedFilename ( ) ) . toMatch ( / p r o f i l e - p i c - u s e r - u p l o a d \. p n g / ) ;
5134
52- // Save the download to verify it's a valid PNG
5335 const downloadPath = await download . path ( ) ;
5436 expect ( downloadPath ) . toBeTruthy ( ) ;
5537
56- // Verify the file exists and has content
5738 if ( downloadPath ) {
5839 const stats = fs . statSync ( downloadPath ) ;
5940 expect ( stats . size ) . toBeGreaterThan ( 0 ) ;
6041
61- // Verify it's a PNG by checking the magic number
6242 const buffer = fs . readFileSync ( downloadPath ) ;
6343 const isPNG =
6444 buffer [ 0 ] === 0x89 &&
@@ -68,36 +48,24 @@ test.describe('Download Functionality', () => {
6848 expect ( isPNG ) . toBe ( true ) ;
6949 }
7050
71- // Clean up test image
7251 if ( fs . existsSync ( testImagePath ) ) {
7352 fs . unlinkSync ( testImagePath ) ;
7453 }
7554 } ) ;
7655
7756 test ( 'should handle download errors gracefully' , async ( { page } ) => {
78- // Navigate to the app
7957 await page . goto ( '/' ) ;
80-
81- // Try to verify error handling by mocking a failure scenario
82- // This test ensures the error handling code path is present
8358 await expect ( page . locator ( 'h1' ) ) . toContainText ( 'Show Solidarity' ) ;
8459
85- // Verify the download button only appears after image upload
8660 const downloadButton = page . getByRole ( 'button' , { name : / d o w n l o a d i m a g e / i } ) ;
8761 await expect ( downloadButton ) . not . toBeVisible ( ) ;
8862 } ) ;
8963
9064 test ( 'should use html2canvas with proper CORS configuration' , async ( {
9165 page,
9266 } ) => {
93- // Navigate to the app
9467 await page . goto ( '/' ) ;
95-
96- // Check that html2canvas is being used in the page
9768 const pageContent = await page . content ( ) ;
98-
99- // This is a simple smoke test to ensure the page loads
100- // The actual html2canvas usage is verified by the successful download test
10169 await expect ( page . locator ( 'h1' ) ) . toContainText ( 'Show Solidarity' ) ;
10270 } ) ;
10371} ) ;
0 commit comments