mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
3.3 KiB
87 lines
3.3 KiB
2 years ago
|
import { expect, Locator, Page } from '@playwright/test';
|
||
|
import BasePage from '../../Base';
|
||
2 years ago
|
|
||
|
export class SurveyFormPage extends BasePage {
|
||
|
readonly formHeading: Locator;
|
||
|
readonly formSubHeading: Locator;
|
||
|
readonly submitButton: Locator;
|
||
|
readonly nextButton: Locator;
|
||
|
readonly nextSlideButton: Locator;
|
||
|
readonly prevSlideButton: Locator;
|
||
|
readonly darkModeButton: Locator;
|
||
|
readonly formFooter: Locator;
|
||
|
|
||
|
constructor(rootPage: Page) {
|
||
|
super(rootPage);
|
||
2 years ago
|
this.formHeading = this.get().locator('[data-nc="nc-survey-form__heading"]');
|
||
|
this.formSubHeading = this.get().locator('[data-nc="nc-survey-form__sub-heading"]');
|
||
|
this.submitButton = this.get().locator('[data-nc="nc-survey-form__btn-submit"]');
|
||
|
this.nextButton = this.get().locator('[data-nc="nc-survey-form__btn-next"]');
|
||
|
this.nextSlideButton = this.get().locator('[data-nc="nc-survey-form__icon-next"]');
|
||
|
this.prevSlideButton = this.get().locator('[data-nc="nc-survey-form__icon-prev"]');
|
||
|
this.darkModeButton = this.get().locator('[data-nc="nc-form-dark-mode"]');
|
||
|
this.formFooter = this.get().locator('[data-nc="nc-survey-form__footer"]');
|
||
2 years ago
|
}
|
||
|
|
||
|
get() {
|
||
2 years ago
|
return this.rootPage.locator('html >> .nc-form-view');
|
||
2 years ago
|
}
|
||
|
|
||
|
async validate({
|
||
|
heading,
|
||
|
subHeading,
|
||
|
fieldLabel,
|
||
|
footer,
|
||
|
}: {
|
||
|
heading: string;
|
||
|
subHeading: string;
|
||
|
fieldLabel: string;
|
||
|
footer: string;
|
||
|
}) {
|
||
|
await expect(this.get()).toBeVisible();
|
||
|
await expect(this.formHeading).toHaveText(heading);
|
||
|
await expect(this.formSubHeading).toHaveText(subHeading);
|
||
|
await expect(this.formFooter).toHaveText(footer);
|
||
2 years ago
|
await expect(this.get().locator(`[data-nc="nc-form-column-label"]`)).toHaveText(fieldLabel);
|
||
2 years ago
|
|
||
|
// parse footer text ("1 / 3") to identify if last slide
|
||
|
let isLastSlide = false;
|
||
|
const footerText = await this.formFooter.innerText();
|
||
2 years ago
|
const slideNumber = footerText.split(' / ')[0];
|
||
|
const totalSlides = footerText.split(' / ')[1];
|
||
2 years ago
|
if (slideNumber === totalSlides) {
|
||
|
isLastSlide = true;
|
||
|
}
|
||
|
if (isLastSlide) {
|
||
|
await expect(this.submitButton).toBeVisible();
|
||
|
} else {
|
||
|
await expect(this.nextButton).toBeVisible();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
async fill(param: { fieldLabel: string; type?: string; value?: string }) {
|
||
2 years ago
|
await this.get().locator(`[data-nc="nc-survey-form__input-${param.fieldLabel}"]`).click();
|
||
2 years ago
|
if (param.type === 'SingleLineText') {
|
||
2 years ago
|
await this.get().locator(`[data-nc="nc-survey-form__input-${param.fieldLabel}"] >> input`).fill(param.value);
|
||
2 years ago
|
// press enter key
|
||
2 years ago
|
await this.get().locator(`[data-nc="nc-survey-form__input-${param.fieldLabel}"] >> input`).press('Enter');
|
||
2 years ago
|
} else if (param.type === 'DateTime') {
|
||
|
const modal = await this.rootPage.locator('.nc-picker-datetime');
|
||
2 years ago
|
await expect(modal).toBeVisible();
|
||
2 years ago
|
await modal.locator('.ant-picker-now-btn').click();
|
||
|
await modal.locator('.ant-picker-ok').click();
|
||
2 years ago
|
await this.nextButton.click();
|
||
|
}
|
||
|
}
|
||
|
|
||
2 years ago
|
async validateSuccessMessage(param: { message: string; showAnotherForm?: boolean }) {
|
||
2 years ago
|
await expect(
|
||
2 years ago
|
this.get().locator(`[data-nc="nc-survey-form__success-msg"]:has-text("${param.message}")`)
|
||
2 years ago
|
).toBeVisible();
|
||
|
|
||
|
if (param.showAnotherForm) {
|
||
2 years ago
|
await expect(this.get().locator(`button:has-text("Submit Another Form")`)).toBeVisible();
|
||
2 years ago
|
}
|
||
|
}
|
||
|
}
|