123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- # Copyright 2023 Avaiga Private Limited
- #
- # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
- # the License. You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
- # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
- # specific language governing permissions and limitations under the License.
- from taipy.gui import Gui
- def test_selector_md_1(gui: Gui, test_client, helpers):
- gui._bind_var_val("selected_val", ["l1", "l2"])
- gui._bind_var_val("selector_properties", {"lov": [("l1", "v1"), ("l2", "v2"), ("l3", "v3")], "filter": True})
- md_string = "<|{selected_val}|selector|properties=selector_properties|multiple|>"
- expected_list = [
- "<Selector",
- 'defaultLov="[["l1", "v1"], ["l2", "v2"], ["l3", "v3"]]"',
- 'defaultValue="["l1", "l2"]"',
- "filter={true}",
- "multiple={true}",
- 'updateVarName="_TpLv_tpec_TpExPr_selected_val_TPMDL_0"',
- "value={_TpLv_tpec_TpExPr_selected_val_TPMDL_0}",
- ]
- helpers.test_control_md(gui, md_string, expected_list)
- def test_selector_md_2(gui: Gui, test_client, helpers):
- gui._bind_var_val("selected_val", "Item 2")
- md_string = "<|{selected_val}|selector|lov=Item 1;Item 2; This is a another value|>"
- expected_list = [
- "<Selector",
- 'defaultLov="["Item 1", "Item 2", " This is a another value"]"',
- 'defaultValue="["Item 2"]"',
- 'updateVarName="_TpLv_tpec_TpExPr_selected_val_TPMDL_0"',
- "value={_TpLv_tpec_TpExPr_selected_val_TPMDL_0}",
- ]
- helpers.test_control_md(gui, md_string, expected_list)
- def test_selector_md_3(gui: Gui, test_client, helpers):
- gui._bind_var_val("elt", None)
- gui._bind_var_val(
- "scenario_list",
- [{"id": "1", "name": "scenario 1"}, {"id": "3", "name": "scenario 3"}, {"id": "2", "name": "scenario 2"}],
- )
- gui._bind_var_val("selected_obj", {"id": "1", "name": "scenario 1"})
- md_string = '<|{selected_obj}|selector|lov={scenario_list}|type=Scenario|adapter={lambda elt: (elt["id"], elt["name"])}|not propagate|>'
- expected_list = [
- "<Selector",
- 'defaultLov="[["1", "scenario 1"], ["3", "scenario 3"], ["2", "scenario 2"]]"',
- 'defaultValue="["1"]"',
- "lov={_TpL_tpec_TpExPr_scenario_list_TPMDL_0}",
- "propagate={false}",
- 'updateVars="lov=_TpL_tpec_TpExPr_scenario_list_TPMDL_0"',
- 'updateVarName="_TpLv_tpec_TpExPr_selected_obj_TPMDL_0"',
- "value={_TpLv_tpec_TpExPr_selected_obj_TPMDL_0}",
- ]
- helpers.test_control_md(gui, md_string, expected_list)
- def test_selector_html_1_1(gui: Gui, test_client, helpers):
- gui._bind_var_val("selected_val", ["l1", "l2"])
- gui._bind_var_val("selector_properties", {"lov": [("l1", "v1"), ("l2", "v2"), ("l3", "v3")], "filter": True})
- html_string = '<taipy:selector value="{selected_val}" properties="selector_properties" multiple="True"/>'
- expected_list = [
- "<Selector",
- 'defaultLov="[["l1", "v1"], ["l2", "v2"], ["l3", "v3"]]"',
- 'defaultValue="["l1", "l2"]"',
- "filter={true}",
- "multiple={true}",
- 'updateVarName="_TpLv_tpec_TpExPr_selected_val_TPMDL_0"',
- "value={_TpLv_tpec_TpExPr_selected_val_TPMDL_0}",
- ]
- helpers.test_control_html(gui, html_string, expected_list)
- def test_selector_html_1_2(gui: Gui, test_client, helpers):
- gui._bind_var_val("selected_val", ["l1", "l2"])
- gui._bind_var_val("selector_properties", {"lov": [("l1", "v1"), ("l2", "v2"), ("l3", "v3")], "filter": True})
- html_string = '<taipy:selector properties="selector_properties" multiple="True">{selected_val}</taipy:selector>'
- expected_list = [
- "<Selector",
- 'defaultLov="[["l1", "v1"], ["l2", "v2"], ["l3", "v3"]]"',
- 'defaultValue="["l1", "l2"]"',
- "filter={true}",
- "multiple={true}",
- 'updateVarName="_TpLv_tpec_TpExPr_selected_val_TPMDL_0"',
- "value={_TpLv_tpec_TpExPr_selected_val_TPMDL_0}",
- ]
- helpers.test_control_html(gui, html_string, expected_list)
- def test_selector_html_2_1(gui: Gui, test_client, helpers):
- gui._bind_var_val("selected_val", "Item 2")
- html_string = '<taipy:selector value="{selected_val}" lov="Item 1;Item 2; This is a another value" />'
- expected_list = [
- "<Selector",
- 'defaultLov="["Item 1", "Item 2", " This is a another value"]"',
- 'defaultValue="["Item 2"]"',
- 'updateVarName="_TpLv_tpec_TpExPr_selected_val_TPMDL_0"',
- "value={_TpLv_tpec_TpExPr_selected_val_TPMDL_0}",
- ]
- helpers.test_control_html(gui, html_string, expected_list)
- def test_selector_html_2_2(gui: Gui, test_client, helpers):
- gui._bind_var_val("selected_val", "Item 2")
- html_string = '<taipy:selector lov="Item 1;Item 2; This is a another value">{selected_val}</taipy:selector>'
- expected_list = [
- "<Selector",
- 'defaultLov="["Item 1", "Item 2", " This is a another value"]"',
- 'defaultValue="["Item 2"]"',
- 'updateVarName="_TpLv_tpec_TpExPr_selected_val_TPMDL_0"',
- "value={_TpLv_tpec_TpExPr_selected_val_TPMDL_0}",
- ]
- helpers.test_control_html(gui, html_string, expected_list)
|