-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a5b116f
commit cc6d803
Showing
3 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { test } from '@playwright/test'; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
const baseUrl = 'http://localhost:8000/'; | ||
|
||
async function navigateToUploadPage(page) { | ||
await page.goto(baseUrl); | ||
await page.getByRole('link', { name: 'Upload a leaflet' }).click(); | ||
await page.getByText('Take a photo of a leaflet').click(); | ||
} | ||
|
||
async function fillPostcodeAndSubmit(page, postcode = 'W8 4NU') { | ||
await page.getByLabel('What postcode was this').click(); | ||
await page.getByLabel('What postcode was this').fill(postcode); | ||
await page.getByRole('button', { name: 'Submit' }).click(); | ||
await page.getByText('Green Party').click(); | ||
await page.getByRole('button', { name: 'Submit' }).click(); | ||
await page.getByText('Thank you so much!'); | ||
} | ||
|
||
// Increase the timeout for all tests | ||
test.setTimeout(60000); | ||
|
||
test('basic upload test', async ({ page }) => { | ||
await navigateToUploadPage(page); | ||
await page.getByLabel('Take a photo of a leaflet').setInputFiles('electionleaflets/test_media/test_images/test_leaflet.jpeg'); | ||
await page.getByRole('button', { name: 'Continue' }).click(); | ||
await fillPostcodeAndSubmit(page); | ||
}); | ||
|
||
test('uploading multiple leaflet images', async ({ page }) => { | ||
await navigateToUploadPage(page); | ||
const imageDir = path.resolve(__dirname, '../electionleaflets/test_media/test_images'); | ||
const imageFiles = fs.readdirSync(imageDir).map(file => path.join(imageDir, file)); | ||
await page.getByLabel('Take a photo of a leaflet').setInputFiles(imageFiles); | ||
await page.getByRole('button', { name: 'Continue' }).click(); | ||
await fillPostcodeAndSubmit(page); | ||
}); | ||
|
||
test('uploading a non-image leaflet file', async ({ page }) => { | ||
await navigateToUploadPage(page); | ||
await page.getByLabel('Take a photo of a leaflet').setInputFiles('electionleaflets/test_media/test_images/test_leaflet.docx'); | ||
await page.getByRole('button', { name: 'Continue' }).click(); | ||
await page.getByText('Error during upload tap to retry'); | ||
}); | ||
|
||
test('read leaflet from latest leaflets', async ({ page }) => { | ||
await page.goto(baseUrl); | ||
await page.getByRole('link', { name: 'Latest leaflets' }).click(); | ||
await page.locator('.ds-card-link').first().click(); | ||
await page.getByText('Leaflet details'); | ||
}); |