Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions __tests/test_avatar.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@


def test_display(browser: BrowserManager, page_path: str):
icon = to_ref("home")

@ui.page(page_path)
def _():
icon = to_ref("home")
rxui.avatar(icon).classes("target")

page = browser.open(page_path)
Expand All @@ -18,53 +17,58 @@ def _():


def test_change_icon(browser: BrowserManager, page_path: str):
icon = to_ref("home")

@ui.page(page_path)
def _():
icon = to_ref("home")
rxui.avatar(icon).classes("target")
ui.button("change icon", on_click=lambda: icon.set_value("add")).classes("btn")

page = browser.open(page_path)

target = page.Base(".target")
btn = page.Button(".btn")
target.expect_to_have_text("home")

icon.value = "add"
btn.click()

target.expect_to_have_text("add")


def test_bind_background_color(browser: BrowserManager, page_path: str):
bg_color = to_ref("red")

@ui.page(page_path)
def _():
bg_color = to_ref("red")
rxui.avatar("home").classes("target").bind_color(bg_color)
ui.button("change color", on_click=lambda: bg_color.set_value("green")).classes("btn")

page = browser.open(page_path)
target = page.Base(".target")
btn = page.Button(".btn")

# page.pause()
target.expect_to_contain_class("bg-red")

bg_color.value = "green"
btn.click()
target.expect_not_to_contain_class("bg-red")
target.expect_to_contain_class("bg-green")


def test_bind_text_color(browser: BrowserManager, page_path: str):
text_color = to_ref("red")

@ui.page(page_path)
def _():
text_color = to_ref("red")
rxui.avatar("home").classes("target").bind_text_color(text_color)
ui.button("change color", on_click=lambda: text_color.set_value("green")).classes("btn")

page = browser.open(page_path)
target = page.Base(".target")
btn = page.Button(".btn")

# page.pause()
target.expect_to_contain_class("text-red")

text_color.value = "green"
btn.click()
target.expect_not_to_contain_class("text-red")
target.expect_to_contain_class("text-green")
3 changes: 1 addition & 2 deletions __tests/test_badge.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@


def test_badge(browser: BrowserManager, page_path: str):
text = to_ref("badge")

@ui.page(page_path)
def _():
text = to_ref("badge")
rxui.input(value=text).classes("input")
rxui.badge(text).classes("target")

Expand Down
18 changes: 12 additions & 6 deletions __tests/test_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,42 @@


def test_ref_text(browser: BrowserManager, page_path: str):
r_text = to_ref("old text")

@ui.page(page_path)
def _():
r_text = to_ref("old text")
rxui.button(r_text).props('data-testid="target"').props("no-caps").classes(
"btn"
)
ui.button("change text").on_click(lambda: r_text.set_value("new text")).classes(
"btn-change-text"
)

page = browser.open(page_path)

btn = page.Button(".btn")
btn_change_text = page.Button(".btn-change-text")

btn.expect_to_have_text("old text")

r_text.value = "new text"
btn_change_text.click()
btn.expect_to_have_text(text="new text")


def test_enabled(browser: BrowserManager, page_path: str):
r_num = to_ref(0)

@ui.page(page_path)
def _():
r_num = to_ref(0)
rxui.button("").bind_enabled(lambda: r_num.value % 2 == 0).classes("btn")
ui.button("change num").on_click(lambda: r_num.set_value(1)).classes(
"btn-change-num"
)

page = browser.open(page_path)
btn = page.Button(".btn")
btn_change_num = page.Button(".btn-change-num")

btn.expect.to_be_enabled()

r_num.value = 1
btn_change_num.click()

btn.expect.not_to_be_enabled()
3 changes: 1 addition & 2 deletions __tests/test_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@


def test_base(browser: BrowserManager, page_path: str):
align_items = to_ref("start")

@ui.page(page_path)
def _():
align_items = to_ref("start")
rxui.select(["start", "center", "end"], value=align_items).classes("select")
rxui.card(align_items=align_items).classes("target") # type: ignore

Expand Down
12 changes: 7 additions & 5 deletions __tests/test_checkbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ def _():


def test_ref_value(browser: BrowserManager, page_path: str):
r_value = to_ref(False)

@ui.page(page_path)
def _():
r_value = to_ref(False)
rxui.checkbox("test checkbox", value=r_value).classes("target")

rxui.label(r_value).classes("value")
Expand All @@ -48,18 +47,21 @@ def _():


def test_ref_str_change_value(browser: BrowserManager, page_path: str):
r_value = to_ref(False)

@ui.page(page_path)
def _():
r_value = to_ref(False)
rxui.checkbox("test checkbox", value=r_value).classes("target")
ui.button("change value").on_click(lambda: r_value.set_value(True)).classes(
"change-value"
)

page = browser.open(page_path)

target = page.Checkbox(".target")
change_value_btn = page.Button(".change-value")

target.expect_to_be_visible()

r_value.value = True
change_value_btn.click()

target.expect.to_be_checked()
3 changes: 1 addition & 2 deletions __tests/test_chip.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@


def test_chip(browser: BrowserManager, page_path: str):
r_text = to_ref("chip")

@ui.page(page_path)
def _():
r_text = to_ref("chip")
rxui.input(value=r_text).classes("input")
rxui.chip(r_text).classes("chip")

Expand Down
9 changes: 6 additions & 3 deletions __tests/test_circular_progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@


