test_selector_action.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # Copyright 2021-2024 Avaiga Private Limited
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
  4. # the License. You may obtain a copy of the License at
  5. #
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. #
  8. # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
  9. # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
  10. # specific language governing permissions and limitations under the License.
  11. import inspect
  12. from importlib import util
  13. import pytest
  14. if util.find_spec("playwright"):
  15. from playwright._impl._page import Page
  16. from taipy.gui import Gui, State
  17. @pytest.mark.teste2e
  18. def test_selector_action(page: "Page", gui: Gui, helpers):
  19. page_md = """
  20. <|{x}|selector|lov=Item 1;Item 2;Item 3|id=selector1|>
  21. """
  22. x = "Item 1" # noqa: F841
  23. def on_init(state: State):
  24. assert state.x == "Item 1"
  25. def on_change(state: State, var, val):
  26. if var == "x":
  27. assert val == "Item 3"
  28. gui._set_frame(inspect.currentframe())
  29. gui.add_page(name="test", page=page_md)
  30. helpers.run_e2e(gui)
  31. page.goto("./test")
  32. page.expect_websocket()
  33. page.wait_for_selector("ul#selector1")
  34. page.click('#selector1 > div[data-id="Item 3"]')
  35. page.wait_for_function(
  36. "document.querySelector('#selector1 > div[data-id=\"Item 3\"]').classList.contains('Mui-selected')"
  37. )