Skip to content

Commit

Permalink
Add test without final assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotrk39 committed Dec 3, 2024
1 parent 541fd18 commit e0b4efa
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
}
@if (isRadioButton(layer.group)) {
<ion-icon
data-testid="matrix-radio-button"
[name]="
layer.active
? 'radio-button-on-outline'
Expand Down
21 changes: 21 additions & 0 deletions tests/e2e/Pages/MapComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class MapComponent extends DashboardPage {
readonly layerMenu: Locator;
readonly adminBoundry: Locator;
readonly layerCheckbox: Locator;
readonly layerRadioButton: Locator;
readonly legendHeader: Locator;
readonly layerMenuToggle: Locator;
readonly redCrossMarker: Locator;
Expand Down Expand Up @@ -45,6 +46,7 @@ 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.layerRadioButton = this.page.getByTestId('matrix-radio-button');
this.legendHeader = this.page.getByTestId('map-legend-header');
this.layerMenuToggle = this.page.getByTestId('layer-menu-toggle-button');
this.redCrossMarker = this.page.getByAltText('Red Cross branches');
Expand Down Expand Up @@ -160,6 +162,25 @@ class MapComponent extends DashboardPage {
}
}

async verifyLayerRadioButtonCheckedByName({
layerName,
}: {
layerName: string;
}) {
const getLayerRow = this.page
.getByTestId('matrix-layer-name')
.filter({ hasText: layerName });
const layerCheckbox = getLayerRow.locator(this.layerRadioButton);

// In case of checbox being checked the name attribute should be "checkbox"
const nameAttribute = await layerCheckbox.getAttribute('name');
const isChecked = nameAttribute === 'radio-button-on-outline';

if (!isChecked) {
throw new Error(`Radio button for layer ${layerName} is not checked`);
}
}

async clickInfoButtonByName({ layerName }: { layerName: string }) {
await this.page
.locator(`ion-item`)
Expand Down
68 changes: 68 additions & 0 deletions tests/e2e/tests/Map/ExposedPopulationVisibleInTrigger.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
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 { TriggerDataSet } 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.Trigger,
TriggerDataSet.CountryCode,
accessToken,
);

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

test(
qase(
36,
'[Trigger] Exposed population legend is visible when exposed population layer is active',
),
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: TriggerDataSet.CountryName,
});
// Wait for the page to load
await dashboard.waitForLoaderToDisappear();

await map.mapComponentIsVisible();
await map.isLegendOpen({ legendOpen: true });
await map.isLayerMenuOpen({ layerMenuOpen: false });
await map.clickLayerMenu();
await map.verifyLayerRadioButtonCheckedByName({
layerName: 'Exposed population',
});
await map.assertLegendElementIsVisible({
legendComponentName: 'Exposed population',
});

// Exposed population layer should be visible by default in trigger mode
console.log('Exposed population layer is visible');
},
);

0 comments on commit e0b4efa

Please sign in to comment.