|
| 1 | +import { APIRequestContext, expect, Page } from '@playwright/test'; |
| 2 | +import { MiscellaneousEnum } from 'dsm/component/navigation/enums/miscellaneousNav-enum'; |
| 3 | +import { Navigation } from 'dsm/component/navigation/navigation'; |
| 4 | +import PreviousSurveysTable from 'dsm/component/tables/previous-surveys-table'; |
| 5 | +import { WelcomePage } from 'dsm/pages/welcome-page'; |
| 6 | +import Button from 'dss/component/button'; |
| 7 | +import Input from 'dss/component/input'; |
| 8 | +import Select from 'dss/component/select'; |
| 9 | +import { waitForNoSpinner } from 'utils/test-utils'; |
| 10 | + |
| 11 | +export default class FollowUpSurveyPage { |
| 12 | + private readonly _table: PreviousSurveysTable = new PreviousSurveysTable(this.page); |
| 13 | + |
| 14 | + static async goto(page: Page, study: string, request: APIRequestContext): Promise<FollowUpSurveyPage> { |
| 15 | + const welcomePage = new WelcomePage(page); |
| 16 | + await welcomePage.selectStudy(study); |
| 17 | + |
| 18 | + const navigation = new Navigation(page, request); |
| 19 | + await navigation.selectMiscellaneous(MiscellaneousEnum.FOLLOW_UP_SURVEY); |
| 20 | + const followUpPage = new FollowUpSurveyPage(page); |
| 21 | + await followUpPage.waitForReady(); |
| 22 | + return followUpPage; |
| 23 | + } |
| 24 | + |
| 25 | + constructor(private readonly page: Page) {} |
| 26 | + |
| 27 | + public get previousSurveysTable(): PreviousSurveysTable { |
| 28 | + return this._table; |
| 29 | + } |
| 30 | + |
| 31 | + public async waitForReady(): Promise<void> { |
| 32 | + await expect(this.page.locator('h1')).toHaveText(/^\s*Follow-Up Survey\s*$/); |
| 33 | + await expect(this.select().toLocator()).toBeVisible({ timeout: 30000 }); |
| 34 | + await waitForNoSpinner(this.page); |
| 35 | + } |
| 36 | + |
| 37 | + public async selectSurvey(survey: string): Promise<void> { |
| 38 | + await this.select().selectOption(survey); |
| 39 | + await waitForNoSpinner(this.page); |
| 40 | + } |
| 41 | + |
| 42 | + public async participantId(id: string): Promise<void> { |
| 43 | + const input = new Input(this.page, { label: 'Participant ID' }); |
| 44 | + await input.fill(id); |
| 45 | + } |
| 46 | + |
| 47 | + public async reasonForFollowUpSurvey(reason: string): Promise<void> { |
| 48 | + const input = new Input(this.page, { label: 'Reason for Follow-Up Survey' }); |
| 49 | + await input.fill(reason); |
| 50 | + } |
| 51 | + |
| 52 | + public async createSurvey(): Promise<void> { |
| 53 | + const button = new Button(this.page, { label: 'Create Survey', root: 'app-survey' }); |
| 54 | + await button.click(); |
| 55 | + await waitForNoSpinner(this.page); |
| 56 | + } |
| 57 | + |
| 58 | + public select(): Select { |
| 59 | + return new Select(this.page, { label: 'Survey', root: 'app-survey' }); |
| 60 | + } |
| 61 | + |
| 62 | + public async reloadTable(): Promise<void> { |
| 63 | + const button = new Button(this.page, { label: 'Reload', root: 'app-survey' }); |
| 64 | + await button.click(); |
| 65 | + await waitForNoSpinner(this.page); |
| 66 | + } |
| 67 | +} |
0 commit comments