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 test cases for selection behaviour #6048

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
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
Loading