tests: Update references section tests for new behavior
**Test 3 Updated**: Shortcut URL behavior changed
- OLD: Expected HTTP 301 redirect to /export/pdf
- NEW: Expects HTTP 200 with direct PDF and Content-Disposition header
- Verifies correct filename: cv-jamr-2025-{lang}.pdf
**Test 6 Added**: Language switching links
- Tests "See this CV in Spanish/English" links
- Verifies URL correctness (/?lang=es and /?lang=en)
- Ensures no URL corruption from replaceYearPlaceholder fix
- Checks target="_blank" attribute
- Tests both English → Spanish and Spanish → English links
All 6 tests passing:
✅ EN Direct Shortcut URL
✅ ES Direct Shortcut URL
✅ Shortcut URL Direct Download (updated)
✅ Year Validation
✅ No JavaScript Required
✅ Language Switching Links (new)
This commit is contained in:
@@ -176,9 +176,9 @@ async function testReferencesPDFShortcutLinks() {
|
||||
testResults.push({ test: 'ES Direct Shortcut URL', passed: test2Passed });
|
||||
|
||||
// ========================================================================
|
||||
// TEST 3: Shortcut URL Responds with 301 Redirect
|
||||
// TEST 3: Shortcut URL Returns PDF with Correct Filename
|
||||
// ========================================================================
|
||||
console.log("\n3️⃣ Testing Shortcut URL Redirects...");
|
||||
console.log("\n3️⃣ Testing Shortcut URL Direct PDF Download...");
|
||||
|
||||
// Test English shortcut
|
||||
const enResponse = await page.request.get(`${URL}/cv-jamr-${CURRENT_YEAR}-en.pdf`, {
|
||||
@@ -187,14 +187,14 @@ async function testReferencesPDFShortcutLinks() {
|
||||
});
|
||||
|
||||
const enStatus = enResponse.status();
|
||||
const enLocation = enResponse.headers()['location'];
|
||||
const enContentDisposition = enResponse.headers()['content-disposition'];
|
||||
const enContentType = enResponse.headers()['content-type'];
|
||||
const enFilename = enContentDisposition?.match(/filename=([^;]+)/)?.[1];
|
||||
|
||||
console.log(` English shortcut HTTP status: ${enStatus} ${enStatus === 301 ? '✅' : '❌'}`);
|
||||
console.log(` Redirect location: ${enLocation}`);
|
||||
console.log(` Points to export/pdf: ${enLocation?.includes('/export/pdf') ? '✅' : '❌'}`);
|
||||
console.log(` Has lang=en: ${enLocation?.includes('lang=en') ? '✅' : '❌'}`);
|
||||
console.log(` Has length=short: ${enLocation?.includes('length=short') ? '✅' : '❌'}`);
|
||||
console.log(` Has version=with_skills: ${enLocation?.includes('version=with_skills') ? '✅' : '❌'}`);
|
||||
console.log(` English shortcut HTTP status: ${enStatus} ${enStatus === 200 ? '✅' : '❌'}`);
|
||||
console.log(` Content-Type: ${enContentType} ${enContentType === 'application/pdf' ? '✅' : '❌'}`);
|
||||
console.log(` Content-Disposition: ${enContentDisposition}`);
|
||||
console.log(` Filename: ${enFilename} ${enFilename === 'cv-jamr-2025-en.pdf' ? '✅' : '❌'}`);
|
||||
|
||||
// Test Spanish shortcut
|
||||
const esResponse = await page.request.get(`${URL}/cv-jamr-${CURRENT_YEAR}-es.pdf`, {
|
||||
@@ -203,20 +203,24 @@ async function testReferencesPDFShortcutLinks() {
|
||||
});
|
||||
|
||||
const esStatus = esResponse.status();
|
||||
const esLocation = esResponse.headers()['location'];
|
||||
const esContentDisposition = esResponse.headers()['content-disposition'];
|
||||
const esContentType = esResponse.headers()['content-type'];
|
||||
const esFilename = esContentDisposition?.match(/filename=([^;]+)/)?.[1];
|
||||
|
||||
console.log(` Spanish shortcut HTTP status: ${esStatus} ${esStatus === 301 ? '✅' : '❌'}`);
|
||||
console.log(` Redirect location: ${esLocation}`);
|
||||
console.log(` Has lang=es: ${esLocation?.includes('lang=es') ? '✅' : '❌'}`);
|
||||
console.log(` Spanish shortcut HTTP status: ${esStatus} ${esStatus === 200 ? '✅' : '❌'}`);
|
||||
console.log(` Content-Type: ${esContentType} ${esContentType === 'application/pdf' ? '✅' : '❌'}`);
|
||||
console.log(` Content-Disposition: ${esContentDisposition}`);
|
||||
console.log(` Filename: ${esFilename} ${esFilename === 'cv-jamr-2025-es.pdf' ? '✅' : '❌'}`);
|
||||
|
||||
const test3Passed = enStatus === 301 &&
|
||||
esStatus === 301 &&
|
||||
enLocation?.includes('/export/pdf') &&
|
||||
enLocation?.includes('lang=en') &&
|
||||
esLocation?.includes('lang=es');
|
||||
const test3Passed = enStatus === 200 &&
|
||||
esStatus === 200 &&
|
||||
enContentType === 'application/pdf' &&
|
||||
esContentType === 'application/pdf' &&
|
||||
enFilename === 'cv-jamr-2025-en.pdf' &&
|
||||
esFilename === 'cv-jamr-2025-es.pdf';
|
||||
|
||||
console.log(` ${test3Passed ? '✅ PASS' : '❌ FAIL'} - Shortcut URL redirects`);
|
||||
testResults.push({ test: 'Shortcut URL Redirects', passed: test3Passed });
|
||||
console.log(` ${test3Passed ? '✅ PASS' : '❌ FAIL'} - Shortcut URL direct download with correct filename`);
|
||||
testResults.push({ test: 'Shortcut URL Direct Download', passed: test3Passed });
|
||||
|
||||
// ========================================================================
|
||||
// TEST 4: Invalid Year Returns 404
|
||||
@@ -296,6 +300,97 @@ async function testReferencesPDFShortcutLinks() {
|
||||
|
||||
await noJSContext.close();
|
||||
|
||||
// ========================================================================
|
||||
// TEST 6: "See this CV in..." Language Switching Links
|
||||
// ========================================================================
|
||||
console.log("\n6️⃣ Testing Language Switching Links...");
|
||||
|
||||
// Test English page has Spanish link
|
||||
await page.goto(`${URL}/?lang=en`);
|
||||
await page.waitForTimeout(1000);
|
||||
|
||||
const enLanguageLink = await page.evaluate(() => {
|
||||
const section = document.querySelector('#references');
|
||||
if (!section) return { found: false };
|
||||
|
||||
const referenceItems = section.querySelectorAll('.reference-item');
|
||||
let spanishLink = null;
|
||||
|
||||
for (const item of referenceItems) {
|
||||
if (item.textContent.includes('Curriculum Vitae in PDF in')) {
|
||||
spanishLink = item.querySelector('a');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
found: true,
|
||||
linkExists: !!spanishLink,
|
||||
linkText: spanishLink ? spanishLink.textContent.trim() : null,
|
||||
href: spanishLink ? spanishLink.getAttribute('href') : null,
|
||||
expectedHref: '/?lang=es',
|
||||
hrefMatches: spanishLink ? spanishLink.getAttribute('href') === '/?lang=es' : false,
|
||||
target: spanishLink ? spanishLink.getAttribute('target') : null,
|
||||
noCorruption: spanishLink ? !spanishLink.getAttribute('href').includes('EXTRA') : false
|
||||
};
|
||||
});
|
||||
|
||||
console.log(` English page - Spanish link exists: ${enLanguageLink.linkExists ? '✅' : '❌'}`);
|
||||
console.log(` Link text: "${enLanguageLink.linkText}"`);
|
||||
console.log(` Href: "${enLanguageLink.href}"`);
|
||||
console.log(` Expected: "${enLanguageLink.expectedHref}"`);
|
||||
console.log(` Href matches: ${enLanguageLink.hrefMatches ? '✅' : '❌'}`);
|
||||
console.log(` No URL corruption: ${enLanguageLink.noCorruption ? '✅' : '❌'}`);
|
||||
console.log(` Target="_blank": ${enLanguageLink.target === '_blank' ? '✅' : '❌'}`);
|
||||
|
||||
// Test Spanish page has English link
|
||||
await page.goto(`${URL}/?lang=es`);
|
||||
await page.waitForTimeout(1000);
|
||||
|
||||
const esLanguageLink = await page.evaluate(() => {
|
||||
const section = document.querySelector('#references');
|
||||
if (!section) return { found: false };
|
||||
|
||||
const referenceItems = section.querySelectorAll('.reference-item');
|
||||
let englishLink = null;
|
||||
|
||||
for (const item of referenceItems) {
|
||||
if (item.textContent.includes('Currículum Vitae en PDF en')) {
|
||||
englishLink = item.querySelector('a');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
found: true,
|
||||
linkExists: !!englishLink,
|
||||
linkText: englishLink ? englishLink.textContent.trim() : null,
|
||||
href: englishLink ? englishLink.getAttribute('href') : null,
|
||||
expectedHref: '/?lang=en',
|
||||
hrefMatches: englishLink ? englishLink.getAttribute('href') === '/?lang=en' : false,
|
||||
target: englishLink ? englishLink.getAttribute('target') : null,
|
||||
noCorruption: englishLink ? !englishLink.getAttribute('href').includes('EXTRA') : false
|
||||
};
|
||||
});
|
||||
|
||||
console.log(` Spanish page - English link exists: ${esLanguageLink.linkExists ? '✅' : '❌'}`);
|
||||
console.log(` Link text: "${esLanguageLink.linkText}"`);
|
||||
console.log(` Href: "${esLanguageLink.href}"`);
|
||||
console.log(` Expected: "${esLanguageLink.expectedHref}"`);
|
||||
console.log(` Href matches: ${esLanguageLink.hrefMatches ? '✅' : '❌'}`);
|
||||
console.log(` No URL corruption: ${esLanguageLink.noCorruption ? '✅' : '❌'}`);
|
||||
console.log(` Target="_blank": ${esLanguageLink.target === '_blank' ? '✅' : '❌'}`);
|
||||
|
||||
const test6Passed = enLanguageLink.linkExists &&
|
||||
enLanguageLink.hrefMatches &&
|
||||
enLanguageLink.noCorruption &&
|
||||
esLanguageLink.linkExists &&
|
||||
esLanguageLink.hrefMatches &&
|
||||
esLanguageLink.noCorruption;
|
||||
|
||||
console.log(` ${test6Passed ? '✅ PASS' : '❌ FAIL'} - Language switching links work correctly`);
|
||||
testResults.push({ test: 'Language Switching Links', passed: test6Passed });
|
||||
|
||||
// ========================================================================
|
||||
// FINAL RESULTS
|
||||
// ========================================================================
|
||||
|
||||
Reference in New Issue
Block a user