Repository: pyscript/pyscript
File: pyscriptjs/tests/integration/test_zz_examples.py (Python)

Code before:
        submit_task_button.click()

        first_task = self.page.locator("#task-0")
        assert "Fold laundry" in first_task.inner_text()

        task_checkbox = first_task.locator("input")
        # Confirm that the new task isn't checked
        assert not task_checkbox.is_checked()

        # Let's mark it as done now
        task_checkbox.check()

        # Basic check that the task has the line-through class
        assert (
            '<p class="m-0 inline line-through">Fold laundry</p>'
            in first_task.inner_html()
        )
        self.assert_no_banners()
        self.check_tutor_generated_code(modules_to_check=["./utils.py", "./todo.py"])

    @pytest.mark.xfail(reason="fails after introducing synclink, fix me soon!")
    def test_todo_pylist(self):
        # XXX improve this test
        self.goto("examples/todo-pylist.html")
        self.wait_for_pyscript()
        assert self.page.title() == "Todo App"
        wait_for_render(self.page, "*", "<input.*?id=['\"]new-task-content['\"].*?>")
        self.assert_no_banners()
        self.check_tutor_generated_code(modules_to_check=["utils.py", "pylist.py"])

    @pytest.mark.xfail(reason="To be moved to collective and updated, see issue #686")
    def test_toga_freedom(self):
        self.goto("examples/toga/freedom.html")
        self.wait_for_pyscript()
        assert self.page.title() in ["Loading...", "Freedom Units"]
        wait_for_render(self.page, "*", "<(main|div).*?id=['\"]toga_\\d+['\"].*?>")

        page_content = self.page.content()

        assert "Fahrenheit" in page_content
        assert "Celsius" in page_content

        self.page.locator("#toga_f_input").fill("105")
        self.page.locator("button#toga_calculate").click()
        result = self.page.locator("#toga_c_input")
        assert "40.555" in result.input_value()
        self.assert_no_banners()
        self.check_tutor_generated_code()

    def test_webgl_raycaster_index(self):
        # XXX improve this test

Review comment (suggestion):
Can you add comments in here in the form or "when we type bla bla in the input element..." --> "assert bla bla"

It's not a merge blocker but I'd like for us to improve the readability of tests...

Code after:
        submit_task_button.click()

        first_task = self.page.locator("#task-0")
        assert "Fold laundry" in first_task.inner_text()

        task_checkbox = first_task.locator("input")
        # Confirm that the new task isn't checked
        assert not task_checkbox.is_checked()

        # Let's mark it as done now
        task_checkbox.check()

        # Basic check that the task has the line-through class
        assert (
            '<p class="m-0 inline line-through">Fold laundry</p>'
            in first_task.inner_html()
        )
        self.assert_no_banners()
        self.check_tutor_generated_code(modules_to_check=["./utils.py", "./todo.py"])

    def test_todo_pylist(self):
        self.goto("examples/todo-pylist.html")
        self.wait_for_pyscript()
        assert self.page.title() == "Todo App"
        wait_for_render(self.page, "*", "<input.*?id=['\"]new-task-content['\"].*?>")
        todo_input = self.page.locator("input")
        submit_task_button = self.page.locator("button#new-task-btn")

        todo_input.type("Fold laundry")
        submit_task_button.click()

        first_task = self.page.locator("div#myList-c-0")
        assert "Fold laundry" in first_task.inner_text()

        task_checkbox = first_task.locator("input")
        # Confirm that the new task isn't checked
        assert not task_checkbox.is_checked()

        # Let's mark it as done now
        task_checkbox.check()

        # Basic check that the task has the line-through class
        assert "line-through" in first_task.get_attribute("class")
        self.assert_no_banners()
        self.check_tutor_generated_code(modules_to_check=["utils.py"])

    @pytest.mark.xfail(reason="To be moved to collective and updated, see issue #686")
    def test_toga_freedom(self):
        self.goto("examples/toga/freedom.html")
        self.wait_for_pyscript()
        assert self.page.title() in ["Loading...", "Freedom Units"]