1
0

test_dialog.py 4.4 KB

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