Skip to content

Commit

Permalink
Add test, testId and loader wait
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotrk39 committed Oct 21, 2024
1 parent c4d6b17 commit 1c4fd39
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 1 deletion.
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 @@ -6,6 +6,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"
(click)="toggleLayerMenu()"
>
Expand Down
6 changes: 6 additions & 0 deletions tests/e2e/Pages/DashboardPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ class DashboardPage {
);
await this.droughtIcon.click();
}

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

export default DashboardPage;
12 changes: 12 additions & 0 deletions tests/e2e/Pages/MapComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class MapComponent extends DashboardPage {
readonly legend: Locator;
readonly layerMenu: Locator;
readonly adminBoundry: Locator;
readonly legendHeader: Locator;
readonly layerMenuToggle: Locator;

constructor(page: Page) {
super(page);
Expand All @@ -35,6 +37,8 @@ class MapComponent extends DashboardPage {
this.legend = this.page.getByTestId('map-legend');
this.layerMenu = this.page.getByTestId('layer-menu');
this.adminBoundry = this.page.locator('.leaflet-interactive');
this.legendHeader = this.page.getByTestId('map-legend-header');
this.layerMenuToggle = this.page.getByTestId('layer-menu-toggle-button');
}

async mapComponentIsVisible() {
Expand Down Expand Up @@ -115,6 +119,14 @@ class MapComponent extends DashboardPage {
await expect(adminBoundaries.nth(i)).toBeVisible();
}
}

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

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

export default MapComponent;
65 changes: 65 additions & 0 deletions tests/e2e/tests/Map/MapFunctionalitiesNotrigger.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
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'),
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 });
},
);

0 comments on commit 1c4fd39

Please sign in to comment.