billscroll should now remember user's position across devices

This commit is contained in:
Disco DeDisco
2026-03-24 17:44:34 -04:00
parent a0f8aeb791
commit cde231d43c
9 changed files with 206 additions and 4 deletions

View File

@@ -1,3 +1,5 @@
import time
from selenium.webdriver.common.by import By
from .base import FunctionalTest
@@ -123,6 +125,63 @@ class BillboardScrollTest(FunctionalTest):
self.assertIn("other", theirs_events[0].text)
class BillscrollPositionTest(FunctionalTest):
"""
FT: the user's scroll position in a billscroll is saved to the server
and restored when they return to the same scroll from any device/session.
"""
def setUp(self):
super().setUp()
self.founder = User.objects.create(email="founder@scrollpos.io")
self.room = Room.objects.create(name="Persistent Chamber", owner=self.founder)
# Enough events to make #id_drama_scroll scrollable
for i in range(20):
record(
self.room, GameEvent.SLOT_FILLED, actor=self.founder,
slot_number=(i % 6) + 1, token_type="coin",
token_display=f"Coin-{i}", renewal_days=7,
)
def test_scroll_position_persists_across_sessions(self):
# 1. Log in and navigate to the room's billscroll
self.create_pre_authenticated_session("founder@scrollpos.io")
self.browser.get(
self.live_server_url + f"/billboard/room/{self.room.id}/scroll/"
)
scroll_el = self.wait_for(
lambda: self.browser.find_element(By.ID, "id_drama_scroll")
)
# 2. Force the element scrollable (CSS not served by StaticLiveServerTestCase),
# set position, and dispatch scroll event to trigger the debounced save
target = 100
self.browser.execute_script("""
var el = arguments[0];
el.style.overflow = 'auto';
el.style.height = '150px';
el.scrollTop = arguments[1];
el.dispatchEvent(new Event('scroll'));
""", scroll_el, target)
# 3. Wait for debounce (800ms) + fetch to complete
time.sleep(3)
# 4. Navigate away and back in a fresh session
self.browser.get(self.live_server_url + "/billboard/")
self.create_pre_authenticated_session("founder@scrollpos.io")
self.browser.get(
self.live_server_url + f"/billboard/room/{self.room.id}/scroll/"
)
# 5. The saved position is reflected in the page's data attribute
scroll_el = self.wait_for(
lambda: self.browser.find_element(By.ID, "id_drama_scroll")
)
restored = int(scroll_el.get_attribute("data-scroll-position"))
self.assertEqual(restored, target)
class BillboardAppletsTest(FunctionalTest):
"""
FT: billboard page renders three applets in the grid — My Scrolls,