5875
Os
ollama-space-molt-player / files
ollama-space-molt-player / packages / tui / tests / manual / test-harness.tsx
3.6 KB
1import React from "react"; 2import { render, useInput } from "ink"; 3import { Box, Text } from "ink"; 4 5interface TestCase { 6 name: string; 7 component: React.ReactNode; 8 description?: string; 9} 10 11interface TestHarnessProps { 12 tests: TestCase[]; 13 title: string; 14} 15 16export function TestHarness({ tests, title }: TestHarnessProps) { 17 const [currentIndex, setCurrentIndex] = React.useState(0); 18 const currentTest = tests[currentIndex]; 19 20 useInput((input, key) => { 21 if (key.leftArrow) { 22 setCurrentIndex((prev) => Math.max(0, prev - 1)); 23 } 24 if (key.rightArrow) { 25 setCurrentIndex((prev) => Math.min(tests.length - 1, prev + 1)); 26 } 27 }); 28 29 return ( 30 <Box flexDirection="column" padding={1}> 31 <Box borderStyle="double" borderColor="cyan" padding={1} marginBottom={1}> 32 <Text bold color="cyan"> 33 {title} 34 </Text> 35 </Box> 36 37 <Box marginBottom={1}> 38 <Text dimColor> 39 Test {currentIndex + 1} of {tests.length}: {currentTest.name} 40 </Text> 41 </Box> 42 43 {currentTest.description && ( 44 <Box marginBottom={1}> 45 <Text color="gray">{currentTest.description}</Text> 46 </Box> 47 )} 48 49 <Box borderStyle="single" borderColor="blue" padding={1}> 50 {currentTest.component} 51 </Box> 52 53 <Box marginTop={1}> 54 <Text dimColor> 55 Press Ctrl+C to exit | Navigate: {currentIndex > 0 ? "← prev" : ""}{" "} 56 {currentIndex < tests.length - 1 ? "→ next" : ""} 57 </Text> 58 </Box> 59 </Box> 60 ); 61} 62 63export function runTests(title: string, tests: TestCase[]) { 64 const { unmount } = render(<TestHarness tests={tests} title={title} />); 65 66 process.on("SIGINT", () => { 67 unmount(); 68 process.exit(0); 69 }); 70} 71 72export function createMockData() { 73 return { 74 gameState: { 75 currentTick: 1337, 76 loopState: "processing_tick" as const, 77 playerName: "CaptainTest", 78 playerId: "test-001", 79 location: "Alpha Centauri - Station Prime", 80 shipName: "SS TestRunner", 81 shipHealth: 85, 82 shipFuel: 42, 83 credits: 10500, 84 cargo: [ 85 { name: "Iron Ore", quantity: 50 }, 86 { name: "Fuel Cells", quantity: 10 }, 87 { name: "Medical Supplies", quantity: 5 }, 88 ], 89 }, 90 recentActions: [ 91 { 92 tick: 1336, 93 command: "travel sector-7", 94 timestamp: "2026-02-03T10:30:00Z", 95 }, 96 { 97 tick: 1335, 98 command: "scan nearby", 99 timestamp: "2026-02-03T10:29:50Z", 100 }, 101 ], 102 recentResponses: [ 103 { 104 tick: 1336, 105 message: "Travel initiated. ETA: 2 ticks", 106 type: "success" as const, 107 timestamp: "2026-02-03T10:30:01Z", 108 }, 109 { 110 tick: 1335, 111 message: "Scan complete. 3 ships detected", 112 type: "info" as const, 113 timestamp: "2026-02-03T10:29:51Z", 114 }, 115 ], 116 chatMessages: [ 117 { 118 tick: 1336, 119 channel: "local" as const, 120 sender: "Trader_01", 121 message: "Anyone selling fuel?", 122 timestamp: "2026-02-03T10:30:00Z", 123 }, 124 { 125 tick: 1335, 126 channel: "system" as const, 127 sender: "SERVER", 128 message: "Player CaptainTest entered the sector", 129 timestamp: "2026-02-03T10:29:50Z", 130 }, 131 ], 132 forumPosts: [ 133 { 134 id: "post-1", 135 author: "AdminBot", 136 title: "Welcome to SpaceMolt!", 137 preview: "Read this guide before starting your journey...", 138 replies: 42, 139 timestamp: "2026-02-01T12:00:00Z", 140 }, 141 { 142 id: "post-2", 143 author: "Veteran_Trader", 144 title: "Best trade routes for beginners", 145 preview: "I've compiled a list of profitable routes...", 146 replies: 15, 147 timestamp: "2026-02-02T08:30:00Z", 148 }, 149 ], 150 serverMessages: [ 151 { 152 tick: 1337, 153 category: "combat", 154 message: "Enemy ship detected in range", 155 timestamp: "2026-02-03T10:30:10Z", 156 }, 157 { 158 tick: 1336, 159 category: "trade", 160 message: "Market prices updated", 161 timestamp: "2026-02-03T10:30:00Z", 162 }, 163 ], 164 }; 165}