-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathtest-import-export.js
More file actions
89 lines (79 loc) · 2.35 KB
/
Copy pathtest-import-export.js
File metadata and controls
89 lines (79 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env node
// Simple test script to verify import/export functionality
import { transpiler } from './packages/transpiler/dist/index.js';
// Create a simple test graph
const testGraph = {
id: '12345678-1234-1234-1234-123456789abc',
name: 'Test Automation',
description: 'A test automation',
nodes: [
{
id: 'trigger-1',
type: 'trigger',
position: { x: 100, y: 100 },
data: {
platform: 'state',
entity_id: 'light.living_room',
to: 'on',
},
},
{
id: 'action-1',
type: 'action',
position: { x: 300, y: 200 },
data: {
service: 'notify.mobile_app',
data: {
message: 'Light turned on!',
},
},
},
],
edges: [
{
id: 'e1',
source: 'trigger-1',
target: 'action-1',
},
],
metadata: {
mode: 'single',
},
version: 1,
};
console.log('=== Testing Export (toYaml) ===\n');
try {
const yaml = transpiler.toYaml(testGraph);
console.log('Generated YAML:');
console.log(yaml);
console.log('\n=== Testing Import (fromYaml) ===\n');
// Test importing the generated YAML
const parseResult = transpiler.fromYaml(yaml);
if (parseResult.success) {
console.log('✅ Import successful!');
console.log(` Graph ID: ${parseResult.graph.id}`);
console.log(` Graph Name: ${parseResult.graph.name}`);
console.log(` Nodes: ${parseResult.graph.nodes.length}`);
console.log(` Edges: ${parseResult.graph.edges.length}`);
console.log(` Had metadata: ${parseResult.hadMetadata}`);
if (parseResult.warnings.length > 0) {
console.log('\n⚠️ Warnings:');
parseResult.warnings.forEach((w) => console.log(` - ${w}`));
}
// Check if positions were preserved
const firstNode = parseResult.graph.nodes[0];
console.log(`\n First node position: x=${firstNode.position.x}, y=${firstNode.position.y}`);
if (firstNode.position.x === 100 && firstNode.position.y === 100) {
console.log(' ✅ Position metadata preserved!');
} else {
console.log(' ⚠️ Position was reset (expected for heuristic layout)');
}
} else {
console.log('❌ Import failed!');
console.log('Errors:', parseResult.errors);
}
} catch (error) {
console.error('❌ Test failed:', error.message);
process.exit(1);
}
console.log('\n=== All tests passed! ===');