test_link.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. from nicegui import ui
  2. from .screen import Screen
  3. def test_local_target_linking_on_sub_pages(screen: Screen):
  4. '''The issue arose when using <base> tag for reverse-proxy path handling. See https://github.com/zauberzeug/nicegui/pull/188#issuecomment-1336313925'''
  5. @ui.page('/sub')
  6. def main():
  7. ui.link('goto target', '#target').style('margin-bottom: 600px')
  8. ui.link_target('target')
  9. ui.label('the target')
  10. ui.label('main page')
  11. screen.open('/sub')
  12. screen.click('goto target')
  13. screen.should_contain('the target')
  14. screen.should_not_contain('main page')
  15. def test_opening_link_in_new_tab(screen: Screen):
  16. @ui.page('/sub')
  17. def subpage():
  18. ui.label('the sub-page')
  19. ui.link('open sub-page in new tab', '/sub', new_tab=True)
  20. screen.open('/')
  21. screen.click('open sub-page')
  22. screen.switch_to(1)
  23. screen.should_contain('the sub-page')
  24. screen.should_not_contain('open sub-page')
  25. screen.switch_to(0)
  26. screen.should_not_contain('the sub-page')
  27. screen.should_contain('open sub-page')
  28. def test_replace_link(screen: Screen):
  29. with ui.row() as container:
  30. ui.link('nicegui.io', 'https://nicegui.io/')
  31. def replace():
  32. container.clear()
  33. with container:
  34. ui.link('zauberzeug', 'https://zauberzeug.com/')
  35. ui.button('Replace', on_click=replace)
  36. screen.open('/')
  37. assert screen.find('nicegui.io').get_attribute('href') == 'https://nicegui.io/'
  38. screen.click('Replace')
  39. assert screen.find('zauberzeug').get_attribute('href') == 'https://zauberzeug.com/'
  40. def test_updating_href_prop(screen: Screen):
  41. l = ui.link('nicegui.io', 'https://nicegui.io')
  42. ui.button('change href', on_click=lambda: l.props('href="https://github.com/zauberzeug/nicegui"'))
  43. screen.open('/')
  44. assert screen.find('nicegui.io').get_attribute('href') == 'https://nicegui.io/'
  45. screen.click('change href')
  46. assert screen.find('nicegui.io').get_attribute('href') == 'https://github.com/zauberzeug/nicegui'