Skip to content

Commit

Permalink
test: combine all mapper tests into single file, improve comments, dry
Browse files Browse the repository at this point in the history
  • Loading branch information
spwoodcock committed Sep 16, 2024
1 parent 6a58845 commit 30c30e5
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 87 deletions.
102 changes: 85 additions & 17 deletions src/frontend/e2e/02-mapper-flow.spec.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
// This file tests the mapper workflow, including changing task status
// to locked, mapped, validated, and then commenting on the task.

import { test, expect } from '@playwright/test';

import { tempLogin } from './helpers';
import { tempLogin, openFirstProject } from './helpers';

test.describe('mapper flow', () => {
test('mapper flow', async ({ browserName, page }) => {
test('task actions', async ({ browserName, page }) => {
// Specific for this large test, only run in one browser
// (playwright.config.ts is configured to run all browsers by default)
test.skip(browserName !== 'chromium', 'Test only for chromium!');

// 0. Temp Login
await tempLogin(page);
await openFirstProject(page);

// click first project card on the home page
await page.locator('.MuiCardContent-root').first().click();

// click on task
await page.waitForTimeout(4000);
// 1. Click on task area on map
await page.locator('canvas').click({
position: {
x: 445,
Expand All @@ -26,15 +27,15 @@ test.describe('mapper flow', () => {
await page.getByTitle('Close').getByTestId('CloseIcon').click();
// Use maxDiffPixelRatio to avoid issues with OSM tile loading delay
expect(await page.locator('canvas').screenshot()).toMatchSnapshot('ready.png', { maxDiffPixelRatio: 0.05 });

await page.locator('canvas').click({
position: {
x: 445,
y: 95,
},
});
// STATUS: READY
await page.getByRole('button', { name: 'START MAPPING' }).waitFor({ state: 'visible' });

// 2. Lock task for mapping
await expect(page.getByRole('button', { name: 'START MAPPING' })).toBeVisible();
await page.getByRole('button', { name: 'START MAPPING' }).click();
await page.waitForSelector('div:has-text("updated status to LOCKED_FOR_MAPPING"):nth-of-type(1)');
await expect(
Expand All @@ -49,14 +50,14 @@ test.describe('mapper flow', () => {
expect(await page.locator('canvas').screenshot()).toMatchSnapshot('locked-for-mapping.png', {
maxDiffPixelRatio: 0.05,
});

await page.locator('canvas').click({
position: {
x: 445,
y: 95,
},
});
//STATUS: LOCKED_FOR_MAPPING

// 3. Mark task as fully mapped
await page.getByRole('button', { name: 'MARK AS FULLY MAPPED' }).click();
await page.getByRole('button', { name: 'MARK AS FULLY MAPPED' }).click();
await page.waitForSelector('div:has-text("updated status to MAPPED"):nth-of-type(1)');
Expand All @@ -70,14 +71,14 @@ test.describe('mapper flow', () => {
await page.getByTitle('Close').getByTestId('CloseIcon').click();
// Use maxDiffPixelRatio to avoid issues with OSM tile loading delay
expect(await page.locator('canvas').screenshot()).toMatchSnapshot('mapped.png', { maxDiffPixelRatio: 0.05 });

await page.locator('canvas').click({
position: {
x: 445,
y: 95,
},
});
// STATUS: MAPPED

// 4. Mark task as validated
await page.getByRole('button', { name: 'START VALIDATION' }).click();
// Wait for redirect to validation page
await page.waitForTimeout(2000);
Expand All @@ -100,17 +101,84 @@ test.describe('mapper flow', () => {
await expect(page.getByText('Status: VALIDATED')).toBeVisible();
});

test('comment section', async ({ browserName, page }) => {
test('open feature (Entity) in ODK', async ({ browserName, page }) => {
// Specific for this large test, only run in one browser
// (playwright.config.ts is configured to run all browsers by default)
test.skip(browserName !== 'chromium', 'Test only for chromium!');

// 0. Temp Login
await tempLogin(page);
await openFirstProject(page);

// 1. Click on task area on map
// click on task & assert task popup visibility
await page.locator('canvas').click({
position: {
x: 388,
y: 220,
},
});
await expect(page.getByText('Status: READY')).toBeVisible();
await expect(page.getByRole('button', { name: 'START MAPPING' })).toBeVisible();

// 2. Click on a specific feature / Entity within a task
// assert feature popup visibility
await page.waitForTimeout(4000);
await page.locator('canvas').click({
position: {
x: 387,
y: 211,
},
});
await expect(page.getByRole('heading', { name: 'Feature:' })).toBeVisible();
await expect(page.getByRole('button', { name: 'MAP FEATURE IN ODK' })).toBeEnabled();
await page.getByRole('button', { name: 'MAP FEATURE IN ODK' }).click();
// Check popup shows because we are not on a mobile device
await expect(
page.getByRole('alert').locator('div').filter({ hasText: 'Requires a mobile phone with ODK collect' }),
).toBeVisible();

// click first project card on the home page
await page.locator('.MuiCardContent-root').first().click();
// 3. Validate feature status updated / locked
// check if task status is updated to locked_for_mapping on entity map
await page.waitForSelector('div:has-text("updated status to LOCKED_FOR_MAPPING"):nth-of-type(1)');
await expect(
page
.locator('div')
.filter({ hasText: /updated status to LOCKED_FOR_MAPPING/ })
.first(),
).toBeVisible();

// click on task to check if task popup has been updated
await page.waitForTimeout(4000);
await page.locator('canvas').click({
position: {
x: 411,
y: 171,
},
});

// await page.getByText('Status: LOCKED_FOR_MAPPING').click();
await expect(page.getByText('Status: LOCKED_FOR_MAPPING')).toBeVisible();

// click entity to confirm task is locked
await page.locator('canvas').click({
position: {
x: 387,
y: 211,
},
});
await expect(page.getByRole('button', { name: 'MAP FEATURE IN ODK' })).toBeDisabled();
});

test('add comment', async ({ browserName, page }) => {
// Specific for this large test, only run in one browser
// (playwright.config.ts is configured to run all browsers by default)
test.skip(browserName !== 'chromium', 'Test only for chromium!');

// 0. Temp Login
await tempLogin(page);
await openFirstProject(page);

await page.locator('canvas').click({
position: {
x: 475,
Expand Down
70 changes: 0 additions & 70 deletions src/frontend/e2e/03-entity-update.spec.ts

This file was deleted.

6 changes: 6 additions & 0 deletions src/frontend/e2e/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ export async function tempLogin(page: Page) {
await page.getByRole('button', { name: 'Sign in' }).click();
await page.getByText('Temporary Account').click();
}

export async function openFirstProject(page: Page) {
// click first project card on the home page
await page.locator('.MuiCardContent-root').first().click();
await page.waitForTimeout(4000);
}

0 comments on commit 30c30e5

Please sign in to comment.