test_selector.py 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. import taipy.gui.builder as tgb
  12. from taipy.gui import Gui
  13. def test_selector_builder_1(gui: Gui, test_client, helpers):
  14. gui._bind_var_val("selected_val", ["l1", "l2"])
  15. gui._bind_var_val("selector_properties", {"lov": [("l1", "v1"), ("l2", "v2"), ("l3", "v3")], "filter": True})
  16. with tgb.Page(frame=None) as page:
  17. tgb.selector(value="{selected_val}", properties="{selector_properties}", multiple=True)
  18. expected_list = [
  19. "<Selector",
  20. 'defaultLov="[[&quot;l1&quot;, &quot;v1&quot;], [&quot;l2&quot;, &quot;v2&quot;], [&quot;l3&quot;, &quot;v3&quot;]]"',
  21. 'defaultValue="[&quot;l1&quot;, &quot;l2&quot;]"',
  22. "filter={true}",
  23. "multiple={true}",
  24. 'updateVarName="_TpLv_tpec_TpExPr_selected_val_TPMDL_0"',
  25. "value={_TpLv_tpec_TpExPr_selected_val_TPMDL_0}",
  26. ]
  27. helpers.test_control_builder(gui, page, expected_list)
  28. def test_selector_builder_2(gui: Gui, test_client, helpers):
  29. gui._bind_var_val("selected_val", "Item 2")
  30. with tgb.Page(frame=None) as page:
  31. tgb.selector(value="{selected_val}", lov="Item 1;Item 2; This is a another value")
  32. expected_list = [
  33. "<Selector",
  34. 'defaultLov="[&quot;Item 1&quot;, &quot;Item 2&quot;, &quot; This is a another value&quot;]"',
  35. 'defaultValue="[&quot;Item 2&quot;]"',
  36. 'updateVarName="_TpLv_tpec_TpExPr_selected_val_TPMDL_0"',
  37. "value={_TpLv_tpec_TpExPr_selected_val_TPMDL_0}",
  38. ]
  39. helpers.test_control_builder(gui, page, expected_list)
  40. def test_selector_builder_3(gui: Gui, test_client, helpers):
  41. gui._bind_var_val("elt", None)
  42. gui._bind_var_val(
  43. "scenario_list",
  44. [{"id": "1", "name": "scenario 1"}, {"id": "3", "name": "scenario 3"}, {"id": "2", "name": "scenario 2"}],
  45. )
  46. gui._bind_var_val("selected_obj", {"id": "1", "name": "scenario 1"})
  47. with tgb.Page(frame=None) as page:
  48. tgb.selector(
  49. value="{selected_obj}",
  50. lov="{scenario_list}",
  51. adapter="{lambda elt: (elt['id'], elt['name'])}",
  52. propagate=False,
  53. )
  54. expected_list = [
  55. "<Selector",
  56. 'defaultLov="[[&quot;1&quot;, &quot;scenario 1&quot;], [&quot;3&quot;, &quot;scenario 3&quot;], [&quot;2&quot;, &quot;scenario 2&quot;]]"',
  57. 'defaultValue="[&quot;1&quot;]"',
  58. "lov={_TpL_tpec_TpExPr_scenario_list_TPMDL_0}",
  59. "propagate={false}",
  60. 'updateVars="lov=_TpL_tpec_TpExPr_scenario_list_TPMDL_0"',
  61. 'updateVarName="_TpLv_tpec_TpExPr_selected_obj_TPMDL_0"',
  62. "value={_TpLv_tpec_TpExPr_selected_obj_TPMDL_0}",
  63. ]
  64. helpers.test_control_builder(gui, page, expected_list)