@@ -215,4 +215,149 @@ public function testSqlScratchpadPaneRenderWithQueryHistory(): void
215215 $ output = ob_get_clean ();
216216 $ this ->assertIsString ($ output );
217217 }
218+
219+ public function testSqlScratchpadPaneRenderFullscreen (): void
220+ {
221+ // Test fullscreen mode
222+ ob_start ();
223+ SqlScratchpadPane::render (
224+ self ::$ db ,
225+ $ this ->layout ,
226+ Layout::PANE_SCRATCHPAD ,
227+ true ,
228+ 'SELECT * FROM users ' ,
229+ null ,
230+ true
231+ );
232+ $ output = ob_get_clean ();
233+ $ this ->assertIsString ($ output );
234+ $ this ->assertStringContainsString ('SQL Scratchpad ' , $ output );
235+ }
236+
237+ public function testServerMetricsPaneRenderWithMetrics (): void
238+ {
239+ // Test with provided metrics
240+ $ metrics = [
241+ 'version ' => 'SQLite 3.40.0 ' ,
242+ 'uptime_seconds ' => 3600 ,
243+ 'threads_connected ' => 5 ,
244+ ];
245+ ob_start ();
246+ ServerMetricsPane::render (
247+ self ::$ db ,
248+ $ this ->layout ,
249+ Layout::PANE_METRICS ,
250+ true ,
251+ $ metrics
252+ );
253+ $ output = ob_get_clean ();
254+ $ this ->assertIsString ($ output );
255+ }
256+
257+ public function testServerMetricsPaneRenderWithEmptyMetrics (): void
258+ {
259+ // Test with empty metrics
260+ ob_start ();
261+ ServerMetricsPane::render (
262+ self ::$ db ,
263+ $ this ->layout ,
264+ Layout::PANE_METRICS ,
265+ true ,
266+ []
267+ );
268+ $ output = ob_get_clean ();
269+ $ this ->assertIsString ($ output );
270+ $ this ->assertStringContainsString ('No metrics available ' , $ output );
271+ }
272+
273+ public function testServerMetricsPaneFormatUptime (): void
274+ {
275+ $ reflection = new \ReflectionClass (ServerMetricsPane::class);
276+ $ method = $ reflection ->getMethod ('formatUptime ' );
277+ $ method ->setAccessible (true );
278+
279+ $ this ->assertEquals ('30s ' , $ method ->invoke (null , 30 ));
280+ $ this ->assertEquals ('5m 30s ' , $ method ->invoke (null , 330 ));
281+ // For hours, formatUptime doesn't include seconds
282+ $ this ->assertEquals ('1h 30m ' , $ method ->invoke (null , 5400 ));
283+ // For days, formatUptime doesn't include minutes or seconds
284+ $ this ->assertEquals ('2d 3h ' , $ method ->invoke (null , 185400 ));
285+ }
286+
287+ public function testServerMetricsPaneFormatBytes (): void
288+ {
289+ $ reflection = new \ReflectionClass (ServerMetricsPane::class);
290+ $ method = $ reflection ->getMethod ('formatBytes ' );
291+ $ method ->setAccessible (true );
292+
293+ // formatBytes uses number_format($size, 2), so 0 becomes "0.00 B"
294+ $ this ->assertEquals ('0.00 B ' , $ method ->invoke (null , 0 ));
295+ $ this ->assertEquals ('512.00 B ' , $ method ->invoke (null , 512 ));
296+ $ this ->assertEquals ('1.00 KB ' , $ method ->invoke (null , 1024 ));
297+ $ this ->assertEquals ('1.00 MB ' , $ method ->invoke (null , 1048576 ));
298+ $ this ->assertEquals ('1.00 GB ' , $ method ->invoke (null , 1073741824 ));
299+ }
300+
301+ public function testServerMetricsPaneTruncate (): void
302+ {
303+ $ reflection = new \ReflectionClass (ServerMetricsPane::class);
304+ $ method = $ reflection ->getMethod ('truncate ' );
305+ $ method ->setAccessible (true );
306+
307+ $ this ->assertEquals ('test ' , $ method ->invoke (null , 'test ' , 10 ));
308+ $ this ->assertEquals ('test... ' , $ method ->invoke (null , 'test string that is too long ' , 7 ));
309+ $ this ->assertEquals ('' , $ method ->invoke (null , 'test ' , 0 ));
310+ }
311+
312+ public function testSqlScratchpadPaneRenderPreview (): void
313+ {
314+ $ reflection = new \ReflectionClass (SqlScratchpadPane::class);
315+ $ method = $ reflection ->getMethod ('renderPreview ' );
316+ $ method ->setAccessible (true );
317+
318+ $ content = ['row ' => 1 , 'col ' => 1 , 'height ' => 5 , 'width ' => 80 ];
319+ ob_start ();
320+ $ method ->invoke (null , $ content , 'SELECT * FROM users ' , null );
321+ $ output = ob_get_clean ();
322+ $ this ->assertStringContainsString ('Last: ' , $ output );
323+ }
324+
325+ public function testSqlScratchpadPaneRenderPreviewWithHistory (): void
326+ {
327+ $ reflection = new \ReflectionClass (SqlScratchpadPane::class);
328+ $ method = $ reflection ->getMethod ('renderPreview ' );
329+ $ method ->setAccessible (true );
330+
331+ $ content = ['row ' => 1 , 'col ' => 1 , 'height ' => 5 , 'width ' => 80 ];
332+ ob_start ();
333+ $ method ->invoke (null , $ content , null , ['SELECT 1 ' , 'SELECT 2 ' ]);
334+ $ output = ob_get_clean ();
335+ $ this ->assertStringContainsString ('History: ' , $ output );
336+ }
337+
338+ public function testSqlScratchpadPaneRenderPreviewWithNoQueries (): void
339+ {
340+ $ reflection = new \ReflectionClass (SqlScratchpadPane::class);
341+ $ method = $ reflection ->getMethod ('renderPreview ' );
342+ $ method ->setAccessible (true );
343+
344+ $ content = ['row ' => 1 , 'col ' => 1 , 'height ' => 5 , 'width ' => 80 ];
345+ ob_start ();
346+ $ method ->invoke (null , $ content , null , null );
347+ $ output = ob_get_clean ();
348+ $ this ->assertStringContainsString ('No queries executed ' , $ output );
349+ }
350+
351+ public function testSqlScratchpadPaneRenderFullscreenMethod (): void
352+ {
353+ $ reflection = new \ReflectionClass (SqlScratchpadPane::class);
354+ $ method = $ reflection ->getMethod ('renderFullscreen ' );
355+ $ method ->setAccessible (true );
356+
357+ $ content = ['row ' => 1 , 'col ' => 1 , 'height ' => 24 , 'width ' => 80 ];
358+ ob_start ();
359+ $ method ->invoke (null , $ content , 'SELECT * FROM users ' , null );
360+ $ output = ob_get_clean ();
361+ $ this ->assertStringContainsString ('SQL Scratchpad ' , $ output );
362+ }
218363}
0 commit comments