Skip to content

Commit

Permalink
Add test cases for selection behaviour (#6048)
Browse files Browse the repository at this point in the history
* Add changes from PR review

---------

Co-authored-by: Domenico Gemoli <dgemoli@redcross.nl>
  • Loading branch information
Piotrk39 and aberonni authored Nov 8, 2024
1 parent 1d91c22 commit 5a87a35
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 1 deletion.
63 changes: 63 additions & 0 deletions e2e/portalicious/pages/RegistrationsPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ class RegistrationsPage extends BasePage {
readonly page: Page;
readonly table: TableComponent;
readonly goToProfileOption: Locator;
readonly sendMessageDialogPreview: Locator;

constructor(page: Page) {
super(page);
this.page = page;
this.table = new TableComponent(page);
this.goToProfileOption = this.page.getByText('Go to profile');
this.sendMessageDialogPreview = this.page.getByTestId(
'send-message-dialog-preview',
);
}

async selectBulkAction(action: string) {
Expand Down Expand Up @@ -89,6 +93,51 @@ class RegistrationsPage extends BasePage {
throw new Error('Registration not found');
}

async performActionOnRegistrationByName({
registrationName,
action,
}: {
registrationName: string;
action: string;
}) {
await this.page.waitForLoadState('domcontentloaded');
await this.page.waitForLoadState('networkidle');
const rowCount = await this.table.tableRows.count();
for (let i = 0; i <= rowCount; i++) {
const fullName = await this.table.getCell(i, 2);
const fullNameText = (await fullName.textContent())?.trim();
const isRequestedFullName = fullNameText?.includes(registrationName);

if (
(registrationName && isRequestedFullName) ||
(!registrationName && !isRequestedFullName)
) {
await this.performActionWithRightClick(action, i);
return;
}
}
throw new Error('Registration not found');
}

async cancelSendMessageBulkAction() {
await this.page.getByRole('button', { name: 'Cancel' }).click();
}

async validateSendMessagePaCount(count: number) {
const dialogText = await this.sendMessageDialogPreview.innerText();

// Extract the number from the dialog text
const regex = /(\d+)/;
const match = regex.exec(dialogText);
if (!match) {
throw new Error('Dialog text does not match expected format');
}

const actualCount = parseInt(match[1], 10);
// Validate the count
expect(actualCount).toBe(count);
}

async goToRandomRegistration() {
const rowCount = await this.table.tableRows.count();
const randomIndex = Math.floor(Math.random() * rowCount);
Expand All @@ -98,6 +147,20 @@ class RegistrationsPage extends BasePage {
await this.goToProfileOption.click();
return randomIndex;
}

async selectMultipleRegistrations(selectionCount: number) {
await this.page.waitForLoadState('domcontentloaded');
await this.page.waitForLoadState('networkidle');
for (let i = 1; i <= selectionCount; i++) {
const rowCheckbox = await this.table.getCell(i, 0);
await rowCheckbox.click();
}
}

async performActionWithRightClick(action: string, row = 0) {
await this.table.tableRows.nth(row).click({ button: 'right' });
await this.page.getByLabel(action).click();
}
}

export default RegistrationsPage;
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { test } from '@playwright/test';

import { SeedScript } from '@121-service/src/scripts/seed-script.enum';
import { seedIncludedRegistrations } from '@121-service/test/helpers/registration.helper';
import { resetDB } from '@121-service/test/helpers/utility.helper';
import { getAccessToken } from '@121-service/test/helpers/utility.helper';
import { registrationsPV } from '@121-service/test/registrations/pagination/pagination-data';

import BasePage from '@121-e2e/portalicious/pages/BasePage';
import LoginPage from '@121-e2e/portalicious/pages/LoginPage';
import RegistrationsPage from '@121-e2e/portalicious/pages/RegistrationsPage';

test.beforeEach(async ({ page }) => {
await resetDB(SeedScript.nlrcMultiple);
const programIdPV = 2;
const pvProgramId = programIdPV;

const accessToken = await getAccessToken();
await seedIncludedRegistrations(registrationsPV, pvProgramId, accessToken);

// Login
const loginPage = new LoginPage(page);
await page.goto('/');
await loginPage.login(
process.env.USERCONFIG_121_SERVICE_EMAIL_ADMIN,
process.env.USERCONFIG_121_SERVICE_PASSWORD_ADMIN,
);
});

test('[31197] Selection should show correct PA count for bulk action (Multiple PAs)', async ({
page,
}) => {
const basePage = new BasePage(page);
const registrations = new RegistrationsPage(page);

const projectTitle = 'NLRC Direct Digital Aid Program (PV)';

await test.step('Select program', async () => {
await basePage.selectProgram(projectTitle);
});

await test.step('Apply bulk action on multiple PAs', async () => {
// Select on to trigger the first count of bulk action
await registrations.performActionOnRegistrationByName({
registrationName: 'Gemma Houtenbos',
action: 'Message',
});
await registrations.validateSendMessagePaCount(1);
await registrations.cancelSendMessageBulkAction();
// Select couple of PAs to trigger the second count of bulk action
await registrations.selectMultipleRegistrations(2);
await registrations.performActionWithRightClick('Message');
await registrations.validateSendMessagePaCount(2);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { test } from '@playwright/test';

import { SeedScript } from '@121-service/src/scripts/seed-script.enum';
import { seedIncludedRegistrations } from '@121-service/test/helpers/registration.helper';
import { resetDB } from '@121-service/test/helpers/utility.helper';
import { getAccessToken } from '@121-service/test/helpers/utility.helper';
import { registrationsPV } from '@121-service/test/registrations/pagination/pagination-data';

import BasePage from '@121-e2e/portalicious/pages/BasePage';
import LoginPage from '@121-e2e/portalicious/pages/LoginPage';
import RegistrationsPage from '@121-e2e/portalicious/pages/RegistrationsPage';

test.beforeEach(async ({ page }) => {
await resetDB(SeedScript.nlrcMultiple);
const programIdPV = 2;
const pvProgramId = programIdPV;

const accessToken = await getAccessToken();
await seedIncludedRegistrations(registrationsPV, pvProgramId, accessToken);

// Login
const loginPage = new LoginPage(page);
await page.goto('/');
await loginPage.login(
process.env.USERCONFIG_121_SERVICE_EMAIL_ADMIN,
process.env.USERCONFIG_121_SERVICE_PASSWORD_ADMIN,
);
});

test('[31196] Selection should show correct PA count for bulk action (Single PA)', async ({
page,
}) => {
const basePage = new BasePage(page);
const registrations = new RegistrationsPage(page);

const projectTitle = 'NLRC Direct Digital Aid Program (PV)';

await test.step('Select program', async () => {
await basePage.selectProgram(projectTitle);
});

await test.step('Apply bulk action on one PA', async () => {
await registrations.performActionOnRegistrationByName({
registrationName: 'Gemma Houtenbos',
action: 'Message',
});
await registrations.validateSendMessagePaCount(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ <h3>
@let previewMessageData = previewData();

@if (!previewMessageData) {
<p>
<p data-testid="send-message-dialog-preview">
<ng-container i18n="@@send-message-dialog-preview"
>You're about to <strong>send a message</strong> to
{{ actionData()?.count }} registration(s).</ng-container
Expand Down

0 comments on commit 5a87a35

Please sign in to comment.