Skip to content

Commit

Permalink
Add basic leaflet CRUD test
Browse files Browse the repository at this point in the history
  • Loading branch information
VirginiaDooley committed Sep 30, 2024
1 parent a5b116f commit cc6d803
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
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.
53 changes: 53 additions & 0 deletions tests/leaflet_crud.spec.js
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');
});

0 comments on commit cc6d803

Please sign in to comment.