π₯ π₯ π₯ A Free & Self-hostable Airtable Alternative
TypeScript airtableairtable-alternativeautomatic-apihacktoberfestlow-codeno-codeno-code-databaseno-code-platformpostgresqlrest-apirestful-apispreadsheetsqliteswagger
feat: add pw tests for onboarding flow
Ramesh Maneacde2a46e6a4
diff --git a/packages/nc-gui/components/auth/onboarding/Layout/index.vue b/packages/nc-gui/components/auth/onboarding/Layout/index.vueindex 0da04ffa98..09f96ac8f1 100644--- a/packages/nc-gui/components/auth/onboarding/Layout/index.vue+++ b/packages/nc-gui/components/auth/onboarding/Layout/index.vue@@ -67,8 +67,8 @@ watch(</script><template>- <div class="w-full flex items-stretch h-full">- <div class="hidden lg:block w-1/2">+ <div data-testid="nc-onboarding-flow-container" class="w-full flex items-stretch h-full">+ <div data-testid="nc-onboarding-flow-image-preview-section" class="hidden lg:block w-1/2"><slot name="imagePreviewSection"><AuthOnboardingLayoutImagePreviewSection ref="imagePreviewSectionRef" /></slot>@@ -77,6 +77,7 @@ watch(class="w-full lg:(w-1/2) transition-width duration-250 h-full flex flex-col gap-[120px] nc-scrollbar-thin relative border-l-1 border-nc-border-gray-medium"><header+ data-testid="nc-onboarding-flow-header"class="px-4 pt-4 pb-2 lg:(pt-10 pb-2 px-8) flex items-center justify-between w-full max-w-[672px] lg:max-w-[704px] mx-auto sticky top-0 lg:-top-4 bg-white z-10"><GeneralIcon icon="nocodb1" class="w-12 h-12 flex-none" />@@ -92,12 +93,16 @@ watch(/></div></header>- <div class="flex-1 w-full max-w-[672px] lg:max-w-[704px] mx-auto flex flex-col gap-[120px] px-4 lg:(px-8)">+ <div+ data-testid="nc-onboarding-flow-content"+ class="flex-1 w-full max-w-[672px] lg:max-w-[704px] mx-auto flex flex-col gap-[120px] px-4 lg:(px-8)"+ ><slot name="content"></slot></div><slot name="footer"><footer+ data-testid="nc-onboarding-flow-footer"class="flex flex-col justify-end w-full max-w-[672px] lg:max-w-[704px] mx-auto px-4 pt-2 pb-4 lg:(pt-2 pb-10 px-8) sticky bottom-0 bg-white z-10"><div@@ -109,13 +114,26 @@ watch(><NcTooltip v-if="stepIndex === 0" :disabled="!isDisabledSkipButton"><template #title> Will be enabled after 2 seconds </template>- <NcButton type="text" size="small" :disabled="isDisabledSkipButton" @click="onCompleteOnboardingFlow(true)">+ <NcButton+ type="text"+ size="small"+ :disabled="isDisabledSkipButton"+ data-testid="nc-onboarding-flow-skip-button"+ @click="onCompleteOnboardingFlow(true)"+ ><div class="opacity-50">{{ $t('general.skip') }}</div></NcButton></NcTooltip>- <NcButton v-else type="text" size="small" :disabled="isFirst" @click="goToPrevious()">+ <NcButton+ v-else+ type="text"+ size="small"+ :disabled="isFirst"+ data-testid="nc-onboarding-flow-back-button"+ @click="goToPrevious()"+ ><template #icon><GeneralIcon icon="ncArrowLeft" class="w-4 h-4" /></template>@@ -126,6 +144,7 @@ watch(type="primary"size="small":disabled="!isFilledVisibleOptions"+ data-testid="nc-onboarding-flow-next-button"@click="isLast ? onCompleteOnboardingFlow(false) : goToNext()"><div class="flex items-center gap-2">diff --git a/packages/nc-gui/components/auth/onboarding/Question/index.vue b/packages/nc-gui/components/auth/onboarding/Question/index.vueindex 62b78b41ea..b5aa837f59 100644--- a/packages/nc-gui/components/auth/onboarding/Question/index.vue+++ b/packages/nc-gui/components/auth/onboarding/Question/index.vue@@ -8,7 +8,9 @@ const props = withDefaults(defineProps<Props>(), {})const { question, questionIndex } = toRefs(props)-const { formState, onSelectOption } = useOnboardingFlow()+const { formState, onSelectOption, stepper } = useOnboardingFlow()++const { isFirst, isLast } = stepperconst options = computed(() => {if (ncIsFunction(question.value.options)) {@@ -38,7 +40,19 @@ const isOptionSelected = (option: OnboardingOptionType) => {</script><template>- <div class="flex flex-col gap-6">+ <div+ data-testid="nc-onboarding-flow-question"+ class="flex flex-col gap-6"+ :class="[+ `nc-active-question-index-${questionIndex}`,+ {+ 'nc-first-question': isFirst,+ 'nc-last-question': isLast,+ 'nc-single-select-question': question.inputType === 'singleSelect',+ 'nc-multi-select-question': question.inputType === 'multiSelect',+ },+ ]"+ ><div class="flex flex-col gap-3"><h3 class="my-0 text-heading3 text-nc-content-gray-emphasis">{{ question.question }}</h3><p v-if="question.description" class="my-0 text-body text-nc-content-gray-subtle2">diff --git a/tests/playwright/pages/OnboardingFlow/index.ts b/tests/playwright/pages/OnboardingFlow/index.tsnew file mode 100644index 0000000000..0702c64eee--- /dev/null+++ b/tests/playwright/pages/OnboardingFlow/index.ts@@ -0,0 +1,214 @@+import { Locator, Page } from '@playwright/test';+import BasePage from '../Base';+import { expect } from '@playwright/test';++export class OnboardingFlowPage extends BasePage {+ /**+ * Left side image preview section+ */+ readonly imagePreviewSection: Locator;++ /**+ * Right side content section+ */+ readonly header: Locator;++ /**+ * Footer+ */+ readonly footer: Locator;+ readonly skipButton: Locator;+ readonly backButton: Locator;+ readonly nextButton: Locator;++ /**+ * Content+ */+ readonly content: Locator;+ readonly question: Locator;++ /**+ * Question options+ */+ readonly questionOptions: Locator;++ constructor(rootPage: Page) {+ super(rootPage);+ this.skipButton = this.get().getByTestId('nc-onboarding-flow-skip-button');+ this.backButton = this.get().getByTestId('nc-onboarding-flow-back-button');+ this.nextButton = this.get().getByTestId('nc-onboarding-flow-next-button');+ this.question = this.get().getByTestId('nc-onboarding-flow-question');++ this.imagePreviewSection = this.get().getByTestId('nc-onboarding-flow-image-preview-section');+ this.header = this.get().getByTestId('nc-onboarding-flow-header');+ this.content = this.get().getByTestId('nc-onboarding-flow-content');+ this.footer = this.get().getByTestId('nc-onboarding-flow-footer');++ // Question options are within the question container+ this.questionOptions = this.question.locator('.nc-onboarding-option');+ }++ get() {+ return this.rootPage.getByTestId('nc-onboarding-flow-container');+ }++ /**+ * Check if current question is single select+ */+ async isSingleSelectQuestion(): Promise<boolean> {+ return (await this.question.evaluate(el => el.classList.contains('nc-single-select-question'))) ?? false;+ }++ /**+ * Check if current question is multi select+ */+ async isMultiSelectQuestion(): Promise<boolean> {+ return (await this.question.evaluate(el => el.classList.contains('nc-multi-select-question'))) ?? false;+ }++ /**+ * Helper method to get current question type+ */+ async getCurrentQuestionType(): Promise<'singleSelect' | 'multiSelect' | void> {+ if (await this.isSingleSelectQuestion()) {+ return 'singleSelect';+ } else if (await this.isMultiSelectQuestion()) {+ return 'multiSelect';+ }+ }++ /**+ * Check if current question is the first question+ */+ async isFirstQuestion(): Promise<boolean> {+ return await this.question.evaluate(el => el.classList.contains('nc-first-question'));+ }++ /**+ * Check if current question is the last question+ */+ async isLastQuestion(): Promise<boolean> {+ return await this.question.evaluate(el => el.classList.contains('nc-last-question'));+ }++ /**+ * Verify current question index+ */+ async verifyQuestionIndex(index: number) {+ await expect(this.question).toHaveClass(`nc-active-question-index-${index}`);+ }++ /**+ * Test single select question behavior with auto-navigation+ */+ async handleSingleSelectQuestion({ optionIndex }: { optionIndex: number }) {+ const option = this.questionOptions.nth(optionIndex);++ // Select option+ await option.click();+ await expect(option).toHaveClass(/nc-selected/);++ // Wait for auto-navigation (500ms delay as per useOnboardingFlow)+ await this.rootPage.waitForTimeout(600);+ }++ /**+ * Test multi select question behavior (no auto-navigation)+ */+ async handleMultiSelectQuestion({ optionIndexes }: { optionIndexes: number[] }) {+ for (const optionIndex of optionIndexes) {+ const option = this.questionOptions.nth(optionIndex);+ await option.click();+ await expect(option).toHaveClass(/nc-selected/);+ }++ await this.navigateToNextQuestion();++ // Wait for auto-navigation (500ms delay as per useOnboardingFlow)+ await this.rootPage.waitForTimeout(600);+ }++ /**+ * Navigate to next question manually (for multi-select or when auto-navigation doesn't work)+ */+ async navigateToNextQuestion() {+ await this.nextButton.click();++ // Wait for transition+ await this.rootPage.waitForTimeout(300);+ }++ /**+ * Navigate back to previous question+ */+ async navigateToPreviousQuestion() {+ await this.backButton.click();++ // Wait for transition+ await this.rootPage.waitForTimeout(300);+ }++ /**+ * Complete the onboarding flow by navigating through all questions+ */+ async completeOnboardingFlow() {+ // Navigate through all questions+ let questionIndex = 0;+ let flag = true;+ while (flag) {+ await this.verifyQuestionIndex(questionIndex);++ const questionType = await this.getCurrentQuestionType();+ if (questionType === 'singleSelect') {+ await this.handleSingleSelectQuestion({ optionIndex: 0 });+ } else if (questionType === 'multiSelect') {+ await this.handleMultiSelectQuestion({ optionIndexes: [0, 1] });+ }++ /**+ * `questionIndex > 25` condition will not be reached in the actual flow,+ * but it's a safety net to prevent infinite loops in case of unexpected behavior.+ */+ if ((await this.isLastQuestion()) || questionIndex > 25) {+ flag = false;+ break;+ }++ questionIndex++;+ }++ // On last question, the next button should say "Finish"+ await expect(this.nextButton).toHaveText('Finish');++ await this.waitForResponse({+ uiAction: () => this.nextButton.click(),+ httpMethodsToMatch: ['PATCH'],+ requestUrlPathToMatch: 'api/v1/user/profile',+ });++ // Wait for redirection+ await this.rootPage.waitForTimeout(1000);++ await expect(this.get()).not.toBeVisible();+ }++ /**+ * Skip the onboarding flow+ */+ async skipOnboardingFlow({ verify = false }: { verify?: boolean } = {}) {+ await this.waitForResponse({+ uiAction: () => this.skipButton.click(),+ httpMethodsToMatch: ['PATCH'],+ requestUrlPathToMatch: 'api/v1/user/profile',+ });++ // Wait for redirection+ await this.rootPage.waitForTimeout(1000);++ if (verify) {+ await expect(this.get()).not.toBeVisible();+ } else {+ await this.get().waitFor({ state: 'hidden' });+ }+ }+}diff --git a/tests/playwright/pages/SignupPage/index.ts b/tests/playwright/pages/SignupPage/index.tsindex 9c4141861f..94205f8ccd 100644--- a/tests/playwright/pages/SignupPage/index.ts+++ b/tests/playwright/pages/SignupPage/index.ts@@ -29,11 +29,13 @@ export class SignupPage extends BasePage {password,withoutPrefix,expectedError,+ skipOnboardingFlow = true,}: {email: string;password: string;withoutPrefix?: boolean;expectedError?: string;+ skipOnboardingFlow?: boolean;}) {if (!withoutPrefix) email = this.prefixEmail(email);@@ -47,6 +49,10 @@ export class SignupPage extends BasePage {await expect(signUp.getByTestId('nc-signup-error')).toHaveText(expectedError);} else {await this.rootPage.waitForLoadState('networkidle');++ if (skipOnboardingFlow) {+ // await this.rootPage.locator('button:has-text("Skip")').click();+ }}}}diff --git a/tests/playwright/tests/onboarding-flow.spec.ts b/tests/playwright/tests/onboarding-flow.spec.tsnew file mode 100644index 0000000000..8271a17ea3--- /dev/null+++ b/tests/playwright/tests/onboarding-flow.spec.ts@@ -0,0 +1,28 @@+import { test } from '@playwright/test';+import { OnboardingFlowPage } from '../pages/OnboardingFlow';++test.describe('Onboarding Flow', () => {+ let onboardingFlowPage: OnboardingFlowPage;++ test.beforeEach(async ({ page }) => {+ // Navigate to the onboarding flow page+ await page.goto('/');++ // Wait for onboarding flow to be visible+ await page.waitForSelector('[data-testid="nc-onboarding-flow-container"]');++ onboardingFlowPage = new OnboardingFlowPage(page);+ });++ test.describe('Flow Completion', () => {+ test('should complete onboarding flow', async () => {+ // Complete the entire flow+ await onboardingFlowPage.completeOnboardingFlow();+ });++ test('should skip onboarding flow', async () => {+ // Skip the flow+ await onboardingFlowPage.skipOnboardingFlow();+ });+ });+});