test_markdown.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. from nicegui import ui
  2. from .screen import Screen
  3. def test_markdown(screen: Screen):
  4. m = ui.markdown('This is **Markdown**')
  5. screen.open('/')
  6. element = screen.find('This is')
  7. assert element.text == 'This is Markdown'
  8. assert element.get_attribute('innerHTML') == 'This is <strong>Markdown</strong>'
  9. m.set_content('New **content**')
  10. element = screen.find('New')
  11. assert element.text == 'New content'
  12. assert element.get_attribute('innerHTML') == 'New <strong>content</strong>'
  13. def test_markdown_with_mermaid(screen: Screen):
  14. m = ui.markdown('''
  15. Mermaid:
  16. ```mermaid
  17. graph TD;
  18. Node_A --> Node_B;
  19. ```
  20. ''', extras=['mermaid', 'fenced-code-blocks'])
  21. screen.open('/')
  22. screen.should_contain('Mermaid')
  23. assert screen.find_by_tag('svg').get_attribute('id') == f'mermaid_{m.id}_0'
  24. assert screen.find('Node_A').get_attribute('class') == 'nodeLabel'
  25. m.set_content('''
  26. New:
  27. ```mermaid
  28. graph TD;
  29. Node_C --> Node_D;
  30. ```
  31. ''')
  32. screen.should_contain('New')
  33. assert screen.find('Node_C').get_attribute('class') == 'nodeLabel'
  34. screen.should_not_contain('Node_A')
  35. def test_strip_indentation(screen: Screen):
  36. ui.markdown('''
  37. **This is Markdown.**
  38. ''')
  39. screen.open('/')
  40. screen.should_contain('This is Markdown.')
  41. screen.should_not_contain('**This is Markdown.**') # NOTE: '**' are translated to formatting and not visible