def test_template_react_ui_example_cloud() -> None:
    """This test ensures streamlit works in the cloud by clicking a button and checking the logs."""
    with run_app_in_cloud(
            os.path.join(_PROJECT_ROOT, "examples/app_template_react_ui")) as (
                _,
                view_page,
                fetch_logs,
            ):

        def click_button(*_, **__):
            button = view_page.frame_locator("iframe").locator(
                'button:has-text("Start Printing")')
            button.wait_for(timeout=3 * 1000)
            if button.all_text_contents() == ["Start Printing"]:
                button.click()
                return True

        wait_for(view_page, click_button)

        has_logs = False
        while not has_logs:
            for log in fetch_logs():
                if "0: Hello World!" in log:
                    has_logs = True
            sleep(1)
def test_v0_app_example_cloud() -> None:
    with run_app_in_cloud(os.path.join(_PROJECT_ROOT, "examples/app_v0")) as (
        _,
        view_page,
        fetch_logs,
    ):

        def check_content(button_name, text_content):
            button = view_page.locator(f'button:has-text("{button_name}")')
            button.wait_for(timeout=3 * 1000)
            button.click()
            view_page.reload()
            locator = view_page.frame_locator("iframe").locator("div")
            locator.wait_for(timeout=3 * 1000)
            assert text_content in " ".join(locator.all_text_contents())
            return True

        wait_for(view_page, check_content, "TAB_1", "Hello from component A")
        wait_for(view_page, check_content, "TAB_2", "Hello from component B")

        has_logs = False
        while not has_logs:
            for log in fetch_logs():
                if "'a': 'a', 'b': 'b'" in log:
                    has_logs = True
            sleep(1)
def test_boring_app_example_cloud() -> None:
    with run_app_in_cloud(os.path.join(_PROJECT_ROOT, "examples/app_boring/"),
                          app_name="app_dynamic.py") as (
                              _,
                              view_page,
                              _,
                          ):

        def check_hello_there(*_, **__):
            locator = view_page.frame_locator("iframe").locator(
                'ul:has-text("Hello there!")')
            locator.wait_for(timeout=3 * 1000)
            if len(locator.all_text_contents()):
                return True

        wait_for(view_page, check_hello_there)
def test_quick_start_example_cloud() -> None:
    with run_app_in_cloud(os.path.join(
            _PROJECT_ROOT, "lightning-quick-start/")) as (_, view_page, _):

        def click_gradio_demo(*_, **__):
            button = view_page.locator('button:has-text("Interactive demo")')
            button.wait_for(timeout=3 * 1000)
            button.click()
            return True

        wait_for(view_page, click_gradio_demo)

        def check_examples(*_, **__):
            locator = view_page.frame_locator("iframe").locator(
                'button:has-text("Submit")')
            locator.wait_for(timeout=10 * 1000)
            if len(locator.all_text_contents()) > 0:
                return True

        wait_for(view_page, check_examples)