feat: enhance web extension with export functionality and utility improvements
Some checks failed
Tests / Tests (push) Has been cancelled
ESLint Check / ESLint Check and Report Upload (push) Has been cancelled
Prettier Check / Format Check (push) Has been cancelled
Prettier Check / Format Code (push) Has been cancelled
ESLint Check / Build Base for Bundle Size Comparison (push) Has been cancelled
Some checks failed
Tests / Tests (push) Has been cancelled
ESLint Check / ESLint Check and Report Upload (push) Has been cancelled
Prettier Check / Format Check (push) Has been cancelled
Prettier Check / Format Code (push) Has been cancelled
ESLint Check / Build Base for Bundle Size Comparison (push) Has been cancelled
- Add export functionality to SessionList and Player pages - Add new utility modules: dataOperations, format, path, settings - Update manifest with export and download permissions - Enhance storage utility with new data operations - Add various test scripts and documentation files
This commit is contained in:
115
simple-export-test.js
Normal file
115
simple-export-test.js
Normal file
@@ -0,0 +1,115 @@
|
||||
// Simple test to verify export functionality without browser
|
||||
console.log('=== Simple Export Function Test ===');
|
||||
|
||||
// Test 1: Check if exportRecording function would work
|
||||
console.log('\n1. Testing export function logic...');
|
||||
|
||||
// Simulate events array
|
||||
const events = [
|
||||
{ type: 2, timestamp: 1642672800000, data: { tagName: 'div', attributes: {} } },
|
||||
{ type: 3, timestamp: 1642672801000, data: { tagName: 'button', attributes: { id: 'test' } } }
|
||||
];
|
||||
|
||||
// Simulate exportRecording function logic
|
||||
function testExportLogic() {
|
||||
if (events.length === 0) {
|
||||
console.log('✗ No events to export');
|
||||
return false;
|
||||
}
|
||||
|
||||
// 准备导出数据
|
||||
const exportData = {
|
||||
version: '1.0',
|
||||
timestamp: new Date().toISOString(),
|
||||
events: events
|
||||
};
|
||||
|
||||
// 转换为JSON字符串
|
||||
const jsonStr = JSON.stringify(exportData, null, 2);
|
||||
|
||||
// Basic validation
|
||||
try {
|
||||
const parsed = JSON.parse(jsonStr);
|
||||
if (parsed.version === '1.0' &&
|
||||
parsed.timestamp &&
|
||||
Array.isArray(parsed.events) &&
|
||||
parsed.events.length === events.length) {
|
||||
console.log('✓ Export data structure valid');
|
||||
console.log(` - Version: ${parsed.version}`);
|
||||
console.log(` - Timestamp: ${parsed.timestamp}`);
|
||||
console.log(` - Event count: ${parsed.events.length}`);
|
||||
return true;
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('✗ JSON validation failed:', e.message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const exportLogicWorks = testExportLogic();
|
||||
|
||||
// Test 2: Check file naming logic
|
||||
console.log('\n2. Testing file naming logic...');
|
||||
function testFileNaming() {
|
||||
const now = new Date();
|
||||
const timestamp = now.toISOString().slice(0, 19).replace(/:/g, '-');
|
||||
const filename = `recording-${timestamp}.json`;
|
||||
console.log(`Generated filename: ${filename}`);
|
||||
|
||||
// Check format
|
||||
const expectedPattern = /^recording-\d{4}-\d{2}-\d{2}T\d{2}-\d{2}-\d{2}\.json$/;
|
||||
if (expectedPattern.test(filename)) {
|
||||
console.log('✓ File naming format correct');
|
||||
return true;
|
||||
} else {
|
||||
console.log('✗ File naming format incorrect');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const fileNamingWorks = testFileNaming();
|
||||
|
||||
// Test 3: Check browser Blob API compatibility
|
||||
console.log('\n3. Testing browser API compatibility...');
|
||||
function testBrowserAPI() {
|
||||
// These APIs should exist in modern browsers
|
||||
const requiredAPIs = [
|
||||
'Blob',
|
||||
'URL.createObjectURL',
|
||||
'URL.revokeObjectURL',
|
||||
'document.createElement'
|
||||
];
|
||||
|
||||
const missingAPIs = requiredAPIs.filter(api => typeof globalThis[api] === 'undefined');
|
||||
|
||||
if (missingAPIs.length === 0) {
|
||||
console.log('✓ All required browser APIs available');
|
||||
return true;
|
||||
} else {
|
||||
console.log(`✗ Missing APIs: ${missingAPIs.join(', ')}`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const browserAPIsWork = testBrowserAPI();
|
||||
|
||||
// Summary
|
||||
console.log('\n=== Test Summary ===');
|
||||
console.log(`✓ Export logic works: ${exportLogicWorks}`);
|
||||
console.log(`✓ File naming works: ${fileNamingWorks}`);
|
||||
console.log(`✓ Browser APIs available: ${browserAPIsWork}`);
|
||||
|
||||
if (exportLogicWorks && fileNamingWorks && browserAPIsWork) {
|
||||
console.log('\n🎉 All export functionality tests passed!');
|
||||
console.log('The export feature should work correctly in a real browser.');
|
||||
} else {
|
||||
console.log('\n❌ Some tests failed. Check the implementation.');
|
||||
}
|
||||
|
||||
console.log('\nNext steps:');
|
||||
console.log('1. Open index.html in a browser');
|
||||
console.log('2. Click "开始录制"');
|
||||
console.log('3. Perform some actions');
|
||||
console.log('4. Click "停止录制"');
|
||||
console.log('5. Click "💾 导出录制文件" button');
|
||||
console.log('6. Verify the download starts with proper JSON data');
|
||||
Reference in New Issue
Block a user