test_tree.py 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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_tree_md(gui: Gui, test_client, helpers):
  13. gui._bind_var_val("value", "Item 1")
  14. md_string = "<|{value}|tree|lov=Item 1;Item 2;Item 3|>"
  15. expected_list = [
  16. "<TreeView",
  17. 'defaultLov="[&quot;Item 1&quot;, &quot;Item 2&quot;, &quot;Item 3&quot;]"',
  18. 'defaultValue="[&quot;Item 1&quot;]"',
  19. 'updateVarName="_TpLv_tpec_TpExPr_value_TPMDL_0"',
  20. "value={_TpLv_tpec_TpExPr_value_TPMDL_0}",
  21. ]
  22. helpers.test_control_md(gui, md_string, expected_list)
  23. def test_tree_expanded_md_1(gui: Gui, test_client, helpers):
  24. gui._bind_var_val("value", "Item 1")
  25. md_string = "<|{value}|tree|lov=Item 1;Item 2;Item 3|not expanded|>"
  26. expected_list = [
  27. "<TreeView",
  28. 'defaultLov="[&quot;Item 1&quot;, &quot;Item 2&quot;, &quot;Item 3&quot;]"',
  29. 'defaultValue="[&quot;Item 1&quot;]"',
  30. 'updateVarName="_TpLv_tpec_TpExPr_value_TPMDL_0"',
  31. "value={_TpLv_tpec_TpExPr_value_TPMDL_0}",
  32. "expanded={false}",
  33. ]
  34. helpers.test_control_md(gui, md_string, expected_list)
  35. def test_tree_expanded_md_2(gui: Gui, test_client, helpers):
  36. gui._bind_var_val("value", "Item 1")
  37. gui._bind_var_val("expa", ["Item1"])
  38. md_string = "<|{value}|tree|lov=Item 1;Item 2;Item 3|expanded={expa}|>"
  39. expected_list = [
  40. "<TreeView",
  41. 'defaultLov="[&quot;Item 1&quot;, &quot;Item 2&quot;, &quot;Item 3&quot;]"',
  42. 'defaultValue="[&quot;Item 1&quot;]"',
  43. 'updateVarName="_TpLv_tpec_TpExPr_value_TPMDL_0"',
  44. "value={_TpLv_tpec_TpExPr_value_TPMDL_0}",
  45. 'defaultExpanded="[&quot;Item1&quot;]"',
  46. "expanded={tpec_TpExPr_expa_TPMDL_0}",
  47. 'updateVars="expanded=tpec_TpExPr_expa_TPMDL_0',
  48. ]
  49. helpers.test_control_md(gui, md_string, expected_list)
  50. def test_tree_html_1(gui: Gui, test_client, helpers):
  51. gui._bind_var_val("value", "Item 1")
  52. html_string = '<taipy:tree lov="Item 1;Item 2;Item 3">{value}</taipy:tree>'
  53. expected_list = [
  54. "<TreeView",
  55. 'defaultLov="[&quot;Item 1&quot;, &quot;Item 2&quot;, &quot;Item 3&quot;]"',
  56. 'defaultValue="[&quot;Item 1&quot;]"',
  57. 'updateVarName="_TpLv_tpec_TpExPr_value_TPMDL_0"',
  58. "value={_TpLv_tpec_TpExPr_value_TPMDL_0}",
  59. ]
  60. helpers.test_control_html(gui, html_string, expected_list)
  61. def test_tree_html_2(gui: Gui, test_client, helpers):
  62. gui._bind_var_val("value", "Item 1")
  63. html_string = '<taipy:tree lov="Item 1;Item 2;Item 3" value="{value}" />'
  64. expected_list = [
  65. "<TreeView",
  66. 'defaultLov="[&quot;Item 1&quot;, &quot;Item 2&quot;, &quot;Item 3&quot;]"',
  67. 'defaultValue="[&quot;Item 1&quot;]"',
  68. 'updateVarName="_TpLv_tpec_TpExPr_value_TPMDL_0"',
  69. "value={_TpLv_tpec_TpExPr_value_TPMDL_0}",
  70. ]
  71. helpers.test_control_html(gui, html_string, expected_list)