test_dark_mode.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. from nicegui import ui
  2. from nicegui.testing import Screen
  3. def test_dark_mode(screen: Screen):
  4. ui.label('Hello')
  5. dark = ui.dark_mode()
  6. ui.button('Dark', on_click=dark.enable)
  7. ui.button('Light', on_click=dark.disable)
  8. ui.button('Auto', on_click=dark.auto)
  9. ui.button('Toggle', on_click=dark.toggle)
  10. screen.open('/')
  11. screen.should_contain('Hello')
  12. assert screen.find_by_tag('body').get_attribute('class') == 'desktop no-touch body--light'
  13. screen.click('Dark')
  14. screen.wait(0.5)
  15. assert screen.find_by_tag('body').get_attribute('class') == 'desktop no-touch body--dark dark'
  16. screen.click('Auto')
  17. screen.wait(0.5)
  18. assert screen.find_by_tag('body').get_attribute('class') == 'desktop no-touch body--light'
  19. screen.click('Toggle')
  20. screen.wait(0.5)
  21. screen.assert_py_logger('ERROR', 'Cannot toggle dark mode when it is set to auto.')
  22. screen.click('Light')
  23. screen.wait(0.5)
  24. assert screen.find_by_tag('body').get_attribute('class') == 'desktop no-touch body--light'
  25. screen.click('Toggle')
  26. screen.wait(0.5)
  27. assert screen.find_by_tag('body').get_attribute('class') == 'desktop no-touch body--dark dark'