-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_core.js
More file actions
42 lines (34 loc) · 1.42 KB
/
test_core.js
File metadata and controls
42 lines (34 loc) · 1.42 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
import HistoryManager from './src/core/HistoryManager.js';
// Mock simple assertions
function assert(condition, message) {
if (!condition) {
console.error(`❌ FAILED: ${message}`);
process.exit(1);
}
console.log(`✅ PASSED: ${message}`);
}
console.log("--- Testing Core Logic (Person A) ---");
// Test Stack Logic via HistoryManager
const manager = new HistoryManager();
// 1. Initial State
const initial = manager.getSnapshot();
assert(initial.undoStack.length === 0, "Undo stack starts empty");
assert(initial.redoStack.length === 0, "Redo stack starts empty");
// 2. Push Action
manager.pushAction({ type: 'TYPING', text: 'Hello' });
const s1 = manager.getSnapshot();
assert(s1.undoStack.length === 1, "Undo stack has 1 item after push");
assert(s1.redoStack.length === 0, "Redo stack empty after push");
// 3. Undo
const undoAction = manager.undo();
const s2 = manager.getSnapshot();
assert(undoAction.text === 'Hello', "Undo returned correct action");
assert(s2.undoStack.length === 0, "Undo stack empty after undo");
assert(s2.redoStack.length === 1, "Redo stack has 1 item after undo");
// 4. Redo
const redoAction = manager.redo();
const s3 = manager.getSnapshot();
assert(redoAction.text === 'Hello', "Redo returned correct action");
assert(s3.undoStack.length === 1, "Undo stack restored");
assert(s3.redoStack.length === 0, "Redo stack empty after redo");
console.log("--- All Core Logic Tests Passed ---");