diff --git a/playwright-e2e/dsm/pages/participant-page/rgp/family-member-tab.ts b/playwright-e2e/dsm/pages/participant-page/rgp/family-member-tab.ts index 0c760bdece..bbe4703276 100644 --- a/playwright-e2e/dsm/pages/participant-page/rgp/family-member-tab.ts +++ b/playwright-e2e/dsm/pages/participant-page/rgp/family-member-tab.ts @@ -1,6 +1,7 @@ import { expect, Locator, Page } from '@playwright/test'; import { FamilyMember } from 'dsm/component/tabs/enums/familyMember-enum'; import TextArea from 'dss/component/textarea'; +import { find } from 'lodash'; import { waitForResponse } from 'utils/test-utils'; /** @@ -109,6 +110,11 @@ export default class FamilyMemberTab { return this.page.getByRole('tabpanel').getByText('Jump to:'); } + //todo Should probably make this a more general method to be applied across studies + public getSurveyDataTab(): Locator { + return this.page.locator(`//app-participant-page//ul//a[contains(., 'Survey Data')]`); + } + public getParticipantInfoMenuLink(): Locator { return this.page.getByRole('tabpanel').locator('a').filter({ hasText: 'Participant Info' }); } @@ -278,11 +284,13 @@ export default class FamilyMemberTab { */ public async inputMixedRaceNotes(notes: string): Promise { const textarea = new TextArea(this.page, {label: 'Mixed Race Notes'}); + console.log(`Previous text: ${await textarea.getText()}`); await textarea.clear(); await Promise.all([ waitForResponse(this.page, {uri: 'ui/patch'}), - textarea.fill(notes) + textarea.fill(notes), ]); + console.log(`New text: ${await textarea.getText()}`); } /** @@ -290,7 +298,7 @@ export default class FamilyMemberTab { * @returns contents of the Mixed Race Notes textarea */ public async getMixedRaceNotesContent(): Promise { - return (await this.page.locator("//textarea[contains(@data-placeholder, 'Mixed Race Notes')]").inputValue()).toString(); + return new TextArea(this.page, {label: 'Mixed Race Notes'}).getText(); } /** @@ -642,7 +650,51 @@ export default class FamilyMemberTab { return this.page.locator("//td[contains(text(), 'RedCap Survey Completed Date')]/following-sibling::td//div/input"); } + public getTellUsAboutYourFamilySection(): Locator { + return this.page.locator(`//app-activity-data//mat-expansion-panel[@id='ENROLLMENT']`); + } + + private howDidYouFindOutAboutThisProjectSection(): Locator { + return this.page.locator(`//app-activity-data//h5[contains(., 'FIND_OUT')]`); + } + + private async getAllParticipantReferralSources(): Promise { + //const findOutSection = this.howDidYouFindOutAboutThisProjectSection(); + //Uses the following xpath to get all listed sources: //app-activity-data//h5[contains(., 'FIND_OUT')]/parent::div//div//ul[@class='ng-star-inserted'] + //return findOutSection.locator(`/parent::div//div//ul[contains(@class, 'ng-star-inserted')]`).all(); + return this.page.locator(`//app-activity-data//h5[contains(., 'FIND_OUT')]/parent::div//div//ul[@class='ng-star-inserted']`).all(); + } + + private getSingleReferralSource(): Locator { + const findOutSection = this.howDidYouFindOutAboutThisProjectSection(); + return findOutSection.locator(`/parent::div//div//ul[@class='ng-star-inserted']//li//b`); + } + /* Utility methods */ + public async getStudyParticipantResponseForReferralSource(): Promise { + const surveyData = this.getSurveyDataTab(); + await surveyData.click(); + await expect(surveyData, 'ERROR - RGP: Survey Data tab is not selected').toHaveAttribute('aria-selected', 'true'); + + const tellUsAboutYourFamilySection = this.getTellUsAboutYourFamilySection(); + await expect(tellUsAboutYourFamilySection, 'ERROR - RGP: Tell Us About Your Family section is not visible in Survey Data tab').toBeVisible(); + await tellUsAboutYourFamilySection.click(); + + const participantReferralSources = this.getAllParticipantReferralSources(); + const amountOfReferralSources = (await participantReferralSources).length; + let referralSource = 'unknown'; + + //Determine the official referral source based on how many sources the study participant selected/provided + if (amountOfReferralSources === 0) { + referralSource = 'Not provided'; + } else if (amountOfReferralSources === 1) { + referralSource = await this.getSingleReferralSource().innerText(); + } else if (amountOfReferralSources > 1) { + referralSource = 'More than one'; + } + return referralSource; + } + public async setRandomRelationshipID(): Promise { const usedRelationshipIDs = await this.getListOfUsedSubjectIDs(); let searchingForID = true; diff --git a/playwright-e2e/tests/rgp/dsm-family-enrollment.spec.ts b/playwright-e2e/tests/rgp/dsm-family-enrollment.spec.ts index a0167e9b99..9c81f86ad0 100644 --- a/playwright-e2e/tests/rgp/dsm-family-enrollment.spec.ts +++ b/playwright-e2e/tests/rgp/dsm-family-enrollment.spec.ts @@ -15,6 +15,7 @@ import { v4 as uuid } from 'uuid'; import ParticipantPage from 'dsm/pages/participant-page/participant-page'; import { WelcomePage } from 'dsm/pages/welcome-page'; import { StudyEnum } from 'dsm/component/navigation/enums/selectStudyNav-enum'; +import * as crypto from 'crypto'; test.describe.serial('DSM Family Enrollment Handling', () => { @@ -104,8 +105,8 @@ test.describe.serial('DSM Family Enrollment Handling', () => { saveParticipantGuid(participantGuid); await participantListPage.filterListByParticipantGUID(user.patient.participantGuid); //Check that the filtered list returns at least one participant - const filteredList = page.locator('tr.ng-star-inserted'); - await expect(filteredList).toHaveCount(1); + const filteredList = await participantListTable.numOfParticipants(); + expect(filteredList).toBe(1); await participantListTable.openParticipantPageAt(0); //Verify that the proband tab is present (and includes the text RGP and 3 as proband subject ids have the format RGP_{family id}_3) @@ -239,7 +240,7 @@ test.describe.serial('DSM Family Enrollment Handling', () => { const familyAccount = new RgpParticipantPage(page); await familyAccount.backToList(); await participantListPage.filters.searchPanel.search(); - await expect(filteredList).toHaveCount(1); + expect(filteredList).toBe(1); await participantListTable.openParticipantPageAt(0); //After refreshing participant list and page, check that the input for the above textareas are as expected @@ -251,10 +252,12 @@ test.describe.serial('DSM Family Enrollment Handling', () => { //Checking textarea content const importantNotesTextarea = proband.getImportantNotes(); const processNotesTextarea = proband.getProcessNotes(); - const mixedRaceTextarea = proband.getMixedRaceNotes(); + //const mixedRaceTextarea = proband.getMixedRaceNotes(); + const mixedRaceTextarea = await proband.getMixedRaceNotesContent(); expect(await importantNotesTextarea.inputValue()).toBe(importantNotes); expect(await processNotesTextarea.inputValue()).toBe(processNotes); - expect(await mixedRaceTextarea.inputValue()).toBe(mixedRaceNotes); + expect(mixedRaceTextarea).toBe(mixedRaceTestingNotes); + //expect(await mixedRaceTextarea.inputValue()).toBe(mixedRaceNotes); //Fill out Contact Info section const contactInfoSection = proband.getContactInfoSection(); @@ -364,10 +367,20 @@ test.describe.serial('DSM Family Enrollment Handling', () => { const familyProvidedURL = proband.getFamilyUrlProvided(); await familyProvidedURL.fill('https://en.wikipedia.org/wiki/Broad_Institute'); - //todo Update testing Referral Source to check for functionality from ticket PEPPER-575 (ticket in-progress) + //Check Survey Data to get the referral source and then check the proband tab to make sure the related source is selected as expected + const surveyData = proband.getSurveyDataTab(); + await surveyData.scrollIntoViewIfNeeded(); + await surveyData.click(); + + const participantReferralSource = await proband.getStudyParticipantResponseForReferralSource(); + console.log(`Participant Referral Source: ${participantReferralSource}`); + await probandTab.click(); + await medicalRecordsSection.click(); + const referralSource = proband.getReferralSource(); - await referralSource.click(); - await dropdownOptions.filter({ hasText: 'Doctor' }).click(); + await referralSource.scrollIntoViewIfNeeded(); + await expect(referralSource, `RGP Referral Source - Expected '${participantReferralSource}' but got: ${await referralSource.innerText()}`) + .toHaveText(participantReferralSource); await proband.inputReferralNotes('Testing notes here - Referral Notes');