<?phpnamespace Tests;use JumPHP\Gui\Container;use JumPHP\Gui\Widget;/** The window at 1024 x 700 and on a phone (390 dp wide): every widget inside the view, the navigation on several lines. */final class LayoutTest extends CryoTestCase{ /** @return list<string> the shown widgets that go past the right edge */ private function outside(\App\Form\MainForm $form, float $width): array { $out = []; $walk = function (Widget $w) use (&$walk, &$out, $form, $width) { if (!$w->isShown($form->breakpoint())) { return; } if ($w->x + $w->w > $width + 1 || $w->x < -1) { $out[] = ($w->props['id'] ?: $w->type()) . sprintf(' %.0f..%.0f', $w->x, $w->x + $w->w); } if ($w instanceof Container) { foreach ($w->children as $c) { $walk($c); } } }; $walk($form->root); return $out; } public function testEveryScreenFitsTheWindowAndAPhone(): void { $form = $this->form(); $scale = $form->theme->scale; foreach (\App\Form\MainForm::VIEWS as $view => [$radio]) { $this->clickOn($form, $radio); self::assertSame('md', $form->breakpoint(), '1024 dp: md'); self::assertSame([], $this->outside($form, $form->viewWidth()), "$view at 1024 x 700"); $nav = $this->w($form, 'navStack'); self::assertEqualsWithDelta($this->w($form, 'navOverview')->y, $nav->y, 1, 'the navigation on one line'); $root = $form->root; $form->layoutTo(390 * $scale, 844 * $scale); self::assertSame('xs', $form->breakpoint()); self::assertSame([], $this->outside($form, 390 * $scale), "$view on a phone"); self::assertGreaterThan($this->w($form, 'navOverview')->y, $this->w($form, 'navStack')->y, 'the navigation wraps on a phone'); self::assertSame($root, $form->root); } } public function testTheWindowSpeaksFrench(): void { $lang = \JumPHP\Kernel\Engine::get()->lang; $lang->setLang('fr'); try { $form = $this->form(); self::assertStringContainsString('accroché par ligne 18', $this->items($form, 'rows')[0]); self::assertStringContainsString('Accroché par la ligne 18 : SqlLogger::log()', $this->text($form, 'detail')); $this->clickOn($form, 'navSeries'); self::assertStringContainsString('échantillons toutes les 50 ms', $this->text($form, 'seriesInfo')); $this->clickOn($form, 'navLeaks'); $this->game->shot('fr-leaks'); } finally { $lang->setLang('en'); } }}