test_dialog.py 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # Copyright 2021-2025 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. import taipy.gui.builder as tgb
  13. from taipy.gui import Gui, Markdown
  14. def test_dialog_builder_1(gui: Gui, helpers):
  15. dialog_open = False # noqa: F841
  16. gui._set_frame(inspect.currentframe())
  17. with tgb.Page(frame=None) as page:
  18. tgb.dialog(title="This is a Dialog", open="{dialog_open}", page="page_test", on_action="validate_action") # type: ignore[attr-defined]
  19. expected_list = [
  20. "<Dialog",
  21. 'onAction="validate_action"',
  22. 'page="page_test"',
  23. 'title="This is a Dialog"',
  24. 'updateVarName="_TpB_tpec_TpExPr_dialog_open_TPMDL_0"',
  25. "open={_TpB_tpec_TpExPr_dialog_open_TPMDL_0}",
  26. ]
  27. helpers.test_control_builder(gui, page, expected_list)
  28. def test_dialog_builder_2(gui: Gui, helpers):
  29. gui._set_frame(inspect.currentframe())
  30. partial = gui.add_partial(Markdown("# A partial")) # noqa: F841
  31. dialog_open = False # noqa: F841
  32. with tgb.Page(frame=None) as page:
  33. tgb.dialog( # type: ignore[attr-defined]
  34. title="Another Dialog",
  35. open="{dialog_open}",
  36. partial="{partial}",
  37. on_action="validate_action",
  38. )
  39. expected_list = [
  40. "<Dialog",
  41. 'page="TaiPy_partials',
  42. 'title="Another Dialog"',
  43. 'onAction="validate_action"',
  44. 'updateVarName="_TpB_tpec_TpExPr_dialog_open_TPMDL_0"',
  45. "open={_TpB_tpec_TpExPr_dialog_open_TPMDL_0}",
  46. ]
  47. helpers.test_control_builder(gui, page, expected_list)
  48. def test_dialog_labels_builder(gui: Gui, helpers):
  49. gui._set_frame(inspect.currentframe())
  50. dialog_open = False # noqa: F841
  51. with tgb.Page(frame=None) as page:
  52. tgb.dialog( # type: ignore[attr-defined]
  53. title="Another Dialog",
  54. open="{dialog_open}",
  55. page="page_test",
  56. labels=["Cancel", "Validate"],
  57. close_label="MYClose",
  58. )
  59. expected_list = [
  60. "<Dialog",
  61. 'page="page_test"',
  62. 'title="Another Dialog"',
  63. 'labels="[&quot;Cancel&quot;, &quot;Validate&quot;]"',
  64. 'updateVarName="_TpB_tpec_TpExPr_dialog_open_TPMDL_0"',
  65. 'closeLabel="MYClose"',
  66. "open={_TpB_tpec_TpExPr_dialog_open_TPMDL_0}",
  67. ]
  68. helpers.test_control_builder(gui, page, expected_list)
  69. def test_dialog_builder_block(gui: Gui, helpers):
  70. with tgb.dialog(title="Another Dialog") as content: # type: ignore[attr-defined]
  71. tgb.text(value="This is in a dialog") # type: ignore[attr-defined]
  72. expected_list = [
  73. "<Dialog",
  74. 'title="Another Dialog"',
  75. "This is in a dialog",
  76. ]
  77. helpers.test_control_builder(gui, tgb.Page(content, frame=None), expected_list)