field-name-validation.jsβ’3.34 kB
#!/usr/bin/env node
/**
* Field Name Validation Test
* Verifies the critical field name fixes are working correctly
*/
import { createComposerFormatter } from '../src/tools/format-for-composer.js';
// Test data with quiz, list, and hotspots
const testData = {
metadata: {
topic: "Test Field Names",
subject: "MatemΓ‘tica",
gradeLevel: "6ΒΊ ano"
},
widgets: [
{
type: "quiz-1",
content: {
questions: [
{
question: "Test question?",
options: ["A", "B", "C"],
correct_option: 1
}
]
}
},
{
type: "list-1",
content: {
items: ["Item 1", "Item 2", "Item 3"]
}
},
{
type: "hotspots-1",
content: {
background_image: "https://example.com/image.jpg",
markers: [
{ x: 50, y: 30, title: "Point 1", content: "Test content" },
{ x: "20%", y: "40%", title: "Point 2", content: "Test content" }
]
}
}
]
};
async function testFieldNames() {
console.error('π§ Testing Critical Field Name Fixes\n');
const formatter = createComposerFormatter();
const result = await formatter.formatForComposer(testData);
if (!result.success) {
console.error('β Formatting failed:', result.error.message);
return;
}
const structure = result.data.composerJSON.structure;
// Test 1: Quiz uses "answers" not "choices"
const quizWidget = structure.find(w => w.type === 'quiz-1');
if (quizWidget && quizWidget.questions && quizWidget.questions[0].answers) {
console.error('β
Quiz widget: Uses "answers" field correctly');
} else {
console.error('β Quiz widget: Still uses "choices" field');
}
// Test 2: List uses "list_items" not "items"
const listWidget = structure.find(w => w.type === 'list-1');
if (listWidget && listWidget.list_items) {
console.error('β
List widget: Uses "list_items" field correctly');
} else {
console.error('β List widget: Still uses "items" field');
}
// Test 3: Hotspots coordinates are strings with percentages
const hotspotsWidget = structure.find(w => w.type === 'hotspots-1');
if (hotspotsWidget && hotspotsWidget.marcadores) {
const marker1 = hotspotsWidget.marcadores[0];
const marker2 = hotspotsWidget.marcadores[1];
if (marker1.x === "50%" && marker1.y === "30%") {
console.error('β
Hotspots widget: Numeric coordinates converted to percentages');
} else {
console.error('β Hotspots widget: Coordinates not converted properly');
console.error(` Expected: "50%", "30%" Got: "${marker1.x}", "${marker1.y}"`);
}
if (marker2.x === "20%" && marker2.y === "40%") {
console.error('β
Hotspots widget: String percentages preserved correctly');
} else {
console.error('β Hotspots widget: String percentages modified incorrectly');
}
} else {
console.error('β Hotspots widget: marcadores field missing');
}
console.error('\nπ Field Name Fix Summary:');
console.error(' Quiz: choices β answers');
console.error(' List: items β list_items');
console.error(' Hotspots: numeric coordinates β percentage strings');
console.error('\nβ
All critical field name fixes verified');
}
testFieldNames().catch(console.error);