test_color_input.py 1.3 KB

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