test_markdown_rendering.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # Copyright 2021-2024 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. gui._set_frame(inspect.currentframe())
  33. gui.add_page("page1", markdown_content, style=style)
  34. helpers.run_e2e(gui)
  35. page.goto("./page1")
  36. page.expect_websocket()
  37. page.wait_for_selector("#text1")
  38. page.wait_for_selector("#Taipy_style", state="attached")
  39. function_evaluated = True
  40. try:
  41. page.wait_for_function(
  42. 'window.getComputedStyle(document.querySelector("#text1"), null).getPropertyValue("color") !== "rgb(255, 255, 255)"' # noqa: E501
  43. )
  44. except Exception as e:
  45. function_evaluated = False
  46. logging.getLogger().debug(f"Function evaluation timeout.\n{e}")
  47. if function_evaluated:
  48. assert (
  49. page.evaluate('window.getComputedStyle(document.querySelector("#text1"), null).getPropertyValue("color")')
  50. == "rgb(0, 128, 0)"
  51. )
  52. assert (
  53. page.evaluate('window.getComputedStyle(document.querySelector("#text2"), null).getPropertyValue("color")')
  54. == "rgb(0, 0, 255)"
  55. )