test_chat_app.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. from typing import Callable
  2. import pytest
  3. from nicegui import ui
  4. from nicegui.testing import User
  5. from . import main
  6. @pytest.mark.module_under_test(main)
  7. async def test_basic_startup_appearance(user: User) -> None:
  8. """Test basic appearance of the chat app."""
  9. await user.open('/')
  10. await user.should_see('simple chat app')
  11. await user.should_see('https://robohash.org/')
  12. await user.should_see('message')
  13. await user.should_see('No messages yet')
  14. @pytest.mark.module_under_test(main)
  15. async def test_sending_messages(create_user: Callable[[], User]) -> None:
  16. """Test sending messages from two different screens."""
  17. userA = create_user()
  18. userB = create_user()
  19. await userA.open('/')
  20. userA.find(ui.input).type('Hello from screen A!').trigger('keydown.enter')
  21. await userA.should_see('Hello from screen A!')
  22. await userA.should_see('message')
  23. await userB.open('/')
  24. await userB.should_see('Hello from screen A!')
  25. userB.find(ui.input).type('Hello from screen B!').trigger('keydown.enter')
  26. await userB.should_see('message')
  27. await userA.should_see('Hello from screen A!')
  28. await userA.should_see('Hello from screen B!')