async def test_mainmenu_autostart_timeout(
    ovshell: testing.OpenVarioShellStub, nosleep: None
) -> None:
    # GIVEN
    app = MockApp()
    ovshell.apps.stub_add_app("mockapp", app, MockExtension())
    ovshell.settings.set("ovshell.autostart_app", "mockapp")
    ovshell.settings.set("ovshell.autostart_timeout", 3)
    act = MainMenuActivity(ovshell)
    w = act.create()

    # WHEN
    act.activate()
    await asyncio.sleep(0)
    await asyncio.sleep(0)

    # THEN
    rendered = _render(w)

    assert "Starting Mock App in" in rendered
    assert "Press any button to cancel" in rendered

    # Let the countdown finish
    assert act.autostart_countdown_task is not None
    await act.autostart_countdown_task
    rendered = _render(w)
    assert "Press any button to cancel" not in rendered
    assert app.launched
async def test_mainmenu_autostart_immediate(
        ovshell: testing.OpenVarioShellStub, nosleep: None) -> None:
    # GIVEN
    app = MockApp()
    ovshell.apps.stub_add_app("mockapp", app, MockExtension())
    act = MainMenuActivity(ovshell, "mockapp")
    act.create()

    # WHEN
    act.activate()
    await asyncio.sleep(0)

    # THEN
    assert app.launched
async def test_mainmenu_autostart_cancel(ovshell: testing.OpenVarioShellStub,
                                         nosleep: None) -> None:
    # GIVEN
    app = MockApp()
    ovshell.settings.set("ovshell.autostart_timeout", 3)
    ovshell.apps.stub_add_app("mockapp", app, MockExtension())
    act = MainMenuActivity(ovshell, "mockapp")
    w = act.create()
    act.activate()
    await asyncio.sleep(0)
    assert "Press any button to cancel" in _render(w)

    # WHEN
    _keypress(w, ["esc"])
    await asyncio.sleep(0)

    # THEN
    rendered = _render(w)
    assert "Press any button to cancel" not in rendered
    assert act.autostart_countdown_task is not None
    assert act.autostart_countdown_task.cancelled()