1
0

test_add_html.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. from nicegui import ui
  2. from nicegui.testing import Screen
  3. def test_add_head_html(screen: Screen) -> None:
  4. ui.add_head_html(r'<style>.my-label {background: rgb(0, 0, 255)}</style>')
  5. ui.label('Label').classes('my-label')
  6. ui.button('Green', on_click=lambda: ui.add_head_html(r'<style>.my-label {background: rgb(0, 255, 0)}</style>'))
  7. screen.open('/')
  8. assert screen.find('Label').value_of_css_property('background-color') == 'rgba(0, 0, 255, 1)'
  9. screen.click('Green')
  10. screen.wait(0.5)
  11. assert screen.find('Label').value_of_css_property('background-color') == 'rgba(0, 255, 0, 1)'
  12. def test_css(screen: Screen):
  13. ui.add_css('''
  14. .red {
  15. color: red;
  16. }
  17. ''')
  18. ui.label('This is red with CSS.').classes('red')
  19. screen.open('/')
  20. assert screen.find('This is red with CSS.').value_of_css_property('color') == 'rgba(255, 0, 0, 1)'
  21. def test_scss(screen: Screen):
  22. ui.add_scss('''
  23. .green {
  24. background-color: lightgreen;
  25. .blue {
  26. color: blue;
  27. }
  28. }
  29. ''')
  30. with ui.element().classes('green'):
  31. ui.label('This is blue on green with SCSS.').classes('blue')
  32. screen.open('/')
  33. assert screen.find('This is blue on green with SCSS.').value_of_css_property('color') == 'rgba(0, 0, 255, 1)'
  34. def test_sass(screen: Screen):
  35. ui.add_sass('''
  36. .yellow
  37. background-color: yellow
  38. .purple
  39. color: purple
  40. ''')
  41. with ui.element().classes('yellow'):
  42. ui.label('This is purple on yellow with SASS.').classes('purple')
  43. screen.open('/')
  44. assert screen.find('This is purple on yellow with SASS.').value_of_css_property('color') == 'rgba(128, 0, 128, 1)'