from selenium.webdriver.common.by import By from .base import FunctionalTest from apps.drama.models import GameEvent, record from apps.epic.models import Room, GateSlot from apps.lyric.models import User class BillboardScrollTest(FunctionalTest): """ FT: game actions in room.html are logged to the drama stream, and the founder can navigate from any page to /billboard/ via the footer fa-scroll icon, select a room, and read the provenance scroll. Events are seeded via ORM — the IT suite covers the recording side; here we test the user-visible navigation and prose display. """ def setUp(self): super().setUp() self.founder = User.objects.create(email="founder@scroll.io") self.other = User.objects.create(email="other@scroll.io") self.room = Room.objects.create(name="Blissful Ignorance", owner=self.founder) # Simulate two gate fills — one by founder, one by the other gamer record( self.room, GameEvent.SLOT_FILLED, actor=self.founder, slot_number=1, token_type="coin", token_display="Coin-on-a-String", renewal_days=7, ) record( self.room, GameEvent.SLOT_FILLED, actor=self.other, slot_number=2, token_type="Free", token_display="Free Token", renewal_days=7, ) # Simulate founder selecting a role record( self.room, GameEvent.ROLE_SELECTED, actor=self.founder, role="PC", slot_number=1, role_display="Player", ) # ------------------------------------------------------------------ # # Test 1 — footer icon navigates to billboard, rooms listed # # ------------------------------------------------------------------ # def test_footer_scroll_icon_leads_to_billboard_with_rooms(self): # Founder logs in and lands on the dashboard self.create_pre_authenticated_session("founder@scroll.io") self.browser.get(self.live_server_url + "/") # Footer contains a scroll icon link pointing to /billboard/ scroll_link = self.wait_for( lambda: self.browser.find_element(By.CSS_SELECTOR, "#id_footer_nav a[href='/billboard/']") ) scroll_link.click() # Billboard page lists the founder's room self.wait_for( lambda: self.assertIn("/billboard/", self.browser.current_url) ) body = self.browser.find_element(By.TAG_NAME, "body") self.assertIn("Blissful Ignorance", body.text) # ------------------------------------------------------------------ # # Test 2 — scroll page renders human-readable prose # # ------------------------------------------------------------------ # def test_scroll_shows_human_readable_event_log(self): self.create_pre_authenticated_session("founder@scroll.io") self.browser.get(self.live_server_url + "/billboard/") # Click the room link to reach the scroll self.wait_for( lambda: self.browser.find_element(By.LINK_TEXT, "Blissful Ignorance") ).click() self.wait_for( lambda: self.assertIn("/scroll/", self.browser.current_url) ) scroll = self.wait_for( lambda: self.browser.find_element(By.ID, "id_drama_scroll") ) # Gate fill events are rendered as prose self.assertIn("deposits a Coin-on-a-String for slot 1 (7 days)", scroll.text) self.assertIn("deposits a Free Token for slot 2 (7 days)", scroll.text) # Role selection event is rendered as prose self.assertIn("starts as Player", scroll.text) # ------------------------------------------------------------------ # # Test 3 — current user's events are right-aligned; others' are left # # ------------------------------------------------------------------ # def test_scroll_aligns_own_events_right_and_others_left(self): self.create_pre_authenticated_session("founder@scroll.io") self.browser.get(self.live_server_url + "/billboard/") self.wait_for( lambda: self.browser.find_element(By.LINK_TEXT, "Blissful Ignorance") ).click() self.wait_for( lambda: self.browser.find_element(By.ID, "id_drama_scroll") ) mine_events = self.browser.find_elements(By.CSS_SELECTOR, ".drama-event.mine") theirs_events = self.browser.find_elements(By.CSS_SELECTOR, ".drama-event.theirs") # Founder has 2 events (slot fill + role select); other gamer has 1 self.assertEqual(len(mine_events), 2) self.assertEqual(len(theirs_events), 1) # The other gamer's event mentions their display name self.assertIn("other", theirs_events[0].text)