Jotley / website · jotley.ai / e2e / mac-download.spec.ts
| 1 | import { test, expect } from '@playwright/test'; |
| 2 | import { createHash, createPublicKey, verify } from 'node:crypto'; |
| 3 | |
| 4 | test('Mac download matches the website release manifest', async ({ request }) => { |
| 5 | const manifestResponse = await request.get('/mac-release.json'); |
| 6 | expect(manifestResponse.ok()).toBeTruthy(); |
| 7 | const manifest = await manifestResponse.json(); |
| 8 | expect(manifest.version).toMatch(/^\d+(\.\d+){1,2}$/); |
| 9 | expect(manifest.build).toBeGreaterThan(0); |
| 10 | expect(manifest.file).toBe(`Jotley-${manifest.version}-${manifest.build}.dmg`); |
| 11 | const response = await request.get(`https://jotley.ai/${manifest.file}`); |
| 12 | expect(response.ok()).toBeTruthy(); |
| 13 | const bytes = await response.body(); |
| 14 | expect(bytes.length).toBe(manifest.bytes); |
| 15 | expect(createHash('sha256').update(bytes).digest('hex')).toBe(manifest.sha256); |
| 16 | }); |
| 17 | |
| 18 | test('the website and Sparkle serve the same signed Mac release', async ({ request }) => { |
| 19 | const manifestResponse = await request.get('/mac-release.json'); |
| 20 | expect(manifestResponse.ok()).toBeTruthy(); |
| 21 | const manifest = await manifestResponse.json(); |
| 22 | const feedResponse = await request.get('/appcast.xml'); |
| 23 | expect(feedResponse.ok()).toBeTruthy(); |
| 24 | const feed = await feedResponse.text(); |
| 25 | const firstItem = feed.match(/<item>[\s\S]*?<\/item>/)?.[0] ?? ''; |
| 26 | const url = firstItem.match(/<enclosure\s[^>]*\burl="(https:\/\/jotley\.ai\/Jotley-[\w.-]+\.dmg)"/)?.[1]; |
| 27 | const length = firstItem.match(/<enclosure\s[^>]*\blength="(\d+)"/)?.[1]; |
| 28 | const signature = firstItem.match(/sparkle:edSignature="([^"]+)"/)?.[1]; |
| 29 | expect(firstItem).toContain(`<sparkle:version>${manifest.build}</sparkle:version>`); |
| 30 | expect(firstItem).toContain(`<sparkle:shortVersionString>${manifest.version}</sparkle:shortVersionString>`); |
| 31 | const feedBuilds = Array.from(feed.matchAll(/<sparkle:version>(\d+)<\/sparkle:version>/g), match => Number(match[1])); |
| 32 | expect(Math.max(...feedBuilds)).toBe(manifest.build); |
| 33 | expect(url).toBe(`https://jotley.ai/${manifest.file}`); |
| 34 | expect(Number(length)).toBe(manifest.bytes); |
| 35 | expect(signature).toBeTruthy(); |
| 36 | expect(firstItem).toContain('<sparkle:minimumSystemVersion>27.0</sparkle:minimumSystemVersion>'); |
| 37 | const response = await request.get(url!); |
| 38 | expect(response.ok()).toBeTruthy(); |
| 39 | const bytes = await response.body(); |
| 40 | expect(bytes.length).toBe(Number(length)); |
| 41 | expect(createHash('sha256').update(bytes).digest('hex')).toBe(manifest.sha256); |
| 42 | const key = createPublicKey({ |
| 43 | key: Buffer.concat([ |
| 44 | Buffer.from('302a300506032b6570032100', 'hex'), |
| 45 | Buffer.from('oVkqL3P3OGrwFhzgcWJQcF2dQ2Dn2rBvlB3bNOXGZSc=', 'base64'), |
| 46 | ]), |
| 47 | type: 'spki', format: 'der', |
| 48 | }); |
| 49 | expect(verify(null, bytes, key, Buffer.from(signature!, 'base64'))).toBeTruthy(); |
| 50 | }); |
| 51 | |
| 52 | test('the installation page shows free feedback and downloads only after a click', async ({ page, request }) => { |
| 53 | const manifest = await (await request.get('/mac-release.json')).json(); |
| 54 | await page.goto('/'); |
| 55 | const links = page.getByRole('link', { name: 'Download for Mac', exact: true }); |
| 56 | expect(await links.count()).toBe(3); |
| 57 | await expect(page.locator('.mac-availability, .mac-download-status')).toHaveCount(0); |
| 58 | await expect(page.locator('.platform-downloads').filter({ hasText: /coming soon/i })).toHaveCount(0); |
| 59 | // Two TestFlight pills plus the phone-width header link. |
| 60 | await expect(page.locator('a[href="https://testflight.apple.com/join/1y7UFzjK"]')).toHaveCount(3); |
| 61 | await expect(page.getByRole('link', { name: 'Join the TestFlight beta', exact: true }).first()).toHaveAttribute('href', 'https://testflight.apple.com/join/1y7UFzjK'); |
| 62 | await expect(page.locator('a[href*="apps.apple.com"]')).toHaveCount(0); |
| 63 | for (const link of await links.all()) await expect(link).toHaveAttribute('href', '/download'); |
| 64 | const downloads: string[] = []; |
| 65 | page.on('download', download => downloads.push(download.suggestedFilename())); |
| 66 | await page.goto('/download'); |
| 67 | await expect(page.getByRole('heading', { name: 'Free software. Supported by people.' })).toBeVisible(); |
| 68 | const feedback = page.locator('.dl-support').getByRole('link', { name: 'Send feedback' }); |
| 69 | await expect(feedback).toHaveAttribute('href', 'https://projectatom.ai/apps?app=jotley#feedback'); |
| 70 | await expect(page.locator('.dl-support')).not.toContainText(/tip|coffee|paid/i); |
| 71 | const downloadButton = page.getByRole('link', { name: 'Download Jotley for Mac', exact: true }); |
| 72 | await expect(downloadButton).toHaveAttribute('href', `/${manifest.file}`); |
| 73 | const feedbackBounds = await feedback.boundingBox(); |
| 74 | const downloadBounds = await downloadButton.boundingBox(); |
| 75 | expect(feedbackBounds!.y + feedbackBounds!.height).toBeLessThan(downloadBounds!.y); |
| 76 | await expect(page.getByRole('heading', { name: 'Download the Installer' })).toBeVisible(); |
| 77 | await expect(page.getByRole('heading', { name: 'Open DMG, Drag to Applications & Launch' })).toBeVisible(); |
| 78 | await expect(page.getByRole('heading', { name: 'Confirm Opening & Grant Permissions' })).toBeVisible(); |
| 79 | for (const alt of ['Jotley DMG file in Downloads folder', 'Jotley installer window, showing the app icon, Applications shortcut, and instructions to drag Jotley into Applications', 'Confirm opening Jotley', 'Jotley microphone access prompt']) { |
| 80 | const image = page.getByRole('img', { name: alt, exact: true }); |
| 81 | await image.scrollIntoViewIfNeeded(); |
| 82 | await expect.poll(() => image.evaluate(el => (el as HTMLImageElement).naturalWidth)).toBeGreaterThan(0); |
| 83 | } |
| 84 | const installer = page.locator('.dl-shot--installer'); |
| 85 | await expect(installer.getByRole('img')).toHaveAttribute('src', '/install-jotley.png'); |
| 86 | await expect(installer.locator('.dl-mark')).toHaveCount(0); |
| 87 | expect(downloads).toEqual([]); |
| 88 | const retry = page.waitForEvent('download'); |
| 89 | await downloadButton.click(); |
| 90 | expect((await retry).suggestedFilename()).toBe(manifest.file); |
| 91 | expect(downloads).toEqual([manifest.file]); |
| 92 | }); |
| 93 | |
| 94 | test('the singular installation page is canonical', async ({ request, baseURL }) => { |
| 95 | const page = await request.get('/download', { maxRedirects: 0 }); |
| 96 | expect(page.status()).toBe(200); |
| 97 | expect(page.headers().location).toBeUndefined(); |
| 98 | expect(await page.text()).toContain('https://jotley.ai/download'); |
| 99 | const legacyPage = await request.get('/downloads', { maxRedirects: 0 }); |
| 100 | const local = ['localhost', '127.0.0.1'].includes(new URL(baseURL!).hostname); |
| 101 | if (local) { |
| 102 | expect(legacyPage.status()).toBe(404); |
| 103 | } else { |
| 104 | expect(legacyPage.status()).toBe(308); |
| 105 | expect(legacyPage.headers().location).toBe('/download'); |
| 106 | } |
| 107 | }); |