S
Solara2w ago
Edan

Testing button click

I'm using an accordion widget (v.ExpansionPanels), where each step has a Button(label="Confirm", ...) that, on click, bubbles up a state change, which, among other things, moves the accordion to the next step. This works as expected in the frontend. However, it does not seem to work in the test.
def test_step_change_on_confirm(self):
"""Test that the wizard step changes on confirm button click."""
self._assert_step_state(0, State.READY)
self._assert_step_state(1, State.INIT)

confirm_button = next(
filter(
lambda btn: "Confirm" in btn.children,
self.rc.find(v.Btn).widgets,
),
None,
)
confirm_button.click()

self._assert_step_state(0, State.SUCCESS)
self._assert_step_state(1, State.CONFIGURED) # works in the frontend, but fails here

def _assert_step_state(self, index, state):
step = self.rc.find(v.ExpansionPanel).widgets[index]
header = step.children[0]
container = header.children[0]
icon = container.children[0]
assert f"background-color: {BG_COLORS[state]}" in header.style_
assert icon.children == [STATE_ICONS[state]]
def test_step_change_on_confirm(self):
"""Test that the wizard step changes on confirm button click."""
self._assert_step_state(0, State.READY)
self._assert_step_state(1, State.INIT)

confirm_button = next(
filter(
lambda btn: "Confirm" in btn.children,
self.rc.find(v.Btn).widgets,
),
None,
)
confirm_button.click()

self._assert_step_state(0, State.SUCCESS)
self._assert_step_state(1, State.CONFIGURED) # works in the frontend, but fails here

def _assert_step_state(self, index, state):
step = self.rc.find(v.ExpansionPanel).widgets[index]
header = step.children[0]
container = header.children[0]
icon = container.children[0]
assert f"background-color: {BG_COLORS[state]}" in header.style_
assert icon.children == [STATE_ICONS[state]]
Is there some special way of testing a button's click? Note that it does change the confirmed step's state to SUCCESS. But the accordion does not move to the next step (should be indicated by the following step moving to a CONFIGURED step). Again, this works in the frontend. Just not in the test. While we're at it, ideally, I'd like to check that the accordion selected index has changed. This is possible with ipywidgets.Accordion, which exposes its selected_index trait. But ipyvuetify.ExpansionPanels does not seem to do so. I tried value (hopeful) and v_model (less hopefull), but neither worked.
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?