TR
apps/jumphp-ide-remote / tests / MainTest.php · commit b81e652
<?phpnamespace Tests;use App\Main;use JumPHP\Testing\AppTestCase;/** The app played without a window: the test is the page (AppTestCase, docs/tauri.md). */final class MainTest extends AppTestCase{    public function testThePageGetsItsSettings(): void    {        $s = $this->invoke('settings');        self::assertStringStartsWith('wss://', $s['relay_url']);        self::assertSame('auto', $s['net_mode']);                  // never `local`        self::assertTrue($s['native']);        self::assertEqualsWithDelta(1.5, $s['direct_head_start'], 0.001);    }    public function testTheTextsAreInTheFourteenLanguages(): void    {        $all = $this->invoke('strings');        self::assertCount(14, $all);        $keys = array_keys($all['en']);        foreach ($all as $lang => $texts) {            self::assertSame($keys, array_keys($texts), "keys of $lang");        }        self::assertSame('Waiting for the PC to allow this device…', $all['en']['waiting']);    }    public function testEveryTextIsReallyTranslated(): void    {        $all = $this->invoke('strings');        $same = ['panel_claude', 'panel_terminal', 'message_aria', 'step', 'done_line', 'tool_steps'];   // names / formats that read the same        foreach ($all as $lang => $texts) {            foreach ($texts as $key => $text) {                self::assertNotSame('', trim((string) $text), "$lang.$key is empty");                preg_match_all('/\{(\w+)\}/', $all['en'][$key], $want);                preg_match_all('/\{(\w+)\}/', (string) $text, $have);                self::assertEqualsCanonicalizing($want[1], $have[1], "placeholders of $lang.$key");                if ($lang !== 'en' && !in_array($key, $same, true) && mb_strlen($all['en'][$key]) > 12) {                    self::assertNotSame($all['en'][$key], $text, "$lang.$key is still English");                }            }        }    }    public function testADirectTargetMustLookLikeAHostAndAPort(): void    {        self::assertTrue(Main::validTarget('192.168.1.20', 41233));        self::assertTrue(Main::validTarget('fe80::1', 41233));        self::assertFalse(Main::validTarget('a b', 41233));        self::assertFalse(Main::validTarget('192.168.1.20', 0));        self::assertFalse($this->invoke('direct.open', ['id' => 'x', 'host' => '', 'port' => 1])['ok']);    }    public function testDirectBytesAreRefusedWithoutAConnection(): void    {        self::assertFalse($this->invoke('direct.write', ['id' => 'nope', 'data' => 'AA==']));        self::assertFalse($this->invoke('direct.close', ['id' => 'nope']));    }    public function testWithoutBrowserTheRuntimeIsUnsupported(): void    {        self::assertSame('unsupported', $this->invoke('runtime.state')['state']);    }}