1
0

test_slider.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 inspect
  12. from taipy.gui import Gui
  13. def test_slider_md(gui: Gui, test_client, helpers):
  14. gui._bind_var_val("x", 10)
  15. md_string = "<|{x}|slider|>"
  16. expected_list = [
  17. "<Slider",
  18. 'updateVarName="_TpN_tpec_TpExPr_x_TPMDL_0',
  19. "defaultValue={10}",
  20. "value={_TpN_tpec_TpExPr_x_TPMDL_0}",
  21. ]
  22. helpers.test_control_md(gui, md_string, expected_list)
  23. def test_slider_with_min_max(gui: Gui, test_client, helpers):
  24. gui._bind_var_val("x", 0)
  25. md_string = "<|{x}|slider|min=-10|max=10|>"
  26. expected_list = ["<Slider", "min={-10.0}", "max={10.0}", "defaultValue={0}"]
  27. helpers.test_control_md(gui, md_string, expected_list)
  28. def test_slider_with_dict_labels_md(gui: Gui, helpers):
  29. sel = "Item 1" # noqa: F841
  30. labels = {"Item 1": "Label Start", "Item 3": "Label End"} # noqa: F841
  31. if frame := inspect.currentframe():
  32. gui._set_frame(frame)
  33. md_string = "<|{sel}|slider|lov=Item 1;Item 2;Item 3|labels={labels}|>"
  34. expected_list = [
  35. "<Slider",
  36. 'labels="{&quot;Item 1&quot;: &quot;Label Start&quot;, &quot;Item 3&quot;: &quot;Label End&quot;}"',
  37. ]
  38. helpers.test_control_md(gui, md_string, expected_list)
  39. def test_slider_with_boolean_labels_md(gui: Gui, helpers):
  40. sel = "Item 1" # noqa: F841
  41. if frame := inspect.currentframe():
  42. gui._set_frame(frame)
  43. md_string = "<|{sel}|slider|lov=Item 1;Item 2;Item 3|labels|>"
  44. expected_list = ["<Slider", "labels={true}"]
  45. helpers.test_control_md(gui, md_string, expected_list)
  46. def test_slider_items_md(gui: Gui, test_client, helpers):
  47. gui._bind_var_val("x", "Item 1")
  48. md_string = "<|{x}|slider|lov=Item 1;Item 2;Item 3|text_anchor=left|>"
  49. expected_list = [
  50. "<Slider",
  51. 'updateVarName="_TpLv_tpec_TpExPr_x_TPMDL_0"',
  52. "value={_TpLv_tpec_TpExPr_x_TPMDL_0}",
  53. 'defaultLov="[&quot;Item 1&quot;, &quot;Item 2&quot;, &quot;Item 3&quot;]"',
  54. 'defaultValue="[&quot;Item 1&quot;]"',
  55. 'textAnchor="left"',
  56. ]
  57. helpers.test_control_md(gui, md_string, expected_list)
  58. def test_slider_text_anchor_md(gui: Gui, test_client, helpers):
  59. gui._bind_var_val("x", "Item 1")
  60. md_string = "<|{x}|slider|text_anchor=NoNe|>"
  61. expected_list = [
  62. "<Slider",
  63. 'updateVarName="_TpN_tpec_TpExPr_x_TPMDL_0"',
  64. "value={_TpN_tpec_TpExPr_x_TPMDL_0}",
  65. 'textAnchor="none"',
  66. ]
  67. helpers.test_control_md(gui, md_string, expected_list)
  68. def test_slider_text_anchor_default_md(gui: Gui, test_client, helpers):
  69. gui._bind_var_val("x", "Item 1")
  70. md_string = "<|{x}|slider|items=Item 1|>"
  71. expected_list = [
  72. "<Slider",
  73. 'updateVarName="_TpN_tpec_TpExPr_x_TPMDL_0"',
  74. "value={_TpN_tpec_TpExPr_x_TPMDL_0}",
  75. 'textAnchor="bottom"',
  76. ]
  77. helpers.test_control_md(gui, md_string, expected_list)
  78. def test_slider_array_md(gui: Gui, test_client, helpers):
  79. gui._bind_var_val("x", [10, 20])
  80. md_string = "<|{x}|slider|>"
  81. expected_list = [
  82. "<Slider",
  83. 'updateVarName="_TpLn_tpec_TpExPr_x_TPMDL_0"',
  84. "value={_TpLn_tpec_TpExPr_x_TPMDL_0}",
  85. ]
  86. helpers.test_control_md(gui, md_string, expected_list)
  87. def test_slider_html_1(gui: Gui, test_client, helpers):
  88. gui._bind_var_val("x", 10)
  89. html_string = '<taipy:slider value="{x}" />'
  90. expected_list = [
  91. "<Slider",
  92. 'updateVarName="_TpN_tpec_TpExPr_x_TPMDL_0"',
  93. "defaultValue={10}",
  94. "value={_TpN_tpec_TpExPr_x_TPMDL_0}",
  95. ]
  96. helpers.test_control_html(gui, html_string, expected_list)
  97. def test_slider_html_2(gui: Gui, test_client, helpers):
  98. gui._bind_var_val("x", 10)
  99. html_string = "<taipy:slider>{x}</taipy:slider>"
  100. expected_list = [
  101. "<Slider",
  102. 'updateVarName="_TpN_tpec_TpExPr_x_TPMDL_0"',
  103. "defaultValue={10}",
  104. "value={_TpN_tpec_TpExPr_x_TPMDL_0}",
  105. ]
  106. helpers.test_control_html(gui, html_string, expected_list)