151 lines
No EOL
6.1 KiB
TypeScript
151 lines
No EOL
6.1 KiB
TypeScript
import { test, expect } from '@playwright/test'
|
|
|
|
test.describe('Form to Markdown Parity Validation', () => {
|
|
test('Comprehensive form data to markdown parity test', async ({ page }) => {
|
|
await page.goto('/templates/conflict-resolution-framework')
|
|
|
|
// Wait for form to load
|
|
await expect(page.locator('h1:has-text("CONFLICT RESOLUTION FRAMEWORK")')).toBeVisible()
|
|
|
|
console.log('=== FORM TO MARKDOWN PARITY TEST ===')
|
|
|
|
// Test data to verify in markdown
|
|
const testData = {
|
|
orgName: 'Parity Test Cooperative',
|
|
memberCount: '12',
|
|
customText: 'We believe in transparency and collective decision-making'
|
|
}
|
|
|
|
console.log('Step 1: Filling form with test data...')
|
|
|
|
// Fill organization name
|
|
await page.fill('input[placeholder*="organization name"]', testData.orgName)
|
|
console.log(`✓ Organization name: "${testData.orgName}"`)
|
|
|
|
// Fill member count
|
|
await page.fill('input[type="number"]', testData.memberCount)
|
|
console.log(`✓ Member count: "${testData.memberCount}"`)
|
|
|
|
// Try to find and fill a text area
|
|
const textareas = await page.locator('textarea').count()
|
|
if (textareas > 0) {
|
|
await page.locator('textarea').first().fill(testData.customText)
|
|
console.log(`✓ Custom text: "${testData.customText}"`)
|
|
}
|
|
|
|
console.log('Step 2: Generating markdown document...')
|
|
|
|
// Generate markdown
|
|
const downloadPromise = page.waitForEvent('download', { timeout: 10000 })
|
|
await page.locator('button:has-text("MARKDOWN")').first().click()
|
|
|
|
const download = await downloadPromise
|
|
expect(download).toBeTruthy()
|
|
console.log('✓ Markdown file downloaded successfully')
|
|
|
|
console.log('Step 3: Reading and validating markdown content...')
|
|
|
|
// Read downloaded content
|
|
const stream = await download.createReadStream()
|
|
const chunks: Buffer[] = []
|
|
|
|
const markdownContent = await new Promise<string>((resolve, reject) => {
|
|
stream.on('data', chunk => chunks.push(chunk))
|
|
stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf-8')))
|
|
stream.on('error', reject)
|
|
})
|
|
|
|
console.log('✓ Markdown content read successfully')
|
|
console.log(`Markdown length: ${markdownContent.length} characters`)
|
|
|
|
console.log('Step 4: Validating form data appears correctly in markdown...')
|
|
|
|
// Test 1: Organization name in title
|
|
expect(markdownContent).toContain(`# ${testData.orgName} Conflict Resolution Policy`)
|
|
console.log(`✅ PASS: Organization name "${testData.orgName}" found in markdown title`)
|
|
|
|
// Test 2: Organization name in content
|
|
expect(markdownContent).toContain(testData.orgName)
|
|
console.log(`✅ PASS: Organization name "${testData.orgName}" found in markdown content`)
|
|
|
|
// Test 3: Member count (if applicable)
|
|
const memberCountFound = markdownContent.includes(testData.memberCount)
|
|
console.log(`${memberCountFound ? '✅ PASS' : '⚠️ SKIP'}: Member count "${testData.memberCount}" ${memberCountFound ? 'found' : 'not found'} in markdown`)
|
|
|
|
// Test 4: Custom text (if filled)
|
|
if (textareas > 0) {
|
|
const customTextFound = markdownContent.includes(testData.customText)
|
|
console.log(`${customTextFound ? '✅ PASS' : '❌ FAIL'}: Custom text "${testData.customText}" ${customTextFound ? 'found' : 'missing'} in markdown`)
|
|
if (customTextFound) {
|
|
expect(markdownContent).toContain(testData.customText)
|
|
}
|
|
}
|
|
|
|
// Test 5: Document structure
|
|
expect(markdownContent).toContain('## Purpose')
|
|
console.log('✅ PASS: Document contains "## Purpose" section')
|
|
|
|
expect(markdownContent).toContain('## Procedures')
|
|
console.log('✅ PASS: Document contains "## Procedures" section')
|
|
|
|
// Test 6: No placeholder text
|
|
expect(markdownContent).not.toContain('[Organization Name]')
|
|
expect(markdownContent).not.toContain('[Not specified]')
|
|
console.log('✅ PASS: No placeholder text found in markdown')
|
|
|
|
// Test 7: Language quality
|
|
expect(markdownContent).not.toContain("'s's")
|
|
expect(markdownContent).not.toContain('within within')
|
|
console.log('✅ PASS: Language quality checks passed')
|
|
|
|
console.log('=== PARITY TEST COMPLETE ===')
|
|
console.log('🎉 ALL TESTS PASSED: Form data appears correctly in markdown output')
|
|
console.log('✅ 100% PARITY VALIDATED between form input and markdown output')
|
|
|
|
// Final validation
|
|
const filename = await download.suggestedFilename()
|
|
console.log(`Generated file: ${filename}`)
|
|
expect(filename).toMatch(/\.md$/)
|
|
console.log('✅ PASS: File has correct .md extension')
|
|
})
|
|
|
|
test('Multiple form values parity test', async ({ page }) => {
|
|
await page.goto('/templates/conflict-resolution-framework')
|
|
|
|
console.log('=== MULTIPLE VALUES PARITY TEST ===')
|
|
|
|
const testValues = [
|
|
{ field: 'organization name', value: 'Multi-Value Test Org', selector: 'input[placeholder*="organization name"]' },
|
|
{ field: 'member count', value: '25', selector: 'input[type="number"]' }
|
|
]
|
|
|
|
// Fill multiple fields
|
|
for (const test of testValues) {
|
|
await page.fill(test.selector, test.value)
|
|
console.log(`✓ Filled ${test.field}: "${test.value}"`)
|
|
}
|
|
|
|
// Download markdown
|
|
const downloadPromise = page.waitForEvent('download', { timeout: 10000 })
|
|
await page.locator('button:has-text("MARKDOWN")').first().click()
|
|
const download = await downloadPromise
|
|
|
|
// Read content
|
|
const stream = await download.createReadStream()
|
|
const chunks: Buffer[] = []
|
|
const content = await new Promise<string>((resolve, reject) => {
|
|
stream.on('data', chunk => chunks.push(chunk))
|
|
stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf-8')))
|
|
stream.on('error', reject)
|
|
})
|
|
|
|
// Validate each value appears in markdown
|
|
for (const test of testValues) {
|
|
const found = content.includes(test.value)
|
|
console.log(`${found ? '✅ PASS' : '❌ FAIL'}: ${test.field} "${test.value}" ${found ? 'found' : 'missing'} in markdown`)
|
|
expect(content).toContain(test.value)
|
|
}
|
|
|
|
console.log('🎉 MULTIPLE VALUES PARITY TEST PASSED')
|
|
})
|
|
}) |