Skip to content

Commit

Permalink
Create e2e test for checkbox
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwillchen committed Dec 13, 2023
1 parent 02b90f9 commit 147611f
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 0 deletions.
13 changes: 13 additions & 0 deletions mesop/components/checkbox/e2e/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
load("//build_defs:defaults.bzl", "py_library")

package(
default_visibility = ["//build_defs:mesop_internal"],
)

py_library(
name = "e2e",
srcs = glob(["*.py"]),
deps = [
"//mesop",
],
)
1 change: 1 addition & 0 deletions mesop/components/checkbox/e2e/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import checkbox_app as checkbox_app
22 changes: 22 additions & 0 deletions mesop/components/checkbox/e2e/checkbox_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import mesop as me


@me.stateclass
class State:
checked: bool = False


@me.on(me.CheckboxEvent)
def on_update(event: me.CheckboxEvent):
state = me.state(State)
state.checked = event.checked


@me.page(path="/components/checkbox/e2e/checkbox_app")
def app():
me.checkbox(label="checkbox", on_update=on_update)
state = me.state(State)
if state.checked:
me.text(text="is checked")
else:
me.text(text="is not checked")
13 changes: 13 additions & 0 deletions mesop/components/checkbox/e2e/checkbox_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {test, expect} from '@playwright/test';

test('test', async ({page}) => {
await page.goto('/components/checkbox/e2e/checkbox_app');
expect(await page.getByText('is not checked').textContent()).toContain(
'is not checked',
);

await page.getByRole('checkbox').check();
expect(await page.getByText('is checked').textContent()).toContain(
'is checked',
);
});
1 change: 1 addition & 0 deletions mesop/testing/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ py_library(
"//mesop/components/markdown/e2e",
"//mesop/components/text_input/e2e",
"//mesop/components/box/e2e",
"//mesop/components/checkbox/e2e",
"//mesop/components/text/e2e",
"//mesop/examples",
],
Expand Down
1 change: 1 addition & 0 deletions mesop/testing/index.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from mesop.examples import index as index
import mesop.components.text.e2e as text_e2e
import mesop.components.box.e2e as box_e2e
import mesop.components.checkbox.e2e as checkbox_e2e
import mesop.components.text_input.e2e as text_input_e2e
import mesop.components.markdown.e2e as markdown_e2e
# REF(//scripts/gen_component.py):insert_component_e2e_import_export

0 comments on commit 147611f

Please sign in to comment.