diff --git a/examples/tutorial/06_components/components.py b/examples/tutorial/06_components/components.py index 5718bea..4959183 100644 --- a/examples/tutorial/06_components/components.py +++ b/examples/tutorial/06_components/components.py @@ -6,7 +6,7 @@ # Using the @t.component decorator registers the component for use elsewhere @t.component() class Card(Component): - props = ["type"] + props = ["type", "button_text"] default_classes = ["card"] def populate(self): @@ -14,7 +14,7 @@ def populate(self): self.insert_slot("card-header") with t.p(): self.insert_slot() # If you don't pass a name, it defaults to the main slot - t.button("Understood", on_click=self.on_button_click) + t.button(self.button_text, on_click=self.on_button_click) def on_button_click(self, event): self.trigger_event("my-custom-event", detail={"type": self.type}) @@ -28,26 +28,26 @@ def initial(self): def populate(self): t.h1("Components are useful") - with t.card(type="success", on_my_custom_event=self.handle_custom_event) as card: + with t.card(type="success", button_text="Okay Then", on_my_custom_event=self.handle_custom_event) as card: with card.slot("card-header"): t("Success!") with card.slot(): t("Your operation worked") - with t.card(type="warning", on_my_custom_event=self.handle_custom_event) as card: + with t.card(type="warning", button_text="Got It", on_my_custom_event=self.handle_custom_event) as card: with card.slot("card-header"): t("Warning!") with card.slot(): t("Your operation may not work") - with t.card(type="error", on_my_custom_event=self.handle_custom_event) as card: + with t.card(type="error", button_text="Understood", on_my_custom_event=self.handle_custom_event) as card: with card.slot("card-header"): t("Failure!") with card.slot(): t("Your operation failed") if self.state["message"]: - t.p(self.state["message"]) + t.p(self.state["message"], id="result") def handle_custom_event(self, event): self.state["message"] = f"Custom event from card with type {event.detail.get('type')}" diff --git a/tests/integration/test_examples.py b/tests/integration/test_examples.py index 525e470..8b77388 100644 --- a/tests/integration/test_examples.py +++ b/tests/integration/test_examples.py @@ -56,7 +56,7 @@ def test_hello_world(http_server, page: Page): expect(page.locator("h1")).to_contain_text("Hello, World!") -def test_hello_name(page: Page) -> None: +def test_hello_name(page: Page): page.goto(f"http://localhost:{PORT}/") page.get_by_role("link", name="Example 2: Hello, Name").click() page.get_by_placeholder("name").click() @@ -65,7 +65,7 @@ def test_hello_name(page: Page) -> None: expect(page.locator("h1")).to_contain_text("Hello, Jack!") -def test_counter(page: Page) -> None: +def test_counter(page: Page): page.goto(f"http://localhost:{PORT}/") page.get_by_role("link", name="Example 3: Counter").click() page.get_by_role("button", name="+").click() @@ -80,7 +80,7 @@ def test_counter(page: Page) -> None: expect(page.locator(".count")).to_contain_text("-1") -def test_refs_problem(page: Page) -> None: +def test_refs_problem(page: Page): def input_is_active(): return page.evaluate("document.querySelector(\"[placeholder='Type a word']\") === document.activeElement") @@ -98,7 +98,7 @@ def input_is_active(): assert not input_is_active() -def test_refs_solution(page: Page) -> None: +def test_refs_solution(page: Page): def input_is_active(): return page.evaluate("document.querySelector(\"[placeholder='Type a word']\") === document.activeElement") @@ -109,3 +109,91 @@ def input_is_active(): assert input_is_active() page.get_by_placeholder("Type a word").fill("foobar") assert input_is_active() + + +def test_watchers(page: Page): + page.goto(f"http://localhost:{PORT}/") + page.get_by_role("link", name="Example 5: Watchers").click() + page.get_by_placeholder("Enter a guess").click() + page.get_by_placeholder("Enter a guess").fill("3") + page.get_by_text("Keep trying...").click() + page.get_by_placeholder("Enter a guess").click() + page.get_by_placeholder("Enter a guess").fill("4") + page.get_by_text("You guessed the number!").click() + + +def test_components(page: Page): + page.goto(f"http://localhost:{PORT}/") + page.get_by_role("link", name="Example 6: Components").click() + + page.get_by_role("button", name="Okay Then").click() + expect(page.locator("#result")).to_contain_text("Custom event from card with type success") + page.get_by_role("button", name="Got It").click() + expect(page.locator("#result")).to_contain_text("Custom event from card with type warning") + page.get_by_role("button", name="Understood").click() + expect(page.locator("#result")).to_contain_text("Custom event from card with type error") + + +def test_routing(page: Page): + page.goto(f"http://localhost:{PORT}/") + page.get_by_role("link", name="Example 7: Routing").click() + + page.get_by_role("heading", name="PuePy Routing Demo: Pet").click() + page.get_by_role("link", name="Scooby-Doo").click() + page.get_by_text("Scooby-Doo").click() + page.get_by_role("link", name="Back to Homepage").click() + page.get_by_role("link", name="Garfield").click() + page.get_by_text("Garfield").click() + page.get_by_role("link", name="Back to Homepage").click() + page.get_by_role("link", name="Snoopy").click() + page.get_by_text("Snoopy").click() + page.get_by_role("link", name="Back to Homepage").click() + page.get_by_role("heading", name="PuePy Routing Demo: Pet").click() + + +def test_pypi_libraries(page: Page): + page.goto(f"http://localhost:{PORT}/") + page.get_by_role("link", name="Example 8: PyPi Libraries").click() + page.get_by_role("textbox").first.click() + page.get_by_role("textbox").first.fill("\n
\n