Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add some backend var state inheritance tests #2685

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 39 additions & 0 deletions integration/test_state_inheritance.py
Expand Up @@ -77,32 +77,47 @@ def on_click_other_mixin(self):
)

class Base1(rx.State, Mixin):
_base1: str = "_base1"
base1: str = "base1"

@rx.var
def computed_basevar(self) -> str:
return "computed_basevar1"

@rx.var
def computed_backend_vars_base1(self) -> str:
return self._base1

class Base2(rx.State):
_base2: str = "_base2"
base2: str = "base2"

@rx.var
def computed_basevar(self) -> str:
return "computed_basevar2"

@rx.var
def computed_backend_vars_base2(self) -> str:
return self._base2

class Child1(Base1, OtherMixin):
pass

class Child2(Base2, Mixin, OtherMixin):
pass

class Child3(Child2):
_child3: str = "_child3"
child3: str = "child3"

@rx.var
def computed_childvar(self) -> str:
return "computed_childvar"

@rx.var
def computed_backend_vars_child3(self) -> str:
return f"{self._base2}.{self._child3}"

def index() -> rx.Component:
return rx.vstack(
rx.chakra.input(
Expand All @@ -118,9 +133,15 @@ def index() -> rx.Component:
on_click=Base1.on_click_mixin, # type: ignore
id="base1-mixin-btn",
),
rx.heading(
Base1.computed_backend_vars_base1, id="base1-computed_backend_vars"
),
# Base 2
rx.heading(Base2.computed_basevar, id="base2-computed_basevar"),
rx.heading(Base2.base2, id="base2-base2"),
rx.heading(
Base2.computed_backend_vars_base2, id="base2-computed_backend_vars"
),
# Child 1
rx.heading(Child1.computed_basevar, id="child1-computed_basevar"),
rx.heading(Child1.computed_mixin, id="child1-computed_mixin"),
Expand Down Expand Up @@ -169,6 +190,9 @@ def index() -> rx.Component:
on_click=Child3.on_click_other_mixin, # type: ignore
id="child3-other-mixin-btn",
),
rx.heading(
Child3.computed_backend_vars_child3, id="child3-computed_backend_vars"
),
)

app = rx.App()
Expand Down Expand Up @@ -262,13 +286,23 @@ def test_state_inheritance(
base1_base1 = driver.find_element(By.ID, "base1-base1")
assert base1_base1.text == "base1"

base1_computed_backend_vars = driver.find_element(
By.ID, "base1-computed_backend_vars"
)
assert base1_computed_backend_vars.text == "_base1"

# Base 2
base2_computed_basevar = driver.find_element(By.ID, "base2-computed_basevar")
assert base2_computed_basevar.text == "computed_basevar2"

base2_base2 = driver.find_element(By.ID, "base2-base2")
assert base2_base2.text == "base2"

base2_computed_backend_vars = driver.find_element(
By.ID, "base2-computed_backend_vars"
)
assert base2_computed_backend_vars.text == "_base2"

# Child 1
child1_computed_basevar = driver.find_element(By.ID, "child1-computed_basevar")
assert child1_computed_basevar.text == "computed_basevar1"
Expand Down Expand Up @@ -332,6 +366,11 @@ def test_state_inheritance(
child3_other_mixin = driver.find_element(By.ID, "child3-other_mixin")
assert child3_other_mixin.text == "other_mixin"

child3_computed_backend_vars = driver.find_element(
By.ID, "child3-computed_backend_vars"
)
assert child3_computed_backend_vars.text == "_base2._child3"

# Event Handler Tests
raises_alert(driver, "base1-mixin-btn")
raises_alert(driver, "child2-mixin-btn")
Expand Down