Files
zeekay e43ab1afe7 chore: rename all PostHog references to Insights/Hanzo
Bulk rename across 989 files:
- Package names: posthog-js → @hanzo/insights, posthog-node → @hanzo/insights-node, etc.
- Repository URLs: posthog/posthog-js → hanzoai/insights-js
- Brand names: PostHog → Insights
- File renames: 259 reference JSON files, source files, workflow files
- Directory rename: eslint-plugin-posthog-js → eslint-plugin-insights

Remaining: 8 refs to @posthog/rrweb-* (real npm deps, need fork+publish)
2026-03-06 01:41:12 -08:00

170 lines
6.6 KiB
TypeScript

import { expect, test } from '../utils/insights-playwright-test-base'
import { start } from '../utils/setup'
const startOptions = {
options: {},
flagsResponseOverrides: {
surveys: true,
},
url: './playground/cypress/index.html',
}
const appearanceWithThanks = {
displayThankYouMessage: true,
thankYouMessageHeader: 'Thanks!',
}
test.describe('survey validation', () => {
test('required field rejects whitespace-only input', async ({ page, context }) => {
const surveysAPICall = page.route('**/surveys/**', async (route) => {
await route.fulfill({
json: {
surveys: [
{
id: 'validation-test-1',
name: 'Required field test',
type: 'popover',
start_date: '2021-01-01T00:00:00Z',
questions: [
{
type: 'open',
question: 'Required feedback',
id: 'q1',
optional: false,
},
],
},
],
},
})
})
await start(startOptions, page, context)
await surveysAPICall
// Wait for survey form to appear
await expect(page.locator('.InsightsSurvey-validation-test-1').locator('.survey-form')).toBeVisible()
// Type only spaces
await page.locator('textarea').fill(' ')
// Submit button should be disabled (validation failed - whitespace only)
await expect(page.locator('button:has-text("Submit")')).toBeDisabled()
// Survey form should still be visible
await expect(page.locator('.InsightsSurvey-validation-test-1').locator('.survey-form')).toBeVisible()
})
test('required field accepts valid input after trim', async ({ page, context }) => {
const surveysAPICall = page.route('**/surveys/**', async (route) => {
await route.fulfill({
json: {
surveys: [
{
id: 'validation-test-2',
name: 'Valid input test',
type: 'popover',
start_date: '2021-01-01T00:00:00Z',
questions: [
{
type: 'open',
question: 'Required feedback',
id: 'q1',
optional: false,
},
],
appearance: appearanceWithThanks,
},
],
},
})
})
await start(startOptions, page, context)
await surveysAPICall
await expect(page.locator('.InsightsSurvey-validation-test-2').locator('.survey-form')).toBeVisible()
// Type valid content with surrounding whitespace
await page.locator('textarea').fill(' valid response ')
await page.locator('button:has-text("Submit")').click()
// Should show thank you message (submitted successfully)
await expect(page.locator('.InsightsSurvey-validation-test-2')).toContainText('Thanks')
})
test('backwards compat - old survey without validation field works', async ({ page, context }) => {
const surveysAPICall = page.route('**/surveys/**', async (route) => {
await route.fulfill({
json: {
surveys: [
{
id: 'validation-test-3',
name: 'Old survey format',
type: 'popover',
start_date: '2021-01-01T00:00:00Z',
questions: [
{
type: 'open',
question: 'Old question format',
id: 'q1',
// No 'validation' field - old survey format
// No 'optional' field - defaults to required
},
],
appearance: appearanceWithThanks,
},
],
},
})
})
await start(startOptions, page, context)
await surveysAPICall
await expect(page.locator('.InsightsSurvey-validation-test-3').locator('.survey-form')).toBeVisible()
await page.locator('textarea').fill('valid response')
await page.locator('button:has-text("Submit")').click()
// Should show thank you message (submitted successfully)
await expect(page.locator('.InsightsSurvey-validation-test-3')).toContainText('Thanks')
})
test('minLength validation prevents short input', async ({ page, context }) => {
const surveysAPICall = page.route('**/surveys/**', async (route) => {
await route.fulfill({
json: {
surveys: [
{
id: 'validation-test-4',
name: 'MinLength test',
type: 'popover',
start_date: '2021-01-01T00:00:00Z',
questions: [
{
type: 'open',
question: 'Enter at least 10 characters',
id: 'q1',
optional: false,
validation: [{ type: 'min_length', value: 10 }],
},
],
},
],
},
})
})
await start(startOptions, page, context)
await surveysAPICall
await expect(page.locator('.InsightsSurvey-validation-test-4').locator('.survey-form')).toBeVisible()
await page.locator('textarea').fill('short')
// Submit button should be disabled (validation failed - too short)
await expect(page.locator('button:has-text("Submit")')).toBeDisabled()
// Survey form should still be visible
await expect(page.locator('.InsightsSurvey-validation-test-4').locator('.survey-form')).toBeVisible()
})
})