test_toggle.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # Copyright 2023 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. from taipy.gui import Gui
  12. def test_toggle_md(gui: Gui, helpers):
  13. md_string = "<|toggle|theme|>"
  14. expected_list = ["<Toggle", 'kind="theme"', 'unselectedValue=""']
  15. helpers.test_control_md(gui, md_string, expected_list)
  16. def test_toggle_allow_unselected_md(gui: Gui, helpers):
  17. md_string = "<|toggle|lov=1;2|allow_unselect|>"
  18. expected_list = ["<Toggle", 'unselectedValue=""', "allowUnselect={true}"]
  19. helpers.test_control_md(gui, md_string, expected_list)
  20. def test_toggle_lov_md(gui: Gui, test_client, helpers):
  21. gui._bind_var_val("x", "l1")
  22. gui._bind_var_val("lov", [("l1", "v1"), ("l2", "v2")])
  23. md_string = "<|{x}|toggle|lov={lov}|label=Label|>"
  24. expected_list = [
  25. "<Toggle",
  26. 'defaultLov="[[&quot;l1&quot;, &quot;v1&quot;], [&quot;l2&quot;, &quot;v2&quot;]]"',
  27. 'defaultValue="l1"',
  28. 'label="Label"',
  29. "lov={_TpL_tpec_TpExPr_lov_TPMDL_0}",
  30. 'updateVars="lov=_TpL_tpec_TpExPr_lov_TPMDL_0"',
  31. 'updateVarName="_TpLv_tpec_TpExPr_x_TPMDL_0"',
  32. 'unselectedValue=""',
  33. "value={_TpLv_tpec_TpExPr_x_TPMDL_0}",
  34. ]
  35. helpers.test_control_md(gui, md_string, expected_list)
  36. def test_toggle_html_1(gui: Gui, helpers):
  37. html_string = '<taipy:toggle theme="True" />'
  38. expected_list = ["<Toggle", 'kind="theme"', 'unselectedValue=""']
  39. helpers.test_control_html(gui, html_string, expected_list)
  40. def test_toggle_html_2(gui: Gui, test_client, helpers):
  41. gui._bind_var_val("x", "l1")
  42. gui._bind_var_val("lov", [("l1", "v1"), ("l2", "v2")])
  43. html_string = '<taipy:toggle lov="{lov}" label="Label">{x}</taipy:toggle>'
  44. expected_list = [
  45. "<Toggle",
  46. 'defaultLov="[[&quot;l1&quot;, &quot;v1&quot;], [&quot;l2&quot;, &quot;v2&quot;]]"',
  47. 'defaultValue="l1"',
  48. 'label="Label"',
  49. "lov={_TpL_tpec_TpExPr_lov_TPMDL_0}",
  50. 'updateVars="lov=_TpL_tpec_TpExPr_lov_TPMDL_0"',
  51. 'updateVarName="_TpLv_tpec_TpExPr_x_TPMDL_0"',
  52. 'unselectedValue=""',
  53. "value={_TpLv_tpec_TpExPr_x_TPMDL_0}",
  54. ]
  55. helpers.test_control_html(gui, html_string, expected_list)