Browse Source

test: survey form

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>
pull/3848/head
Raju Udava 2 years ago committed by Muhammed Mustafa
parent
commit
58c520b7e4
  1. 27
      packages/nc-gui/pages/[projectType]/form/[viewId]/index/survey.vue
  2. 118
      scripts/playwright/pages/Dashboard/SurveyForm/index.ts
  3. 6
      scripts/playwright/pages/Dashboard/Toolbar/ShareView.ts
  4. 79
      scripts/playwright/tests/viewFormShareSurvey.spec.ts

27
packages/nc-gui/pages/[projectType]/form/[viewId]/index/survey.vue

@ -208,12 +208,15 @@ onMounted(() => {
class="max-w-[max(33%,600px)] mx-auto flex flex-col justify-end"
>
<div class="px-4 md:px-0 flex flex-col justify-end">
<h1 class="prose-2xl font-bold self-center my-4" data-cy="nc-survey-form__heading">{{ sharedFormView.heading }}</h1>
<h1 class="prose-2xl font-bold self-center my-4" data-cy="nc-survey-form__heading" data-pw="nc-survey-form__heading">
{{ sharedFormView.heading }}
</h1>
<h2
v-if="sharedFormView.subheading && sharedFormView.subheading !== ''"
class="prose-lg text-slate-500 dark:text-slate-300 self-center mb-4 leading-6"
data-cy="nc-survey-form__sub-heading"
data-pw="nc-survey-form__sub-heading"
>
{{ sharedFormView?.subheading }}
</h2>
@ -228,7 +231,7 @@ onMounted(() => {
class="color-transition h-full flex flex-col mt-6 gap-4 w-full max-w-[max(33%,600px)] m-auto"
>
<div v-if="field && !submitted" class="flex flex-col gap-2">
<div class="flex nc-form-column-label">
<div class="flex nc-form-column-label" data-pw="nc-form-column-label">
<LazySmartsheetHeaderVirtualCell
v-if="isVirtualCol(field)"
:column="{ ...field, title: field.label || field.title }"
@ -252,6 +255,7 @@ onMounted(() => {
class="mt-0 nc-input"
:row="{ row: {}, oldRow: {}, rowMeta: {} }"
:data-cy="`nc-survey-form__input-${field.title.replaceAll(' ', '')}`"
:data-pw="`nc-survey-form__input-${field.title.replaceAll(' ', '')}`"
:column="field"
/>
@ -260,6 +264,7 @@ onMounted(() => {
v-model="formState[field.title]"
class="nc-input"
:data-cy="`nc-survey-form__input-${field.title.replaceAll(' ', '')}`"
:data-pw="`nc-survey-form__input-${field.title.replaceAll(' ', '')}`"
:column="field"
:edit-enabled="true"
/>
@ -272,6 +277,7 @@ onMounted(() => {
<div
class="block text-[14px]"
:class="field.uidt === UITypes.Checkbox ? 'text-center' : ''"
data-pw="nc-survey-form__field-description"
data-cy="nc-survey-form__field-description"
>
{{ field.description }}
@ -297,6 +303,7 @@ onMounted(() => {
type="submit"
class="uppercase scaling-btn prose-sm"
data-cy="nc-survey-form__btn-submit"
data-pw="nc-survey-form__btn-submit"
@click="submit"
>
{{ $t('general.submit') }}
@ -312,6 +319,7 @@ onMounted(() => {
<button
class="bg-opacity-100 scaling-btn flex items-center gap-1"
data-cy="nc-survey-form__btn-next"
data-pw="nc-survey-form__btn-next"
:class="[
v$.localState[field.title]?.$error ? 'after:!bg-gray-100 after:!ring-red-500' : '',
animationTarget === AnimationTarget.OkButton && isAnimating
@ -341,7 +349,11 @@ onMounted(() => {
<Transition name="slide-left">
<div v-if="submitted" class="flex flex-col justify-center items-center text-center">
<div class="text-lg px-6 py-3 bg-green-300 text-gray-700 rounded" data-cy="nc-survey-form__success-msg">
<div
class="text-lg px-6 py-3 bg-green-300 text-gray-700 rounded"
data-cy="nc-survey-form__success-msg"
data-pw="nc-survey-form__success-msg"
>
<template v-if="sharedFormView?.success_msg">
{{ sharedFormView?.success_msg }}
</template>
@ -365,6 +377,7 @@ onMounted(() => {
type="button"
class="scaling-btn bg-opacity-100"
data-cy="nc-survey-form__btn-submit-another-form"
data-pw="nc-survey-form__btn-submit-another-form"
@click="resetForm"
>
Submit Another Form
@ -378,7 +391,11 @@ onMounted(() => {
</div>
<template v-if="!submitted">
<div class="mb-24 md:my-4 select-none text-center text-gray-500 dark:text-slate-200" data-cy="nc-survey-form__footer">
<div
class="mb-24 md:my-4 select-none text-center text-gray-500 dark:text-slate-200"
data-cy="nc-survey-form__footer"
data-pw="nc-survey-form__footer"
>
{{ index + 1 }} / {{ formColumns?.length }}
</div>
</template>
@ -398,6 +415,7 @@ onMounted(() => {
"
class="p-0.5 flex items-center group color-transition"
data-cy="nc-survey-form__icon-prev"
data-pw="nc-survey-form__icon-prev"
@click="goPrevious()"
>
<MdiChevronLeft :class="isFirst ? 'text-gray-300' : 'group-hover:text-accent'" class="text-2xl md:text-md" />
@ -417,6 +435,7 @@ onMounted(() => {
"
class="p-0.5 flex items-center group color-transition"
data-cy="nc-survey-form__icon-next"
data-pw="nc-survey-form__icon-next"
@click="goNext()"
>
<MdiChevronRight

118
scripts/playwright/pages/Dashboard/SurveyForm/index.ts

@ -0,0 +1,118 @@
// playwright-dev-page.ts
import { Page, expect, Locator } from "@playwright/test";
import BasePage from "../../Base";
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);
this.formHeading = this.get().locator(
'[data-pw="nc-survey-form__heading"]'
);
this.formSubHeading = this.get().locator(
'[data-pw="nc-survey-form__sub-heading"]'
);
this.submitButton = this.get().locator(
'[data-pw="nc-survey-form__btn-submit"]'
);
this.nextButton = this.get().locator(
'[data-pw="nc-survey-form__btn-next"]'
);
this.nextSlideButton = this.get().locator(
'[data-pw="nc-survey-form__icon-next"]'
);
this.prevSlideButton = this.get().locator(
'[data-pw="nc-survey-form__icon-prev"]'
);
this.darkModeButton = this.get().locator('[data-pw="nc-form-dark-mode"]');
this.formFooter = this.get().locator('[data-pw="nc-survey-form__footer"]');
}
get() {
return this.rootPage.locator("html >> .nc-form-view");
}
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);
await expect(
this.get().locator(`[data-pw="nc-form-column-label"]`)
).toHaveText(fieldLabel);
// parse footer text ("1 / 3") to identify if last slide
let isLastSlide = false;
const footerText = await this.formFooter.innerText();
const slideNumber = footerText.split(" / ")[0];
const totalSlides = footerText.split(" / ")[1];
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 }) {
await this.get()
.locator(`[data-pw="nc-survey-form__input-${param.fieldLabel}"]`)
.click();
if (param.type === "SingleLineText") {
await this.get()
.locator(
`[data-pw="nc-survey-form__input-${param.fieldLabel}"] >> input`
)
.fill(param.value);
// press enter key
await this.get()
.locator(
`[data-pw="nc-survey-form__input-${param.fieldLabel}"] >> input`
)
.press("Enter");
} else if (param.type === "DateTime") {
const modal = await this.rootPage.locator(".nc-picker-datetime");
await expect(modal).toBeVisible();
await modal.locator(".ant-picker-now-btn").click();
await modal.locator(".ant-picker-ok").click();
await this.nextButton.click();
}
}
async validateSuccessMessage(param: {
message: string;
showAnotherForm?: boolean;
}) {
await expect(
this.get().locator(
`[data-pw="nc-survey-form__success-msg"]:has-text("${param.message}")`
)
).toBeVisible();
if (param.showAnotherForm) {
await expect(
this.get().locator(`button:has-text("Submit Another Form")`)
).toBeVisible();
}
}
}

6
scripts/playwright/pages/Dashboard/Toolbar/ShareView.ts

@ -47,4 +47,10 @@ export class ToolbarShareViewPage extends BasePage {
async close() {
await this.get().locator(`.ant-modal-close-x`).click();
}
async toggleSurveyMode() {
await this.get()
.locator(`[data-pw="nc-modal-share-view__survey-mode"]`)
.click();
}
}

79
scripts/playwright/tests/viewFormShareSurvey.spec.ts

@ -0,0 +1,79 @@
import { test } from "@playwright/test";
import { DashboardPage } from "../pages/Dashboard";
import { SurveyFormPage } from "../pages/Dashboard/SurveyForm";
import setup from "../setup";
test.describe("Share form", () => {
let dashboard: DashboardPage;
let surveyForm: SurveyFormPage;
let context: any;
test.beforeEach(async ({ page }) => {
context = await setup({ page });
dashboard = new DashboardPage(page, context.project);
});
test("Survey", async () => {
// close 'Team & Auth' tab
await dashboard.closeTab({ title: "Team & Auth" });
await dashboard.treeView.openTable({ title: "Country" });
await dashboard.viewSidebar.createFormView({
title: "Country Form",
});
await dashboard.form.configureHeader({
title: "Country Title",
subtitle: "Country Form Subtitle",
});
await dashboard.form.configureSubmitMessage({
message: "Thank you for submitting the form",
});
await dashboard.form.showAnotherFormRadioButton.click();
await dashboard.form.showAnotherFormAfter5SecRadioButton.click();
await dashboard.toolbar.clickShareView();
await dashboard.toolbar.shareView.toggleSurveyMode();
const surveyLink = await dashboard.toolbar.shareView.getShareLink();
await dashboard.rootPage.waitForTimeout(2000);
await dashboard.rootPage.goto(surveyLink);
await dashboard.rootPage.waitForTimeout(2000);
surveyForm = new SurveyFormPage(dashboard.rootPage);
await surveyForm.validate({
heading: "Country Title",
subHeading: "Country Form Subtitle",
fieldLabel: "Country *",
footer: "1 / 3",
});
await surveyForm.fill({
fieldLabel: "Country",
value: "New Country",
type: "SingleLineText",
});
await surveyForm.validate({
heading: "Country Title",
subHeading: "Country Form Subtitle",
fieldLabel: "LastUpdate",
footer: "2 / 3",
});
await surveyForm.fill({
fieldLabel: "LastUpdate",
type: "DateTime",
});
await surveyForm.validate({
heading: "Country Title",
subHeading: "Country Form Subtitle",
fieldLabel: "City List",
footer: "3 / 3",
});
await surveyForm.submitButton.click();
// validate post submit data
await surveyForm.validateSuccessMessage({
message: "Thank you for submitting the form",
showAnotherForm: true,
});
});
});
Loading…
Cancel
Save