test_margin.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 importlib import util
  13. import pytest
  14. if util.find_spec("playwright"):
  15. from playwright._impl._page import Page
  16. from taipy.gui import Gui
  17. @pytest.mark.teste2e
  18. def test_margin_1(page: "Page", gui: Gui, helpers):
  19. page_md = """
  20. <|Just a page|id=text1|>
  21. """
  22. if frame := inspect.currentframe():
  23. gui._set_frame(frame)
  24. gui.add_page(name="test", page=page_md)
  25. helpers.run_e2e(gui, dark_mode=False, margin="10rem")
  26. page.goto("./")
  27. page.expect_websocket()
  28. page.wait_for_selector("#text1")
  29. margin = page.evaluate('window.getComputedStyle(document.querySelector("#root"), null).getPropertyValue("margin")')
  30. assert margin == "160px"
  31. @pytest.mark.teste2e
  32. def test_margin_2(page: "Page", gui: Gui, helpers):
  33. page_md = """
  34. <|Just a page|id=text1|>
  35. """
  36. if frame := inspect.currentframe():
  37. gui._set_frame(frame)
  38. gui.add_page(name="test", page=page_md)
  39. helpers.run_e2e(gui, dark_mode=False)
  40. page.goto("./")
  41. page.expect_websocket()
  42. page.wait_for_selector("#text1")
  43. margin = page.evaluate('window.getComputedStyle(document.querySelector("#root"), null).getPropertyValue("margin")')
  44. assert margin == "16px"
  45. @pytest.mark.teste2e
  46. def test_margin_3(page: "Page", gui: Gui, helpers):
  47. page_md = """
  48. <|Just a page|id=text1|>
  49. """
  50. if frame := inspect.currentframe():
  51. gui._set_frame(frame)
  52. gui.add_page(name="test", page=page_md)
  53. helpers.run_e2e(gui, dark_mode=False, margin="10rem", stylekit=True)
  54. page.goto("./")
  55. page.expect_websocket()
  56. page.wait_for_selector("#text1")
  57. margin = page.evaluate('window.getComputedStyle(document.querySelector("#root"), null).getPropertyValue("margin")')
  58. assert margin == "160px"
  59. @pytest.mark.teste2e
  60. def test_margin_4(page: "Page", gui: Gui, helpers):
  61. page_md = """
  62. <|Just a page|id=text1|>
  63. """
  64. if frame := inspect.currentframe():
  65. gui._set_frame(frame)
  66. gui.add_page(name="test", page=page_md)
  67. helpers.run_e2e(gui, dark_mode=False, stylekit={"root_margin": "20rem"})
  68. page.goto("./")
  69. page.expect_websocket()
  70. page.wait_for_selector("#text1")
  71. margin = page.evaluate('window.getComputedStyle(document.querySelector("#root"), null).getPropertyValue("margin")')
  72. assert margin == "320px"
  73. @pytest.mark.teste2e
  74. def test_margin_5(page: "Page", gui: Gui, helpers):
  75. page_md = """
  76. <|Just a page|id=text1|>
  77. """
  78. if frame := inspect.currentframe():
  79. gui._set_frame(frame)
  80. gui.add_page(name="test", page=page_md)
  81. helpers.run_e2e(gui, dark_mode=False, stylekit={"root_margin": "20rem"}, margin="10rem")
  82. page.goto("./")
  83. page.expect_websocket()
  84. page.wait_for_selector("#text1")
  85. margin = page.evaluate('window.getComputedStyle(document.querySelector("#root"), null).getPropertyValue("margin")')
  86. assert margin == "320px"