test_tree.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # Copyright 2021-2025 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
  13. def test_tree_builder(gui: Gui, test_client, helpers):
  14. gui._bind_var_val("value", "Item 1")
  15. with tgb.Page(frame=None) as page:
  16. tgb.tree(value="{value}", lov="Item 1;Item 2;Item 3") # type: ignore[attr-defined]
  17. expected_list = [
  18. "<TreeView",
  19. 'defaultLov="[&quot;Item 1&quot;, &quot;Item 2&quot;, &quot;Item 3&quot;]"',
  20. 'defaultValue="[&quot;Item 1&quot;]"',
  21. 'updateVarName="_TpLv_tpec_TpExPr_value_TPMDL_0"',
  22. "value={_TpLv_tpec_TpExPr_value_TPMDL_0}",
  23. ]
  24. helpers.test_control_builder(gui, page, expected_list)
  25. def test_tree_expanded_builder_1(gui: Gui, test_client, helpers):
  26. gui._bind_var_val("value", "Item 1")
  27. with tgb.Page(frame=None) as page:
  28. tgb.tree(value="{value}", lov="Item 1;Item 2;Item 3", expanded=False) # type: ignore[attr-defined]
  29. expected_list = [
  30. "<TreeView",
  31. 'defaultLov="[&quot;Item 1&quot;, &quot;Item 2&quot;, &quot;Item 3&quot;]"',
  32. 'defaultValue="[&quot;Item 1&quot;]"',
  33. 'updateVarName="_TpLv_tpec_TpExPr_value_TPMDL_0"',
  34. "value={_TpLv_tpec_TpExPr_value_TPMDL_0}",
  35. "expanded={false}",
  36. ]
  37. helpers.test_control_builder(gui, page, expected_list)
  38. def test_tree_expanded_builder_2(gui: Gui, test_client, helpers):
  39. gui._bind_var_val("value", "Item 1")
  40. gui._bind_var_val("expa", ["Item1"])
  41. with tgb.Page(frame=None) as page:
  42. tgb.tree(value="{value}", lov="Item 1;Item 2;Item 3", expanded="{expa}") # type: ignore[attr-defined]
  43. expected_list = [
  44. "<TreeView",
  45. 'defaultLov="[&quot;Item 1&quot;, &quot;Item 2&quot;, &quot;Item 3&quot;]"',
  46. 'defaultValue="[&quot;Item 1&quot;]"',
  47. 'updateVarName="_TpLv_tpec_TpExPr_value_TPMDL_0"',
  48. "value={_TpLv_tpec_TpExPr_value_TPMDL_0}",
  49. 'defaultExpanded="[&quot;Item1&quot;]"',
  50. "expanded={tpec_TpExPr_expa_TPMDL_0}",
  51. 'updateVars="expanded=tpec_TpExPr_expa_TPMDL_0',
  52. ]
  53. helpers.test_control_builder(gui, page, expected_list)