test_dialog.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. 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")
  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(
  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(
  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)