-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-persistence.js
More file actions
89 lines (79 loc) · 2.74 KB
/
test-persistence.js
File metadata and controls
89 lines (79 loc) · 2.74 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
// Simple test to verify localStorage persistence functionality
// This can be run in the browser console to test the implementation
console.log('Testing localStorage persistence functionality...');
// Test data
const testConversation = {
id: 'test-conv-1',
question: 'What is the weather like?',
answer: 'It is sunny today.',
created_at: new Date().toISOString(),
confidence: 'high'
};
const testMemorySave = {
success: true,
response: {
memory_id: 'test-memory-1',
message: 'Memory saved successfully'
},
originalText: 'I had a great lunch today',
timestamp: new Date().toISOString()
};
const testRecallResponse = {
success: true,
response: {
success: true,
query: 'Tell me about my food experiences',
mental_state: 'The user has positive food experiences including a great lunch.',
memories: [],
memory_count: 1
},
originalQuery: 'Tell me about my food experiences',
timestamp: new Date().toISOString()
};
// Test localStorage operations
const CHAT_STORAGE_KEY = 'memory-chat-history';
const STORAGE_VERSION = '1.0';
// Create test data structure
const testData = {
version: STORAGE_VERSION,
data: {
conversations: [testConversation],
memorySaveResponses: [testMemorySave],
recallResponses: [testRecallResponse],
lastUpdated: new Date().toISOString()
},
savedAt: new Date().toISOString()
};
// Test saving to localStorage
try {
localStorage.setItem(CHAT_STORAGE_KEY, JSON.stringify(testData));
console.log('✓ Successfully saved test data to localStorage');
} catch (error) {
console.error('✗ Failed to save test data to localStorage:', error);
}
// Test loading from localStorage
try {
const savedData = localStorage.getItem(CHAT_STORAGE_KEY);
if (savedData) {
const parsed = JSON.parse(savedData);
console.log('✓ Successfully loaded test data from localStorage');
console.log('Data structure:', {
version: parsed.version,
conversations: parsed.data?.conversations?.length || 0,
memorySaves: parsed.data?.memorySaveResponses?.length || 0,
recallResponses: parsed.data?.recallResponses?.length || 0
});
} else {
console.log('✗ No data found in localStorage');
}
} catch (error) {
console.error('✗ Failed to load test data from localStorage:', error);
}
// Test clearing localStorage
try {
localStorage.removeItem(CHAT_STORAGE_KEY);
console.log('✓ Successfully cleared test data from localStorage');
} catch (error) {
console.error('✗ Failed to clear test data from localStorage:', error);
}
console.log('Persistence test completed. Check the console output above for results.');