test_color_input.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. from selenium.webdriver.common.keys import Keys
  2. from nicegui import ui
  3. from nicegui.testing import Screen
  4. def test_entering_color(screen: Screen):
  5. ui.color_input(label='Color', on_change=lambda e: ui.label(f'content: {e.value}'), preview=True)
  6. screen.open('/')
  7. screen.type(Keys.TAB)
  8. screen.type('#001100')
  9. screen.should_contain('content: #001100')
  10. button = screen.find_by_class('q-btn')
  11. assert button.value_of_css_property('background-color') == 'rgba(0, 17, 0, 1)'
  12. def test_picking_color(screen: Screen):
  13. ui.color_input(label='Color', on_change=lambda e: output.set_text(e.value))
  14. output = ui.label()
  15. screen.open('/')
  16. screen.click('colorize')
  17. screen.click_at_position(screen.find('HEX'), x=0, y=60)
  18. content = screen.find_by_class('q-color-picker__header-content')
  19. assert content.value_of_css_property('background-color') in {'rgba(245, 186, 186, 1)', 'rgba(245, 184, 184, 1)'}
  20. assert output.text in {'#f5baba', '#f5b8b8'}
  21. screen.type(Keys.ESCAPE)
  22. screen.wait(0.5)
  23. screen.should_not_contain('HEX')
  24. screen.click('colorize')
  25. content = screen.find_by_class('q-color-picker__header-content')
  26. assert content.value_of_css_property('background-color') in {'rgba(245, 186, 186, 1)', 'rgba(245, 184, 184, 1)'}
  27. assert output.text in {'#f5baba', '#f5b8b8'}