-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-app-functionality.mjs
More file actions
325 lines (282 loc) · 8.98 KB
/
test-app-functionality.mjs
File metadata and controls
325 lines (282 loc) · 8.98 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
/**
* Manual Application Testing
* Tests core functionality without complex test framework setup
*/
console.log('=== Director\'s Palette Functionality Test ===\n');
// Test 1: Check if core files exist and can be imported
const tests = [];
async function testFileImports() {
console.log('1. Testing File Imports...');
try {
// Test core action files
const fs = await import('fs');
const path = await import('path');
const criticalFiles = [
'app/actions/story/references.ts',
'app/actions/commercial/generate.ts',
'app/actions/image-edit.ts',
'components/containers/StoryContainer.tsx',
'components/containers/CommercialContainer.tsx',
'app/post-production/page.tsx',
'app/settings/page.tsx',
'lib/post-production/transfer.ts',
'lib/commercial-templates.ts',
'stores/templates-store.ts'
];
let passed = 0;
let failed = 0;
for (const file of criticalFiles) {
try {
if (fs.existsSync(file)) {
console.log(` ✓ ${file}`);
passed++;
} else {
console.log(` ✗ ${file} - NOT FOUND`);
failed++;
}
} catch (error) {
console.log(` ✗ ${file} - ERROR: ${error.message}`);
failed++;
}
}
tests.push({
test: 'File Imports',
passed,
failed,
status: failed === 0 ? 'PASS' : 'FAIL'
});
} catch (error) {
tests.push({
test: 'File Imports',
passed: 0,
failed: 1,
status: 'FAIL',
error: error.message
});
}
}
async function testStoryTransferLogic() {
console.log('\n2. Testing Story Transfer Logic...');
try {
// Simulate story shot conversion
const sampleChapterBreakdown = {
chapterId: 'chapter-1',
shots: [
'Wide shot of detective walking into warehouse',
'Close-up of briefcase on table',
'Medium shot of detective examining evidence'
]
};
// Test the ID generation logic manually
const shots = [];
sampleChapterBreakdown.shots.forEach((shotDescription, index) => {
const id = `${sampleChapterBreakdown.chapterId}_shot_${index + 1}_${Date.now()}_${Math.random().toString(36).substr(2, 4)}`;
shots.push({
id,
projectId: 'test-project',
projectType: 'story',
shotNumber: index + 1,
description: shotDescription,
sourceChapter: sampleChapterBreakdown.chapterId
});
});
// Check for unique IDs
const ids = shots.map(s => s.id);
const uniqueIds = new Set(ids);
if (ids.length === uniqueIds.size) {
console.log(' ✓ Shot IDs are unique');
console.log(` ✓ Generated ${shots.length} shots`);
console.log(` ✓ Sample ID: ${shots[0].id}`);
tests.push({
test: 'Story Transfer Logic',
passed: 3,
failed: 0,
status: 'PASS'
});
} else {
console.log(' ✗ Duplicate shot IDs found');
tests.push({
test: 'Story Transfer Logic',
passed: 0,
failed: 1,
status: 'FAIL',
error: 'Duplicate IDs generated'
});
}
} catch (error) {
console.log(` ✗ Story transfer test failed: ${error.message}`);
tests.push({
test: 'Story Transfer Logic',
passed: 0,
failed: 1,
status: 'FAIL',
error: error.message
});
}
}
async function testBrowserFeatures() {
console.log('\n3. Testing Browser Feature Dependencies...');
const features = [
{ name: 'localStorage', check: () => typeof Storage !== 'undefined' },
{ name: 'sessionStorage', check: () => typeof Storage !== 'undefined' },
{ name: 'URL.createObjectURL', check: () => typeof URL !== 'undefined' && typeof URL.createObjectURL === 'function' },
{ name: 'FileReader', check: () => typeof FileReader !== 'undefined' },
{ name: 'fetch', check: () => typeof fetch !== 'undefined' }
];
let passed = 0;
let failed = 0;
features.forEach(feature => {
try {
if (feature.check()) {
console.log(` ✓ ${feature.name} available`);
passed++;
} else {
console.log(` ✗ ${feature.name} not available`);
failed++;
}
} catch (error) {
console.log(` ✗ ${feature.name} check failed: ${error.message}`);
failed++;
}
});
tests.push({
test: 'Browser Features',
passed,
failed,
status: failed === 0 ? 'PASS' : 'FAIL'
});
}
async function testTemplateStructure() {
console.log('\n4. Testing Template System Structure...');
try {
// Test commercial template structure
const expectedCommercialTemplates = [
'tech-product-reveal',
'saas-productivity-demo',
'electronics-lifestyle-integration',
'restaurant-community-experience',
'nonprofit-impact-story'
];
// Test if we can validate template structure
const sampleTemplate = {
id: 'test-template',
name: 'Test Template',
type: 'commercial',
category: 'sample',
content: {
brandDescription: 'Test brand',
campaignGoals: 'Test goals',
targetAudience: 'Test audience',
keyMessages: 'Test messages',
constraints: 'Test constraints'
}
};
const requiredFields = ['id', 'name', 'type', 'category', 'content'];
const hasAllFields = requiredFields.every(field => sampleTemplate.hasOwnProperty(field));
if (hasAllFields) {
console.log(' ✓ Template structure validation passed');
console.log(' ✓ Required fields present:', requiredFields.join(', '));
tests.push({
test: 'Template Structure',
passed: 2,
failed: 0,
status: 'PASS'
});
} else {
console.log(' ✗ Missing required template fields');
tests.push({
test: 'Template Structure',
passed: 0,
failed: 1,
status: 'FAIL'
});
}
} catch (error) {
console.log(` ✗ Template test failed: ${error.message}`);
tests.push({
test: 'Template Structure',
passed: 0,
failed: 1,
status: 'FAIL',
error: error.message
});
}
}
async function testApiKeyValidation() {
console.log('\n5. Testing API Key Validation...');
try {
// Test API key validation logic
const validateKey = (type, key) => {
if (!key.trim()) return { valid: false, error: 'Empty key' };
if (type === 'openai') {
if (!key.startsWith('sk-')) return { valid: false, error: 'Should start with sk-' };
if (key.length < 20) return { valid: false, error: 'Too short' };
} else if (type === 'replicate') {
if (!key.startsWith('r8_')) return { valid: false, error: 'Should start with r8_' };
if (key.length < 20) return { valid: false, error: 'Too short' };
}
return { valid: true };
};
// Test cases
const testCases = [
{ type: 'openai', key: 'sk-1234567890abcdefghijk', expected: true },
{ type: 'openai', key: 'invalid-key', expected: false },
{ type: 'replicate', key: 'r8_1234567890abcdefghijk', expected: true },
{ type: 'replicate', key: 'invalid-token', expected: false },
{ type: 'openai', key: '', expected: false }
];
let passed = 0;
let failed = 0;
testCases.forEach((testCase, index) => {
const result = validateKey(testCase.type, testCase.key);
if (result.valid === testCase.expected) {
console.log(` ✓ Test case ${index + 1}: ${testCase.type} validation`);
passed++;
} else {
console.log(` ✗ Test case ${index + 1}: Expected ${testCase.expected}, got ${result.valid}`);
failed++;
}
});
tests.push({
test: 'API Key Validation',
passed,
failed,
status: failed === 0 ? 'PASS' : 'FAIL'
});
} catch (error) {
console.log(` ✗ API validation test failed: ${error.message}`);
tests.push({
test: 'API Key Validation',
passed: 0,
failed: 1,
status: 'FAIL',
error: error.message
});
}
}
// Run all tests
async function runTests() {
await testFileImports();
await testStoryTransferLogic();
await testBrowserFeatures();
await testTemplateStructure();
await testApiKeyValidation();
// Summary
console.log('\n=== TEST RESULTS SUMMARY ===');
const totalPassed = tests.reduce((sum, test) => sum + (test.passed || 0), 0);
const totalFailed = tests.reduce((sum, test) => sum + (test.failed || 0), 0);
const totalTests = tests.length;
tests.forEach(test => {
console.log(`${test.status === 'PASS' ? '✓' : '✗'} ${test.test}: ${test.status}`);
if (test.error) {
console.log(` Error: ${test.error}`);
}
});
console.log(`\nOverall: ${totalPassed} passed, ${totalFailed} failed out of ${totalTests} test suites`);
if (totalFailed > 0) {
console.log('\n⚠️ ISSUES FOUND - Application may not work correctly');
} else {
console.log('\n✅ Basic functionality tests passed');
}
}
runTests().catch(console.error);