|
| 1 | +import {MBCPageBase} from './mbc-page-base'; |
| 2 | +import {expect, Locator, Page} from '@playwright/test'; |
| 3 | +import {waitForNoSpinner} from 'utils/test-utils'; |
| 4 | +import Question from '../../component/Question'; |
| 5 | + |
| 6 | +type yesNoDontKnow = 'Yes' | 'No' | "I don't know"; |
| 7 | + |
| 8 | +interface MedicationDetails { |
| 9 | + medication: string, |
| 10 | + startDate: { |
| 11 | + month: string, |
| 12 | + year: string |
| 13 | + }, |
| 14 | + endDate?: { |
| 15 | + month: string, |
| 16 | + year: string |
| 17 | + } |
| 18 | +} |
| 19 | + |
| 20 | +export class MBCFollowUpSurvey1 extends MBCPageBase { |
| 21 | + private readonly pageTitle: Locator; |
| 22 | + private readonly title = 'Follow-up survey #1: Additional details about your cancer & treatments'; |
| 23 | + |
| 24 | + constructor(page: Page) { |
| 25 | + super(page); |
| 26 | + this.pageTitle = this.page.locator('h1.PageHeader-title'); |
| 27 | + } |
| 28 | + |
| 29 | + public async waitForReady(): Promise<void> { |
| 30 | + await expect(this.pageTitle).toHaveText(this.title); |
| 31 | + await waitForNoSpinner(this.page); |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * <br> Question: Please select all the places in your body where you currently have metastatic breast cancer to the best of your knowledge (select all that apply). If you don’t have any detectable disease please select No Evidence of Disease (NED). |
| 36 | + */ |
| 37 | + public async currentCancerLocation(answer: string): Promise<void> { |
| 38 | + const question = new Question(this.page, {cssClassAttribute: '.picklist-answer-CURRENT_CANCER_LOC'}); |
| 39 | + await question.toCheckbox(answer).check(); |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * <br> Question: When you were first diagnosed with metastatic breast cancer, where were all of the places in your body that it was detected (select all that apply)? |
| 44 | + */ |
| 45 | + public async diagnosisCancerLocation(answer: string): Promise<void> { |
| 46 | + const question = new Question(this.page, {cssClassAttribute: '.picklist-answer-DIAGNOSIS_CANCER_LOC'}); |
| 47 | + await question.toCheckbox(answer).check(); |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * <br> Question: Please select all of the places in your body that metastatic breast cancer has been found at any time (select all that apply)? |
| 52 | + */ |
| 53 | + public async anytimeCancerLocation(answer: string): Promise<void> { |
| 54 | + const question = new Question(this.page, {cssClassAttribute: '.picklist-answer-ANYTIME_CANCER_LOC'}); |
| 55 | + await question.toCheckbox(answer).check(); |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * <br> Question: Was your breast cancer identified as any of the following at any time (select all that apply)? |
| 60 | + */ |
| 61 | + public async cancerIdentification(answer: string): Promise<void> { |
| 62 | + const question = new Question(this.page, {cssClassAttribute: '.picklist-answer-CANCER_IDENTIFICATION'}); |
| 63 | + await question.toCheckbox(answer).check(); |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * <br> Question: Are you currently receiving any medications/chemotherapies for treatment of your metastatic breast cancer? |
| 68 | + */ |
| 69 | + public async currentlyMedicated(answer: yesNoDontKnow, opts?: MedicationDetails): Promise<void> { |
| 70 | + await new Question(this.page, {cssClassAttribute: '.picklist-answer-CURRENTLY_MEDICATED'}) |
| 71 | + .radioButton(answer, {exactMatch: true}).click(); |
| 72 | + if (opts) { |
| 73 | + await this.currentMedicationAnswer(opts); |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + /** |
| 78 | + * <br> Question: Have you received any other medications/chemotherapies in the past for treatment of your metastatic breast cancer? |
| 79 | + */ |
| 80 | + public async previouslyMedicated(answer: yesNoDontKnow, opts?: MedicationDetails): Promise<void> { |
| 81 | + await new Question(this.page, {cssClassAttribute: '.picklist-answer-PREVIOUSLY_MEDICATED'}) |
| 82 | + .radioButton(answer, {exactMatch: true}).click(); |
| 83 | + if (opts) { |
| 84 | + await this.pastMedicationAnswer(opts); |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + /* Helper functions */ |
| 89 | + private async currentMedicationAnswer(opts: MedicationDetails): Promise<void> { |
| 90 | + await this.page.waitForLoadState('networkidle'); |
| 91 | + |
| 92 | + if (opts?.medication) { |
| 93 | + const medication = new Question(this.page, {cssClassAttribute: '.composite-answer-CURRENT_MED_LIST'}); |
| 94 | + await medication.toInput().fill(opts.medication); |
| 95 | + } |
| 96 | + |
| 97 | + await this.fillCurrentAndPastMedicationDates('CURRENT', opts); |
| 98 | + } |
| 99 | + |
| 100 | + private async pastMedicationAnswer(opts: MedicationDetails): Promise<void> { |
| 101 | + if (opts?.medication) { |
| 102 | + const medication = new Question(this.page, {cssClassAttribute: '.composite-answer-PAST_MED_LIST'}); |
| 103 | + await medication.toInput().fill(opts.medication); |
| 104 | + } |
| 105 | + await this.fillCurrentAndPastMedicationDates('PAST', opts); |
| 106 | + } |
| 107 | + |
| 108 | + private async fillCurrentAndPastMedicationDates(cssClassPart: 'CURRENT' | 'PAST', { |
| 109 | + startDate, |
| 110 | + endDate |
| 111 | + }: MedicationDetails): Promise<void> { |
| 112 | + if (startDate) { |
| 113 | + const startDateQuestion = new Question(this.page, |
| 114 | + { |
| 115 | + cssClassAttribute: '.picklist', |
| 116 | + parentSelector: this.page.locator(`.date-answer-${cssClassPart}_MED_START`) |
| 117 | + }); |
| 118 | + await startDateQuestion.toSelect('Choose month...') |
| 119 | + .toLocator() |
| 120 | + .selectOption(startDate.month); |
| 121 | + |
| 122 | + await startDateQuestion.toSelect('Choose year...') |
| 123 | + .toLocator() |
| 124 | + .selectOption(startDate.year) |
| 125 | + } |
| 126 | + |
| 127 | + if (endDate) { |
| 128 | + const endDateQuestion = new Question(this.page, |
| 129 | + { |
| 130 | + cssClassAttribute: '.picklist', |
| 131 | + parentSelector: this.page.locator(`.date-answer-${cssClassPart}_MED_END`) |
| 132 | + } |
| 133 | + ); |
| 134 | + await endDateQuestion.toSelect('Choose month...') |
| 135 | + .toLocator() |
| 136 | + .selectOption(endDate.month); |
| 137 | + |
| 138 | + await endDateQuestion.toSelect('Choose year...') |
| 139 | + .toLocator() |
| 140 | + .selectOption(endDate.year); |
| 141 | + } |
| 142 | + } |
| 143 | +} |
0 commit comments