Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Playwright tests for mapper flow #1766

Merged
merged 13 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions src/frontend/e2e/entityPopup.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { test, expect } from '@playwright/test';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was checking the test ordering for Playwright
https://playwright.dev/docs/next/test-parallel#control-test-order

It seems they simply run in alphabetical order of the files, so with that in mind I think we should append numbers to some tests like:

  • 0-project-create.spec.ts
  • 1-mapper-workflow.spec.ts

This should mean that the project is created first, then the project page can be viewed and tests carried out there


test('entity test', async ({ page }) => {
await page.goto('/');
await page.getByRole('button', { name: 'Sign in' }).click();
await page
.getByLabel('', { exact: true })
.locator('div')
.filter({ hasText: "Temporary AccountIf you're" })
.nth(3)
.click();

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

// click on task & assert task popup visibility
await page.waitForTimeout(4000);
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();

// click on entity within 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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After this click I think we should expect a console warning that the redirect to protocol odkcollect:// failed (it attempts to open the link via mobile intent).

We could set a console listener via playwright and check this warning is displayed (it's not a user facing thing, but it helps check the button works as intended)


// 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();
});
64 changes: 64 additions & 0 deletions src/frontend/e2e/mapperFlow.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { test, expect } from '@playwright/test';

test('mapper flow test', async ({ page }) => {
await page.goto('/');
await page.getByRole('button', { name: 'Sign in' }).click();
await page
.getByLabel('', { exact: true })
.locator('div')
.filter({ hasText: "Temporary AccountIf you're" })
.nth(3)
.click();

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

// click on task
await page.waitForTimeout(4000);
await page.locator('canvas').click({
position: {
x: 445,
y: 95,
},
});
await expect(page.getByText('Status: READY')).toBeVisible();

// STATUS: READY
await page.getByRole('button', { name: 'START MAPPING' }).waitFor({ state: 'visible' });
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(
page
.locator('div')
.filter({ hasText: /updated status to LOCKED_FOR_MAPPING/ })
.first(),
).toBeVisible();

//STATUS: LOCKED_FOR_MAPPING
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)');
await expect(
page
.locator('div')
.filter({ hasText: /updated status to MAPPED/ })
.first(),
).toBeVisible();

// STATUS: MAPPED
await page.getByRole('button', { name: 'START VALIDATION' }).click();
await page.getByRole('button', { name: 'FULLY MAPPED' }).click();

await page.getByText('has been updated to VALIDATED').waitFor({ state: 'visible' });
await expect(page.getByText('has been updated to VALIDATED')).toBeVisible();

// click on validated task after map renders
await page.waitForTimeout(4000);
await page.locator('canvas').click({
position: {
x: 445,
y: 95,
},
});
await expect(page.getByText('Status: VALIDATED')).toBeVisible();
});
1 change: 1 addition & 0 deletions src/frontend/src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default {
{ key: 'Mapping Needed', value: 'INVALIDATED', btnBG: 'transparent' },
],
},
{ label: 'VALIDATED', action: [] },
// { label: 'VALIDATED', action: [{ key: 'Merge data with OSM', value: 'MERGE_WITH_OSM', btnBG: 'gray' }] },
{ label: 'INVALIDATED', action: [{ key: 'Map Again', value: 'LOCKED_FOR_MAPPING', btnBG: 'gray' }] },
{ label: 'BAD', action: [] },
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/store/slices/ProjectSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ const ProjectSlice = createSlice({
const updatedProjectTaskBoundries = state.projectTaskBoundries?.map((boundary) => {
if (boundary.id == action.payload.projectId) {
const updatedBoundary = boundary?.taskBoundries?.map((taskBoundary) => {
if (taskBoundary?.index === action.payload.taskId) {
if (taskBoundary?.index === +action.payload.taskId) {
return {
...taskBoundary,
task_status: action.payload.task_status,
Expand Down
Loading