test_dialog.py 2.9 KB

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