test_space.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. # SPDX-License-Identifier: AGPL-3.0-only
  2. """Integration tests for Twitter Spaces support."""
  3. import pytest
  4. from seleniumbase import BaseCase
  5. class TestSpacePage(BaseCase):
  6. """Tests for /i/spaces/@id route."""
  7. SPACE_ID = "1mxPaaRAwYjKN"
  8. SPACE_URL = f"http://localhost:8080/i/spaces/{SPACE_ID}"
  9. def test_space_page_loads(self):
  10. """Space page should load with title."""
  11. self.open(self.SPACE_URL)
  12. self.assert_element(".space-page")
  13. self.assert_element(".space-panel")
  14. self.assert_text_visible("INTEL WILL MOON NEXT WEEK", ".space-title")
  15. def test_space_host_info(self):
  16. """Space should display host in participants."""
  17. self.open(self.SPACE_URL)
  18. self.assert_element(".space-participants")
  19. self.assert_text_visible("bubble boi")
  20. self.assert_element(".host-badge")
  21. def test_space_metadata(self):
  22. """Space should display listener count and state."""
  23. self.open(self.SPACE_URL)
  24. self.assert_element(".space-meta")
  25. # Should show listener count (number format)
  26. meta_text = self.get_text(".space-meta")
  27. assert any(c.isdigit() for c in meta_text), "Should show listener count"
  28. # Should show ended state
  29. assert "Ended" in meta_text or "Jun" in meta_text, "Should show ended state"
  30. def test_space_participants(self):
  31. """Space should display host and speakers."""
  32. self.open(self.SPACE_URL)
  33. self.assert_element(".space-participants")
  34. # Host should have badge
  35. self.assert_element(".host-badge")
  36. self.assert_text_visible("Host", ".host-badge")
  37. # Should show speakers
  38. self.assert_text_visible("CANTELOPEPEEL")
  39. self.assert_text_visible("Based Burner Account")
  40. self.assert_text_visible("anon invests")
  41. def test_space_participant_avatars(self):
  42. """Participant avatars should load correctly."""
  43. self.open(self.SPACE_URL)
  44. # Check avatars in participants section
  45. avatars = self.find_elements(".space-participant img")
  46. assert len(avatars) >= 4, "Should have at least 4 participant avatars"
  47. for avatar in avatars:
  48. src = avatar.get_attribute("src")
  49. # Should NOT be double-encoded
  50. assert "%2Fpic%2F" not in src, f"Avatar URL double-encoded: {src}"
  51. # Should have valid path
  52. assert "/pic/" in src, f"Avatar URL missing /pic/: {src}"
  53. def test_space_player_hls_disabled(self):
  54. """Without HLS, should show enable button with video-overlay style."""
  55. self.open(self.SPACE_URL)
  56. self.assert_element(".space-player")
  57. self.assert_element(".video-overlay")
  58. # Should show duration in overlay-duration
  59. self.assert_element(".overlay-duration")
  60. # Should have enable button
  61. source = self.get_page_source()
  62. assert "Enable hls playback" in source
  63. def test_space_player_hls_enabled(self):
  64. """With HLS enabled, should have audio element in DOM."""
  65. self.open(self.SPACE_URL)
  66. # Set HLS preference via cookie
  67. self.add_cookie({"name": "hlsPlayback", "value": "on"})
  68. self.refresh()
  69. # Check page source for audio element (hidden until play clicked)
  70. source = self.get_page_source()
  71. assert '<audio data-url="' in source, "Should have audio element"
  72. assert "playAudio(this)" in source, "Should have play handler"
  73. # Overlay should be visible (uses video-overlay class)
  74. self.assert_element(".video-overlay")
  75. def test_space_stream_endpoint(self):
  76. """Stream endpoint should return HLS manifest."""
  77. import requests
  78. resp = requests.get(f"{self.SPACE_URL}/stream")
  79. assert resp.status_code == 200
  80. assert "#EXTM3U" in resp.text
  81. assert "#EXT-X-TARGETDURATION" in resp.text
  82. class TestSpaceCard(BaseCase):
  83. """Tests for Space cards in tweets."""
  84. def test_space_card_in_tweet(self):
  85. """Tweet with Space should show card linking to Space page."""
  86. self.open("http://localhost:8080/bubbleboi/status/2065299704808960482")
  87. self.assert_element(".card")
  88. # Card should link to Space
  89. card_link = self.find_element(".card-container")
  90. href = card_link.get_attribute("href")
  91. assert "/i/spaces/" in href
  92. def test_space_card_title(self):
  93. """Space card should have title."""
  94. self.open("http://localhost:8080/bubbleboi/status/2065299704808960482")
  95. self.assert_text_visible("Twitter Space", ".card-title")
  96. class TestSpaceNotFound(BaseCase):
  97. """Tests for error handling."""
  98. def test_invalid_space_id(self):
  99. """Invalid Space ID should show error."""
  100. self.open("http://localhost:8080/i/spaces/invalid123")
  101. self.assert_text_visible("Space not found")