test_markdown_rendering.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 logging
  13. from importlib import util
  14. import pytest
  15. if util.find_spec("playwright"):
  16. from playwright._impl._page import Page
  17. from taipy.gui import Gui
  18. @pytest.mark.teste2e
  19. def test_markdown_render_with_style(page: "Page", gui: Gui, helpers):
  20. markdown_content = """
  21. <|Hey|id=text1|>
  22. <|There|id=text2|class_name=custom-text|>
  23. """
  24. style = """
  25. .taipy-text {
  26. color: green;
  27. }
  28. .custom-text {
  29. color: blue;
  30. }
  31. """
  32. if frame := inspect.currentframe():
  33. gui._set_frame(frame)
  34. gui.add_page("page1", markdown_content, style=style)
  35. helpers.run_e2e(gui)
  36. page.goto("./page1")
  37. page.expect_websocket()
  38. page.wait_for_selector("#text1")
  39. page.wait_for_selector("#Taipy_style", state="attached")
  40. function_evaluated = True
  41. try:
  42. page.wait_for_function(
  43. 'window.getComputedStyle(document.querySelector("#text1"), null).getPropertyValue("color") !== "rgb(255, 255, 255)"' # noqa: E501
  44. )
  45. except Exception as e:
  46. function_evaluated = False
  47. logging.getLogger().debug(f"Function evaluation timeout.\n{e}")
  48. if function_evaluated:
  49. assert (
  50. page.evaluate('window.getComputedStyle(document.querySelector("#text1"), null).getPropertyValue("color")')
  51. == "rgb(0, 128, 0)"
  52. )
  53. assert (
  54. page.evaluate('window.getComputedStyle(document.querySelector("#text2"), null).getPropertyValue("color")')
  55. == "rgb(0, 0, 255)"
  56. )