Skip to content

Commit

Permalink
Add test for multiplie selection count
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotrk39 committed Nov 8, 2024
1 parent 43ec73f commit aa7d17b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 36 deletions.
25 changes: 19 additions & 6 deletions e2e/portalicious/pages/RegistrationsPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ class RegistrationsPage extends BasePage {
throw new Error('Registration not found');
}

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

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

Expand All @@ -131,13 +135,8 @@ class RegistrationsPage extends BasePage {
}

const actualCount = parseInt(match[1], 10);

// Validate the count
if (actualCount !== count) {
throw new Error(
`Expected ${count} registrations, but found ${actualCount}`,
);
}
expect(actualCount).toBe(count);
}

async goToRandomRegistration() {
Expand All @@ -149,6 +148,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) {
await this.table.tableRows.nth(0).click({ button: 'right' });
await this.page.getByLabel(action).click();
}
}

export default RegistrationsPage;
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import { registrationsPV } from '@121-service/test/registrations/pagination/pagi

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

test.beforeEach(async ({ page }) => {
await resetDB(SeedScript.nlrcMultiple);
Expand All @@ -29,43 +27,29 @@ test.beforeEach(async ({ page }) => {
);
});

test('[31077] Send custom message', async ({ page }) => {
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 activityLog = new RegistrationActivityLogPage(page);
const table = new TableComponent(page);

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

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

await test.step('Send custom message', async () => {
const registrationFullName =
await registrations.getFirstRegistrationNameFromTable();
if (!registrationFullName) {
throw new Error('Registration full name is undefined');
}
const customMessageText =
'This is {{fullName}} custom message from the Red Cross.';
const customMessagePreview = `This is ${registrationFullName} custom message from the Red Cross.`;
const sendingMessageToast =
'Closing this notification will not cancel message sending.';

await table.selectAllCheckbox();
await registrations.selectBulkAction('Message');
await registrations.selectCustomMessage();
await registrations.typeCustomMessage(customMessageText);
await registrations.clickContinueToPreview();
await registrations.validateMessagePresent(customMessagePreview);
await registrations.sendMessage();

await registrations.validateToastMessage(sendingMessageToast);
await registrations.goToRegistrationByName({
registrationName: registrationFullName,
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 activityLog.validateLastMessageSent(customMessagePreview);
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);
});
});

0 comments on commit aa7d17b

Please sign in to comment.