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 tests for the AOI feature specification #1216

Merged
merged 5 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ const SelectorWrapper = styled.div`
position: relative;
`;

const PresetSelect = styled.select`
const PresetSelect = styled.select.attrs({
'data-testid': 'preset-selector'
})`
max-width: 200px;
height: ${selectorHeight};
color: transparent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ const MessageStatusIndicator = styled.div<MessageStatusIndicatorProps>`
}
}}
`;
const MessageContent = styled.div`
const MessageContent = styled.div.attrs({
'data-testid': 'analysis-message'
})`
stephenkilbourn marked this conversation as resolved.
Show resolved Hide resolved
line-height: 1.5rem;
max-height: 1.5rem;

Expand Down
14 changes: 14 additions & 0 deletions docs/development/SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ VEDA-UI includes a GitHub action for checking TypeScript and lint errors. If you
#### Pre-commit Hook
Additionally, there's a pre-commit hook that performs the same error checks. This helps developers identify and address issues at an earlier stage. If you need to bypass the check (to make a local temporary commit etc.), include the `--no-verify`` flag in your commit command.

### Testing
AliceR marked this conversation as resolved.
Show resolved Hide resolved

## Unit tests

`yarn test`

## End-to-end tests
Make sure the development server is running (`yarn serve`)

`yarn test:e2e --ui`

Alternatively, you can install the playwright extension for vs code (ms-playwright.playwright) and run the tests directly from there. It allows to run the tests in watch mode, open the browser or trace viewer, set breakpoints,...
Again, make sure that the development server is running (`yarn serve`).

## Deployment
To prepare the app for deployment run:

Expand Down
55 changes: 55 additions & 0 deletions test/playwright/tests/exploreAoi.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { test, expect } from '../pages/basePage';

test.describe('Area of Interest (AOI) Analysis', () => {
test.beforeEach(
async ({ page, explorePage, consentBanner, datasetSelectorComponent }) => {
let pageErrorCalled = false;
// Log all uncaught errors to the terminal to be visible in trace
page.on('pageerror', (exception) => {
console.log(`Uncaught exception: "${JSON.stringify(exception)}"`);
pageErrorCalled = true;
});

const mapboxResponsePromise = page.waitForResponse(
/api\.mapbox.com\/v4\/mapbox\.mapbox-streets-v8/i
);

// Given that I am on the map view (explore page)
AliceR marked this conversation as resolved.
Show resolved Hide resolved
await page.goto('/exploration');
await consentBanner.acceptButton.click();
await datasetSelectorComponent.addFirstDataset();
await explorePage.closeFeatureTour();
}
);

test('User selects a pre-defined AOI', async ({ page }) => {
// When I select the "Analyze an area" tool (Dropdown menu)
const toolbar = page.getByTestId('preset-selector');
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can update the explorePage.ts to use this better locator

// And choose one of the listed regions
await toolbar.selectOption('Hawaii');

// Then map should display the selected area as the AOI
// const aoi = await page.$('selector-for-aoi'); // Adjust the selector as needed
// expect(aoi).not.toBeNull();

// // And the AOI should not be editable when clicking on it
// await page.click('selector-for-aoi'); // Adjust the selector as needed
// const isEditable = await page.$eval('selector-for-aoi', el => console.log(el)); // Adjust the selector as needed
// expect(isEditable).toBe(false);

// And the analysis message should display the size of the area
const analysisMessage = await page
.getByTestId('analysis-message')
.textContent()

expect(analysisMessage).toContain('An area of 17 K km2 is selected.');
AliceR marked this conversation as resolved.
Show resolved Hide resolved

// And the 'Delete all areas' button should be shown
const deleteButton = await page.$('text=Delete all areas');
AliceR marked this conversation as resolved.
Show resolved Hide resolved
expect(deleteButton).not.toBeNull();
AliceR marked this conversation as resolved.
Show resolved Hide resolved

// And the 'Run analysis' button should be shown
const runButton = await page.$('text=Run analysis');
expect(runButton).not.toBeNull();
AliceR marked this conversation as resolved.
Show resolved Hide resolved
});
});