Skip to content

Commit

Permalink
zauberzeug#228 add markdown and mermaid tests
Browse files Browse the repository at this point in the history
  • Loading branch information
falkoschindler committed Feb 3, 2023
1 parent ced4b0f commit ed05443
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
45 changes: 45 additions & 0 deletions tests/test_markdown.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from nicegui import ui

from .screen import Screen


def test_markdown(screen: Screen):
m = ui.markdown('This is **markdown**')

screen.open('/')
element = screen.find('This is')
assert element.text == 'This is markdown'
assert element.get_attribute('innerHTML') == 'This is <strong>markdown</strong>'

m.set_content('New **content**')
element = screen.find('New')
assert element.text == 'New content'
assert element.get_attribute('innerHTML') == 'New <strong>content</strong>'


def test_markdown_with_mermaid(screen: Screen):
m = ui.markdown('''
Mermaid:
```mermaid
graph TD;
Node_A --> Node_B;
```
''', extras=['mermaid', 'fenced-code-blocks'])

screen.open('/')
screen.should_contain('Mermaid')
assert screen.find_by_tag('svg').get_attribute('id') == f'mermaid_{m.id}_0'
assert screen.find('Node_A').get_attribute('class') == 'nodeLabel'

m.set_content('''
New:
```mermaid
graph TD;
Node_C --> Node_D;
```
''')
screen.should_contain('New')
assert screen.find('Node_C').get_attribute('class') == 'nodeLabel'
screen.should_not_contain('Node_A')
20 changes: 20 additions & 0 deletions tests/test_mermaid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from nicegui import ui

from .screen import Screen


def test_mermaid(screen: Screen):
m = ui.mermaid('''
graph TD;
Node_A --> Node_B;
''')

screen.open('/')
assert screen.find('Node_A').get_attribute('class') == 'nodeLabel'

m.set_content('''
graph TD;
Node_C --> Node_D;
''')
assert screen.find('Node_C').get_attribute('class') == 'nodeLabel'
screen.should_not_contain('Node_A')

0 comments on commit ed05443

Please sign in to comment.