test_on_action.py 1.4 KB

123456789101112131415161718192021222324252627282930
  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 taipy.gui.builder as tgb
  12. from taipy.gui import Gui, notify
  13. def test_builder_on_function(gui: Gui, test_client, helpers):
  14. def on_slider(state):
  15. notify(state, "success", f"Value: {state.value}")
  16. gui._bind_var_val("on_slider", on_slider)
  17. with tgb.Page(frame=None) as page:
  18. tgb.slider(value="{value}", on_change=on_slider) # type: ignore[attr-defined] # noqa: B023
  19. expected_list = ['<Slider','onChange="on_slider"']
  20. helpers.test_control_builder(gui, page, expected_list)
  21. def test_builder_on_lambda(gui: Gui, test_client, helpers):
  22. with tgb.Page(frame=None) as page:
  23. tgb.slider(value="{value}", on_change=lambda s: notify(s, "success", f"Lambda Value: {s.value}")) # type: ignore[attr-defined] # noqa: B023
  24. expected_list = ['<Slider','onChange="__lambda_']
  25. helpers.test_control_builder(gui, page, expected_list)