test_chat_app.py 1.2 KB

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