1
0

test_bindings.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. from nicegui import ui
  2. from .screen import Screen
  3. def test_ui_select_with_tuple_as_key(screen: Screen):
  4. class Model:
  5. selection = None
  6. data = Model()
  7. options = {
  8. (2, 1): 'option A',
  9. (1, 2): 'option B',
  10. }
  11. data.selection = list(options.keys())[0]
  12. ui.select(options).bind_value(data, 'selection')
  13. screen.open('/')
  14. screen.should_not_contain('option B')
  15. element = screen.click('option A')
  16. screen.click_at_position(element, x=20, y=100)
  17. screen.wait(0.3)
  18. screen.should_contain('option B')
  19. screen.should_not_contain('option A')
  20. assert data.selection == (1, 2)
  21. def test_ui_select_with_list_of_tuples(screen: Screen):
  22. class Model:
  23. selection = None
  24. data = Model()
  25. options = [(1, 1), (2, 2), (3, 3)]
  26. data.selection = options[0]
  27. ui.select(options).bind_value(data, 'selection')
  28. screen.open('/')
  29. screen.should_not_contain('2,2')
  30. element = screen.click('1,1')
  31. screen.click_at_position(element, x=20, y=100)
  32. screen.wait(0.3)
  33. screen.should_contain('2,2')
  34. screen.should_not_contain('1,1')
  35. assert data.selection == (2, 2)
  36. def test_ui_select_with_list_of_lists(screen: Screen):
  37. class Model:
  38. selection = None
  39. data = Model()
  40. options = [[1, 1], [2, 2], [3, 3]]
  41. data.selection = options[0]
  42. ui.select(options).bind_value(data, 'selection')
  43. screen.open('/')
  44. screen.should_not_contain('2,2')
  45. element = screen.click('1,1')
  46. screen.click_at_position(element, x=20, y=100)
  47. screen.wait(0.3)
  48. screen.should_contain('2,2')
  49. screen.should_not_contain('1,1')
  50. assert data.selection == [2, 2]