def test_base(browser: BrowserManager, page_path: str):
value = to_ref(0.3)

@ui.page(page_path)
def _():
value = to_ref(0.3)
rxui.circular_progress(value, show_value=True, size="100px").classes("cp")
rxui.number(value=value).classes("number")
ui.button("change value").on_click(lambda: value.set_value(0.9)).classes(
"change-value"
)

page = browser.open(page_path)

cp = page.Base(".cp")
btn = page.Button(".change-value")

cp.expect.to_contain_text("0.3")

value.value = 0.9
btn.click()

cp.expect.to_contain_text("0.9")
3 changes: 1 addition & 2 deletions __tests/test_colort_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@


def test_display(browser: BrowserManager, page_path: str):
r_color = to_ref("red")

@ui.page(page_path)
def _():
r_color = to_ref("red")
rxui.color_picker(r_color).classes("target")
rxui.label(r_color).classes("label")

Expand Down
3 changes: 1 addition & 2 deletions __tests/test_column.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@


def test_base(browser: BrowserManager, page_path: str):
wrap = to_ref(True)

@ui.page(page_path)
def _():
wrap = to_ref(True)
rxui.checkbox(value=wrap).classes("checkbox")

with rxui.column(wrap=wrap).classes("target"):
Expand Down
36 changes: 23 additions & 13 deletions __tests/test_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ def _():


def test_ref_value(browser: BrowserManager, page_path: str):
r_value = to_ref("2023-01-01")

@ui.page(page_path)
def _():
r_value = to_ref("2023-01-01")
rxui.date(r_value)

page = browser.open(page_path)
Expand All @@ -41,10 +40,9 @@ def _():


def test_ref_range_value(browser: BrowserManager, page_path: str):
r_value = to_ref([{"from": "2023-01-01", "to": "2023-01-06"}, "2023-01-10"])

@ui.page(page_path)
def _():
r_value = to_ref([{"from": "2023-01-01", "to": "2023-01-06"}, "2023-01-10"])
rxui.date(r_value) # type: ignore

page = browser.open(page_path)
Expand All @@ -54,27 +52,39 @@ def _():


def test_ref_change_value(browser: BrowserManager, page_path: str):
r_single_value = to_ref("2023-01-01")
r_range_value = to_ref([{"from": "2023-01-01", "to": "2023-01-06"}])

@ui.page(page_path)
def _():
r_single_value = to_ref("2023-01-01")
r_range_value = to_ref([{"from": "2023-01-01", "to": "2023-01-06"}])
rxui.date(r_single_value).classes("single-date")
rxui.date(r_range_value).props("multiple range").classes("range-date") # type: ignore

ui.button("change single date").on_click(
lambda: r_single_value.set_value("2023-01-02")
).classes("change-single-date")
ui.button("change range date").on_click(
lambda: r_range_value.set_value(
[
{"from": "2023-01-06", "to": "2023-01-10"},
{"from": "2023-01-15", "to": "2023-01-16"},
"2023-01-12",
]
)
).classes("change-range-date") # type: ignore

page = browser.open(page_path)

single_date = page.Base(".single-date")
range_date = page.Base(".range-date")
change_single_date = page.Button(".change-single-date")
change_range_date = page.Button(".change-range-date")

expect(single_date.get_by_text("Sun, Jan 1").first).to_be_visible()
r_single_value.value = "2023-01-02"
change_single_date.click()

expect(single_date.get_by_text("Mon, Jan 2").first).to_be_visible()

expect(range_date.get_by_text("6 days").first).to_be_visible()
r_range_value.value = [
{"from": "2023-01-06", "to": "2023-01-10"},
{"from": "2023-01-15", "to": "2023-01-16"},
"2023-01-12", # type: ignore
]
change_range_date.click()

expect(range_date.get_by_text("8 days").first).to_be_visible()
7 changes: 3 additions & 4 deletions __tests/test_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@


def test_value_change(browser: BrowserManager, page_path: str):
show = to_ref(False)

@ui.page(page_path)
def _():
show = to_ref(False)

def open_dialog():
show.value = True

Expand All @@ -33,10 +33,9 @@ def close_dialog():


def test_ref_change(browser: BrowserManager, page_path: str):
show = to_ref(False)

@ui.page(page_path)
def _():
show = to_ref(False)
rxui.checkbox(value=show).classes("checkbox")

with rxui.dialog(value=show), ui.card():
Expand Down
26 changes: 13 additions & 13 deletions __tests/test_drawer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ def _():


def test_toggle_side(browser: BrowserManager, page_path: str):
r_side = to_ref("left")

def toggle_side():
if r_side.value == "left":
r_side.value = "right"
else:
r_side.value = "left"

@ui.page(page_path)
def _():
r_side = to_ref("left")

def toggle_side():
if r_side.value == "left":
r_side.value = "right"
else:
r_side.value = "left"

with rxui.drawer(r_side): # type: ignore
ui.label("drawer showed")
rxui.label(r_side)
Expand All @@ -52,13 +52,13 @@ def onclick():


def test_toggle_show(browser: BrowserManager, page_path: str):
r_show = to_ref(True)

def toggle_show():
r_show.value = not r_show.value

@ui.page(page_path)
def _():
r_show = to_ref(True)

def toggle_show():
r_show.value = not r_show.value

with rxui.drawer(value=r_show):
ui.label("drawer showed").classes("label")

Expand Down
Loading