|
| 1 | +// @ts-check |
| 2 | +const { test, expect } = require('@playwright/test'); |
| 3 | +const path = require('path'); |
| 4 | +const fs = require('fs'); |
| 5 | +const os = require('os'); |
| 6 | + |
| 7 | +test.beforeEach(async ({ page }) => { |
| 8 | + await page.goto('/'); |
| 9 | + // Wait for Blazor WASM to finish loading |
| 10 | + await page.waitForSelector('.spinner-border', { state: 'hidden', timeout: 30000 }); |
| 11 | +}); |
| 12 | + |
| 13 | +test('page title and heading', async ({ page }) => { |
| 14 | + await expect(page).toHaveTitle(/GZIP/i); |
| 15 | + await expect(page.getByRole('heading', { name: /Online GZIP de\/compressor/i })).toBeVisible(); |
| 16 | +}); |
| 17 | + |
| 18 | +test('compress mode is selected by default', async ({ page }) => { |
| 19 | + await expect(page.locator('#radio-compress')).toBeChecked(); |
| 20 | + await expect(page.locator('#radio-decompress')).not.toBeChecked(); |
| 21 | +}); |
| 22 | + |
| 23 | +test('all four compression levels are shown in compress mode', async ({ page }) => { |
| 24 | + await expect(page.locator('#radio-smallest')).toBeVisible(); |
| 25 | + await expect(page.locator('#radio-optimal')).toBeVisible(); |
| 26 | + await expect(page.locator('#radio-fastest')).toBeVisible(); |
| 27 | + await expect(page.locator('#radio-no-compression')).toBeVisible(); |
| 28 | + await expect(page.locator('#radio-optimal')).toBeChecked(); |
| 29 | +}); |
| 30 | + |
| 31 | +test('compress button is disabled with no files selected', async ({ page }) => { |
| 32 | + await expect(page.getByRole('button', { name: 'Compress Files' })).toBeDisabled(); |
| 33 | + await expect(page.getByText('No files selected')).toBeVisible(); |
| 34 | +}); |
| 35 | + |
| 36 | +test('compression level options are hidden in decompress mode', async ({ page }) => { |
| 37 | + await page.locator('#radio-decompress').check(); |
| 38 | + await expect(page.locator('#radio-optimal')).not.toBeVisible(); |
| 39 | + await expect(page.getByRole('button', { name: 'Decompress Files' })).toBeDisabled(); |
| 40 | +}); |
| 41 | + |
| 42 | +test('compress a file end-to-end', async ({ page }) => { |
| 43 | + // Create a temp file to compress |
| 44 | + const tmpFile = path.join(os.tmpdir(), 'test-input.txt'); |
| 45 | + fs.writeFileSync(tmpFile, 'Hello, GZIP!'); |
| 46 | + |
| 47 | + const downloadPromise = page.waitForEvent('download'); |
| 48 | + await page.locator('input[type="file"]').setInputFiles(tmpFile); |
| 49 | + await page.getByRole('button', { name: 'Compress Files' }).click(); |
| 50 | + |
| 51 | + const download = await downloadPromise; |
| 52 | + expect(download.suggestedFilename()).toBe('test-input.txt.gz'); |
| 53 | + |
| 54 | + // Verify the status shows Finished |
| 55 | + await expect(page.getByText('✔ Finished')).toBeVisible({ timeout: 10000 }); |
| 56 | + |
| 57 | + fs.unlinkSync(tmpFile); |
| 58 | +}); |
| 59 | + |
| 60 | +test('decompress a file end-to-end', async ({ page }) => { |
| 61 | + // Create a real gzip file to decompress |
| 62 | + const { execSync } = require('child_process'); |
| 63 | + const tmpDir = os.tmpdir(); |
| 64 | + const srcFile = path.join(tmpDir, 'test-decompress.txt'); |
| 65 | + const gzFile = path.join(tmpDir, 'test-decompress.txt.gz'); |
| 66 | + fs.writeFileSync(srcFile, 'Hello, GZIP decompressed!'); |
| 67 | + execSync(`gzip -kf ${srcFile}`); |
| 68 | + |
| 69 | + await page.locator('#radio-decompress').check(); |
| 70 | + |
| 71 | + const downloadPromise = page.waitForEvent('download'); |
| 72 | + await page.locator('input[type="file"]').setInputFiles(gzFile); |
| 73 | + await page.getByRole('button', { name: 'Decompress Files' }).click(); |
| 74 | + |
| 75 | + const download = await downloadPromise; |
| 76 | + expect(download.suggestedFilename()).toBe('test-decompress.txt'); |
| 77 | + |
| 78 | + await expect(page.getByText('✔ Finished')).toBeVisible({ timeout: 10000 }); |
| 79 | + |
| 80 | + fs.unlinkSync(srcFile); |
| 81 | + fs.unlinkSync(gzFile); |
| 82 | +}); |
0 commit comments