Skip to content

Commit

Permalink
UHF-10149: Add tests for after submit messaging (#1590)
Browse files Browse the repository at this point in the history
* Add tests for after submit messaging

* Add tests for after submit messaging

* UHF-10149: Add attachment test to messaging

* UHF-10149: Fix variable name

* UHF-10149: Remove one await

---------

Co-authored-by: Janne Suominen <[email protected]>
  • Loading branch information
jeremysteerio and jiisuominen authored Dec 9, 2024
1 parent b71dfd8 commit 6236e03
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 5 deletions.
2 changes: 1 addition & 1 deletion e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ The file should be located in the `/e2e` directory.
Example `.env` file:
```
# =======================
# ENVIRONEMNT VARIABLES
# ENVIRONMENT VARIABLES
#
# Copy this file to create a .env file and make necessary changes.
# NOTE! Copy the relevant values from local.settings.php to these environment variables.
Expand Down
23 changes: 20 additions & 3 deletions e2e/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,22 @@ const waitForTextWithInterval = async (
}
}

/**
* The getFulfilledResponse function.
*
* Wait for a fulfilled response from a request.
*
* @param page
* Playwright page object
*/
async function getFulfilledResponse(page: Page) {
const response = await page.waitForResponse(async (response) => {
return response.ok();
});

return response.json();
}

/**
* The logCurrentUrl function.
*
Expand All @@ -169,11 +185,12 @@ const logCurrentUrl = async (page: Page) => {
}

export {
slowLocator,
extractPath,
hideSlidePopup,
getApplicationNumberFromBreadCrumb,
waitForTextWithInterval,
getFulfilledResponse,
hideSlidePopup,
logCurrentUrl,
slowLocator,
waitForTextWithInterval,
};

86 changes: 85 additions & 1 deletion e2e/utils/validation_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import {logger} from "./logger";
import {FormField, FormData, FormFieldWithRemove} from "./data/test_data"
import {viewPageBuildSelectorForItem} from "./view_page_helpers";
import {PROFILE_INPUT_DATA, ProfileInputData} from "./data/profile_input_data";
import {logCurrentUrl} from "./helpers";
import {getFulfilledResponse, logCurrentUrl} from "./helpers";
import { uploadFile } from './input_helpers';
import { ATTACHMENTS } from './data/attachment_data';

/**
* The pageType type.
Expand Down Expand Up @@ -49,6 +51,10 @@ const validateSubmission = async (
await navigateAndValidateViewPage(page, thisStoreData);
await validateFormData(page, 'viewPage', formDetails);
}
if (thisStoreData.status === 'RECEIVED') {
logger(`Validating messaging for sent application with application ID: ${thisStoreData.applicationId}...`);
await validateMessaging(page, thisStoreData);
}
}

/**
Expand Down Expand Up @@ -424,6 +430,84 @@ const navigateAndValidateViewPage = async (
logger('Draft validation on page:', viewPageURL);
}

/**
* The validateMessaging function.
*
* This function validates messaging after
* form submitting works as intended.
*
* @param page
* Page object from Playwright.
* @param thisStoreData
* The env form data.
*/
const validateMessaging = async (
page: Page,
thisStoreData: any
) => {
const { applicationId } = thisStoreData;
const viewPageUrl = `/fi/hakemus/${applicationId}/katso`;

await page.goto(viewPageUrl);
await logCurrentUrl(page);
await page.waitForURL('**/katso');

const formActionButton = page.locator('form.grants-handler-message button.form-submit[name="op"]');
const textArea = page.locator('textarea[name="message"]');

// Validate error on empty message.
await formActionButton.click();
await page.waitForSelector('form.grants-handler-message .hds-notification--error');
await expect(page.locator('form.grants-handler-message .hds-notification--error')).toBeVisible();
await expect(page.locator('form.grants-handler-message .hds-notification--error .hds-notification__body')).toHaveText('1 virhe löytyi: Viesti');

// Validate sending message works.
await textArea.fill('Test message');

await formActionButton.click();
const responseBody = await getFulfilledResponse(page);
await expect(responseBody.length).toBe(4);

await page.waitForSelector('form.grants-handler-message .hds-notification--info');
const infoMessage = page.locator('form.grants-handler-message .hds-notification--info');
await expect(infoMessage).toBeVisible();
await expect(page.locator('form.grants-handler-message .hds-notification--info .hds-notification__body')).toContainText('Viestisi on lähetetty.');
await expect(formActionButton).toHaveText('Uusi viesti');

// Reload page to see message list.
await page.reload();
await page.waitForSelector('ul.webform-submission-messages__messages-list');

// Validate sending additional messages.
await textArea.fill('Test message 2');
await formActionButton.click();
const secondSubmitBody = await getFulfilledResponse(page);
expect(secondSubmitBody.length).toBe(4);
await page.waitForSelector('ul.webform-submission-messages__messages-list > h5');

const messages = await page.locator('.webform-submission-messages__messages-list .webform-submission-messages__message-body').all();
expect(messages.length).toEqual(2);
await expect(messages[0]).toContainText('Test message');
await expect(messages[1]).toContainText('Test message 2');

// Test adding attachment.
await formActionButton.click();
await textArea.fill('Attachment test message');
await uploadFile(
page,
'form.grants-handler-message .form-file',
'form.grants-handler-message .form-managed-file a',
ATTACHMENTS.MUU_LIITE,
);
await page.locator('input[name="attachmentDescription"]').fill('Attachment test description');
await formActionButton.click();

await expect(infoMessage).toBeVisible();
await expect(page.locator('form.grants-handler-message .hds-notification--info .hds-notification__body')).toContainText('Viestisi on lähetetty.');

logger('Message validation successful!');
}

/**
* The navigateAndValidatePrintPage function.
*
Expand Down

0 comments on commit 6236e03

Please sign in to comment.