test_dialog.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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, Markdown
  13. def test_dialog_md_1(gui: Gui, helpers):
  14. dialog_open = False # noqa: F841
  15. gui._set_frame(inspect.currentframe())
  16. md_string = "<|dialog|title=This is a Dialog|open={dialog_open}|page=page_test|on_action=validate_action|>"
  17. expected_list = [
  18. "<Dialog",
  19. 'onAction="validate_action"',
  20. 'page="page_test"',
  21. 'title="This is a Dialog"',
  22. 'updateVarName="_TpB_tpec_TpExPr_dialog_open_TPMDL_0"',
  23. "open={_TpB_tpec_TpExPr_dialog_open_TPMDL_0}",
  24. ]
  25. helpers.test_control_md(gui, md_string, expected_list)
  26. def test_dialog_md_2(gui: Gui, helpers):
  27. gui._set_frame(inspect.currentframe())
  28. partial = gui.add_partial(Markdown("# A partial")) # noqa: F841
  29. dialog_open = False # noqa: F841
  30. md_string = "<|dialog|title=Another Dialog|open={dialog_open}|partial={partial}|on_action=validate_action|>"
  31. expected_list = [
  32. "<Dialog",
  33. 'page="TaiPy_partials',
  34. 'title="Another Dialog"',
  35. 'onAction="validate_action"',
  36. 'updateVarName="_TpB_tpec_TpExPr_dialog_open_TPMDL_0"',
  37. "open={_TpB_tpec_TpExPr_dialog_open_TPMDL_0}",
  38. ]
  39. helpers.test_control_md(gui, md_string, expected_list)
  40. def test_dialog_labels_md(gui: Gui, helpers):
  41. gui._set_frame(inspect.currentframe())
  42. dialog_open = False # noqa: F841
  43. md_string = (
  44. "<|dialog|title=Another Dialog|open={dialog_open}|page=page_test|labels=Cancel;Validate|close_label=MYClose|>"
  45. )
  46. expected_list = [
  47. "<Dialog",
  48. 'page="page_test"',
  49. 'title="Another Dialog"',
  50. 'labels="[&quot;Cancel&quot;, &quot;Validate&quot;]"',
  51. 'updateVarName="_TpB_tpec_TpExPr_dialog_open_TPMDL_0"',
  52. 'closeLabel="MYClose"',
  53. "open={_TpB_tpec_TpExPr_dialog_open_TPMDL_0}",
  54. ]
  55. helpers.test_control_md(gui, md_string, expected_list)
  56. def test_dialog_html_1(gui: Gui, helpers):
  57. gui._set_frame(inspect.currentframe())
  58. dialog_open = False # noqa: F841
  59. html_string = (
  60. '<taipy:dialog title="This is a Dialog" open="{dialog_open}" page="page1" on_action="validate_action" />'
  61. )
  62. expected_list = [
  63. "<Dialog",
  64. 'page="page1"',
  65. 'title="This is a Dialog"',
  66. 'onAction="validate_action"',
  67. 'updateVarName="_TpB_tpec_TpExPr_dialog_open_TPMDL_0"',
  68. "open={_TpB_tpec_TpExPr_dialog_open_TPMDL_0}",
  69. ]
  70. helpers.test_control_html(gui, html_string, expected_list)
  71. def test_dialog_html_2(gui: Gui, helpers):
  72. gui._set_frame(inspect.currentframe())
  73. partial = gui.add_partial(Markdown("# A partial")) # noqa: F841
  74. dialog_open = False # noqa: F841
  75. html_string = (
  76. '<taipy:dialog title="Another Dialog" open="{dialog_open}" partial="{partial}" on_action="validate_action" />'
  77. )
  78. expected_list = [
  79. "<Dialog",
  80. 'page="TaiPy_partials',
  81. 'title="Another Dialog"',
  82. 'onAction="validate_action"',
  83. 'updateVarName="_TpB_tpec_TpExPr_dialog_open_TPMDL_0"',
  84. "open={_TpB_tpec_TpExPr_dialog_open_TPMDL_0}",
  85. ]
  86. helpers.test_control_html(gui, html_string, expected_list)
  87. def test_dialog_labels_html(gui: Gui, helpers):
  88. gui._set_frame(inspect.currentframe())
  89. dialog_open = False # noqa: F841
  90. html_string = (
  91. '<taipy:dialog title="Another Dialog" open="{dialog_open}" page="page_test" labels="Cancel;Validate" />'
  92. )
  93. expected_list = [
  94. "<Dialog",
  95. 'page="page_test"',
  96. 'title="Another Dialog"',
  97. 'labels="[&quot;Cancel&quot;, &quot;Validate&quot;]"',
  98. 'updateVarName="_TpB_tpec_TpExPr_dialog_open_TPMDL_0"',
  99. "open={_TpB_tpec_TpExPr_dialog_open_TPMDL_0}",
  100. ]
  101. helpers.test_control_html(gui, html_string, expected_list)