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 e2e test for map functionalities in no-trigger mode #1662

Merged
merged 7 commits into from
Oct 22, 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
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ export class MapComponent implements AfterViewInit, OnDestroy {
index === self.findIndex((t) => t.name === value.name),
); // deduplicate based on name (for e.g. waterpoints_internal)

let detailsString = `<details data-testid="map-legend" open><summary><div class="legend-header">${this.mapLegendService.getLegendTitle()}
let detailsString = `<details data-testid="map-legend" open><summary><div data-testid="map-legend-header" class="legend-header">${this.mapLegendService.getLegendTitle()}
<ion-icon class="icon-down" name="chevron-down-outline"></ion-icon>
<ion-icon class="icon-up" name="chevron-up-outline"></ion-icon></div>
</summary>`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<ion-button
class="ion-no-margin ion-justify-content-between"
color="ibf-no-alert-primary "
data-testid="layer-menu-toggle-button"
id="layer-menu-toggle-button"
data-testid="layer-menu-toggle-button"
(click)="toggleLayerMenu()"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ export class PointMarkerService {
const markerInstance = marker(markerLatLng, {
title: markerTitle,
icon: icon(LEAFLET_MARKER_ICON_OPTIONS_RED_CROSS_BRANCH),
alt: 'red-cross-branch-marker',
});
markerInstance.bindPopup(this.createMarkerRedCrossPopup(markerProperties));
markerInstance.on(
Expand Down
12 changes: 12 additions & 0 deletions tests/e2e/Pages/DashboardPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ class DashboardPage {
this.loader = this.page.getByTestId('loader');
}

getRandomInt(min: number, max: number): number {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}

async navigateToFloodDisasterType() {
await this.page.waitForSelector(
'[data-testid=disaster-type-button-floods]',
Expand All @@ -53,6 +59,12 @@ class DashboardPage {
);
await this.droughtIcon.click();
}

async waitForLoaderToDisappear() {
await this.page.waitForSelector('[data-testid=loader]', {
state: 'hidden',
});
}
}

export default DashboardPage;
28 changes: 26 additions & 2 deletions tests/e2e/Pages/MapComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ class MapComponent extends DashboardPage {
readonly layerMenu: Locator;
readonly adminBoundry: Locator;
readonly layerCheckbox: Locator;
readonly legendHeader: Locator;
readonly layerMenuToggle: Locator;
readonly redCrossMarker: Locator;

constructor(page: Page) {
super(page);
Expand All @@ -39,7 +41,9 @@ class MapComponent extends DashboardPage {
this.layerMenu = this.page.getByTestId('layer-menu');
this.adminBoundry = this.page.locator('.leaflet-interactive');
this.layerCheckbox = this.page.getByTestId('matrix-checkbox');
this.legendHeader = this.page.getByTestId('map-legend-header');
this.layerMenuToggle = this.page.getByTestId('layer-menu-toggle-button');
this.redCrossMarker = this.page.getByAltText('red-cross-branch-marker');
}

async mapComponentIsVisible() {
Expand Down Expand Up @@ -121,7 +125,7 @@ class MapComponent extends DashboardPage {
}
}

async turnOffLayer({ layerName }: { layerName: string }) {
async clickLayerCheckbox({ layerName }: { layerName: string }) {
// Remove Glofas station from the map (in case the mock is for floods)
await this.layerMenuToggle.click();
const getLayerRow = this.page
Expand All @@ -147,6 +151,26 @@ class MapComponent extends DashboardPage {
'National View',
);
}
}

async clickLegendHeader() {
await this.legendHeader.click();
}

async clickLayerMenu() {
await this.layerMenuToggle.click();
}

async redCrossMarkersAreVisible() {
// Wait for the page to load
await this.page.waitForSelector('[alt="red-cross-branch-marker"]');

// Count the number of red cross markers
const redCrossMarkersCount = await this.redCrossMarker.count();
const nthSelector = this.getRandomInt(1, redCrossMarkersCount);

// Assert that the number of red cross markers is greater than 0 and randomly select one to be visible
expect(redCrossMarkersCount).toBeGreaterThan(0);
await expect(this.redCrossMarker.nth(nthSelector)).toBeVisible();
}
}
export default MapComponent;
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ test.beforeEach(async ({ page }) => {
);
});

test(
test.skip(
qase(12, 'Aggregates title should be dynamic no-trigger'),
jannisvisser marked this conversation as resolved.
Show resolved Hide resolved
async ({ page }) => {
const dashboard = new DashboardPage(page);
Expand All @@ -45,7 +45,7 @@ test(
await dashboard.navigateToFloodDisasterType();
// Assertions
await aggregates.aggregateComponentIsVisible();
await map.turnOffLayer({ layerName: 'Glofas stations' });
await map.clickLayerCheckbox({ layerName: 'Glofas stations' });
Piotrk39 marked this conversation as resolved.
Show resolved Hide resolved
await map.assertAggregateTitleOnHoverOverMap();
jannisvisser marked this conversation as resolved.
Show resolved Hide resolved
},
);
73 changes: 73 additions & 0 deletions tests/e2e/tests/Map/AssertMapFunctionalitiesNotrigger.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { test } from '@playwright/test';
import DashboardPage from 'Pages/DashboardPage';
import MapComponent from 'Pages/MapComponent';
import UserStateComponent from 'Pages/UserStateComponent';
import { qase } from 'playwright-qase-reporter';
import { NoTriggerDataSet } from 'testData/testData.enum';

import { FloodsScenario } from '../../../../services/API-service/src/scripts/enum/mock-scenario.enum';
import {
getAccessToken,
mockFloods,
resetDB,
} from '../../helpers/utility.helper';
import LoginPage from '../../Pages/LoginPage';

let accessToken: string;

test.beforeEach(async ({ page }) => {
// Login
const loginPage = new LoginPage(page);
accessToken = await getAccessToken();
await resetDB(accessToken);

// We should maybe create one mock for all different disaster types for now we can just use floods
await mockFloods(
FloodsScenario.NoTrigger,
NoTriggerDataSet.CountryCode,
accessToken,
);

await page.goto('/');
await loginPage.login(
NoTriggerDataSet.UserMail,
NoTriggerDataSet.UserPassword,
);
});

test(
qase(7, 'Verify Map functionality for no-triggered mode'),
jannisvisser marked this conversation as resolved.
Show resolved Hide resolved
async ({ page }) => {
const dashboard = new DashboardPage(page);
const userState = new UserStateComponent(page);
const map = new MapComponent(page);

// Navigate to disaster type the data was mocked for
await dashboard.navigateToFloodDisasterType();
// Assertions
await userState.headerComponentIsVisible({
countryName: NoTriggerDataSet.CountryName,
});
// Wait for the page to load
await dashboard.waitForLoaderToDisappear();
await map.mapComponentIsVisible();

// Close the legend
await map.isLegendOpen({ legendOpen: true });
await map.clickLegendHeader();
await map.isLegendOpen({ legendOpen: false });

// Open the layer menu
await map.isLayerMenuOpen({ layerMenuOpen: false });
await map.clickLayerMenu();
await map.isLayerMenuOpen({ layerMenuOpen: true });

// Select and deselect the layer
await map.clickLayerMenu();
await map.clickLayerCheckbox({ layerName: 'Red Cross branches' });
await map.isLayerMenuOpen({ layerMenuOpen: true });

// Red Cross branches layer should be visible
await map.redCrossMarkersAreVisible();
},
);