maybe don't delete collectstatic static/tests/ dir

This commit is contained in:
Disco DeDisco
2026-03-29 23:39:03 -04:00
parent 224f5e2ad0
commit fb782cf5ef
14 changed files with 15894 additions and 206 deletions

View File

@@ -8,6 +8,11 @@ class JasmineTest(FunctionalTest):
def check_results():
result = self.browser.find_element(By.CSS_SELECTOR, ".jasmine-overall-result")
self.assertIn("0 failures", result.text)
if "0 failures" not in result.text:
failures = self.browser.find_elements(
By.CSS_SELECTOR, ".jasmine-failed .jasmine-description"
)
detail = "\n".join(f.text for f in failures) if failures else "(no detail)"
self.fail(f"{result.text}\nFailing specs:\n{detail}")
self.wait_for(check_results)

View File

@@ -547,23 +547,14 @@ class RoleSelectTrayTest(FunctionalTest):
"""After confirming a role pick, the role card enters the tray grid and
the tray opens to reveal it.
Grid conventions:
Portrait — grid-auto-flow:column, 8 explicit rows. Position 0 = row 1, col 1
(topmost-leftmost). New items prepended → grid grows rightward.
Landscape — grid-auto-flow:row, 8 explicit columns, anchored to bottom.
Position 0 = row 1 (bottom), col 1. New items prepended → grid
grows upward.
"Dummy objects" in T2/T3 are prior gamers' role cards already placed in the
tray. They are injected via JS because no backend mechanism exists yet to
populate the tray for a specific gamer's view.
Portrait — card lands at the topmost grid square (first child, row 1 col 1).
Landscape — card lands at the leftmost grid square (first child, row 1 col 1).
"""
EMAILS = [
"slot1@test.io", "slot2@test.io", "slot3@test.io",
"slot4@test.io", "slot5@test.io", "slot6@test.io",
]
ALL_ROLES = ["PC", "BC", "SC", "AC", "NC", "EC"]
def setUp(self):
super().setUp()
@@ -574,21 +565,17 @@ class RoleSelectTrayTest(FunctionalTest):
slug="my-games", defaults={"name": "My Games", "context": "gameboard"}
)
def _make_room(self, active_slot=1):
"""Room in ROLE_SELECT with all 6 seats created. Seats 1..(active_slot-1)
already have roles assigned so the active_slot gamer is eligible."""
def _make_room(self):
"""Room in ROLE_SELECT with all 6 seats created, slot 1 eligible."""
founder, _ = User.objects.get_or_create(email=self.EMAILS[0])
room = Room.objects.create(name="Tray Card Test", owner=founder)
_fill_room_via_orm(room, self.EMAILS)
room.table_status = Room.ROLE_SELECT
room.save()
for slot in room.gate_slots.order_by("slot_number"):
ts = TableSeat.objects.create(
TableSeat.objects.create(
room=room, gamer=slot.gamer, slot_number=slot.slot_number
)
if slot.slot_number < active_slot:
ts.role = self.ALL_ROLES[slot.slot_number - 1]
ts.save()
return room
def _select_role(self):
@@ -602,199 +589,76 @@ class RoleSelectTrayTest(FunctionalTest):
self.browser.find_element(By.CSS_SELECTOR, "#id_role_select .card").click()
self.confirm_guard()
def _inject_prior_role_cards(self, roles):
"""Prepend tray-role-card divs into #id_tray_grid to simulate cards
placed by earlier gamers. roles is oldest-first; the final state has
the most-recent card at position 0 (front of grid)."""
self.browser.execute_script("""
var grid = document.getElementById('id_tray_grid');
var roles = arguments[0];
roles.forEach(function(role) {
var card = document.createElement('div');
card.className = 'tray-cell tray-role-card';
card.dataset.role = role;
grid.insertBefore(card, grid.firstChild);
});
""", roles)
# ------------------------------------------------------------------ #
# T1 — Portrait, position 1: empty tray, card at row 1 col 1 #
# T1 — Portrait: role card at topmost grid square, tray opens #
# ------------------------------------------------------------------ #
def test_portrait_first_role_card_enters_grid_position_zero(self):
"""Portrait, slot 1: after confirming a role, a .tray-role-card element
appears as the first child of #id_tray_grid (topmost-leftmost cell), and
the tray wrap is at least partially open."""
def test_portrait_role_card_enters_topmost_grid_square(self):
"""Portrait: after confirming a role, a .tray-role-card is the first child
of #id_tray_grid (topmost cell) and the tray is open."""
self.browser.set_window_size(390, 844)
room = self._make_room(active_slot=1)
room = self._make_room()
self.create_pre_authenticated_session("slot1@test.io")
self.browser.get(f"{self.live_server_url}/gameboard/room/{room.id}/gate/")
wrap = self.wait_for(lambda: self.browser.find_element(By.ID, "id_tray_wrap"))
# Record closed position before selection.
initial_left = self.browser.execute_script(
"return parseInt(arguments[0].style.left, 10) || window.innerWidth", wrap
)
grid_before = self.browser.execute_script(
"return document.getElementById('id_tray_grid').children.length"
)
self.wait_for(lambda: self.browser.find_element(By.ID, "id_tray_wrap"))
self._select_role()
# 1. A .tray-role-card is now in the grid.
# Card appears in the grid.
self.wait_for(
lambda: self.browser.find_element(
By.CSS_SELECTOR, "#id_tray_grid .tray-role-card"
)
)
# 2. It is the first child — topmost, leftmost in portrait.
# It is the first child — topmost in portrait.
is_first = self.browser.execute_script("""
var card = document.querySelector('#id_tray_grid .tray-role-card');
return card !== null && card === card.parentElement.firstElementChild;
""")
self.assertTrue(is_first, "Role card should be the first child of #id_tray_grid")
# 3. Exactly one item was prepended.
grid_after = self.browser.execute_script(
"return document.getElementById('id_tray_grid').children.length"
# Tray is open.
self.assertTrue(
self.browser.execute_script("return Tray.isOpen()"),
"Tray should be open after role selection"
)
self.assertEqual(grid_after, grid_before + 1)
# 4. Tray moved from closed position toward open.
current_left = self.browser.execute_script(
"return parseInt(arguments[0].style.left, 10)", wrap
)
self.assertLess(current_left, initial_left,
"Tray should have moved left (toward open) after role selection")
# ------------------------------------------------------------------ #
# T2 — Portrait, position 2: col 1 full, 8th item overflows to col 2 #
# T2 — Landscape: role card at leftmost grid square, tray opens #
# ------------------------------------------------------------------ #
def test_portrait_second_card_prepended_pushes_eighth_item_to_col_2(self):
"""Portrait, slot 2: col 1 already holds slot 1's role card (position 0)
plus 7 tray-cells (positions 1-7), filling the column. After slot 2
confirms, the new card takes position 0; the old position-7 item
(tray-cell 6) moves to col 2, row 1 (position 8)."""
self.browser.set_window_size(390, 844)
room = self._make_room(active_slot=2)
self.create_pre_authenticated_session("slot2@test.io")
self.browser.get(f"{self.live_server_url}/gameboard/room/{room.id}/gate/")
# Simulate slot 1's card already placed in the tray.
# Grid starts with 8 tray-cells; injecting 1 role card → 9 items total.
# Col 1: [PC-card, tray-0..tray-6] = 8 (full). Col 2: [tray-7].
self.wait_for(lambda: self.browser.find_element(By.ID, "id_tray_wrap"))
self._inject_prior_role_cards(["PC"])
grid_before = self.browser.execute_script(
"return document.getElementById('id_tray_grid').children.length"
)
self.assertEqual(grid_before, 9, "9 items before: 1 prior card + 8 tray-cells")
self._select_role()
# 1. Wait for grid to grow (fetch .then() is async).
self.wait_for(
lambda: self.assertEqual(
self.browser.execute_script(
"return document.getElementById('id_tray_grid').children.length"
),
grid_before + 1,
)
)
grid_after = grid_before + 1
# 2. New tray-role-card is the first child.
is_first = self.browser.execute_script("""
var card = document.querySelector('#id_tray_grid .tray-role-card');
return card !== null && card === card.parentElement.firstElementChild;
""")
self.assertTrue(is_first, "Newest role card should be first child")
# 3. The item now at position 8 (col 2, row 1) is a tray-cell —
# it was the 8th item in col 1 and has been displaced.
displaced = self.browser.execute_script("""
var grid = document.getElementById('id_tray_grid');
var el = grid.children[8];
return el ? el.className : null;
""")
self.assertIsNotNone(displaced)
self.assertIn("tray-cell", displaced)
# 4. Tray open enough to reveal at least col 1 (left < initial closed pos).
wrap = self.browser.find_element(By.ID, "id_tray_wrap")
left = self.browser.execute_script("return parseInt(arguments[0].style.left, 10)", wrap)
viewport_w = self.browser.execute_script("return window.innerWidth")
self.assertLess(left, viewport_w,
"Tray should be at least partially open after role selection")
# ------------------------------------------------------------------ #
# T3 — Landscape, position 3: row 1 full, rightmost item enters row 2 #
# ------------------------------------------------------------------ #
def test_landscape_third_card_at_bottom_left_rightmost_overflows_to_row_2(self):
"""Landscape, slot 3: row 1 (bottom, 8 cols) already holds 2 prior role
cards + 6 tray-cells. After slot 3 confirms, new card at position 0
(bottommost-leftmost); old position-7 item enters row 2, col 1 (pos 8)."""
@tag('two-browser')
def test_landscape_role_card_enters_leftmost_grid_square(self):
"""Landscape: after confirming a role, a .tray-role-card is the first child
of #id_tray_grid (leftmost cell) and the tray is open."""
self.browser.set_window_size(844, 390)
room = self._make_room(active_slot=3)
self.create_pre_authenticated_session("slot3@test.io")
room = self._make_room()
self.create_pre_authenticated_session("slot1@test.io")
self.browser.get(f"{self.live_server_url}/gameboard/room/{room.id}/gate/")
# Inject 2 prior role cards (oldest first → newest at grid front).
# Grid: [BC-card(0), PC-card(1), tray-0(2)..tray-7(9)] = 10 items.
# Row 1 (bottom): positions 0-7 = full. Row 2: positions 8-9.
self.wait_for(lambda: self.browser.find_element(By.ID, "id_tray_wrap"))
self._inject_prior_role_cards(["PC", "BC"])
grid_before = self.browser.execute_script(
"return document.getElementById('id_tray_grid').children.length"
)
self.assertEqual(grid_before, 10, "10 items before: 2 prior cards + 8 tray-cells")
wrap = self.browser.find_element(By.ID, "id_tray_wrap")
initial_top = self.browser.execute_script(
"return parseInt(arguments[0].style.top, 10)", wrap
)
self._select_role()
# 1. Wait for grid to grow (fetch .then() is async).
# Card appears in the grid.
self.wait_for(
lambda: self.assertEqual(
self.browser.execute_script(
"return document.getElementById('id_tray_grid').children.length"
),
grid_before + 1,
lambda: self.browser.find_element(
By.CSS_SELECTOR, "#id_tray_grid .tray-role-card"
)
)
grid_after = grid_before + 1
# 2. Newest tray-role-card is the first child — bottommost-leftmost in landscape.
# It is the first child — leftmost in landscape.
is_first = self.browser.execute_script("""
var card = document.querySelector('#id_tray_grid .tray-role-card');
return card !== null && card === card.parentElement.firstElementChild;
""")
self.assertTrue(is_first, "Newest role card should be first child")
self.assertTrue(is_first, "Role card should be the first child of #id_tray_grid")
# 3. Item at position 8 (row 2, col 1) is a tray-cell — it was the
# rightmost item in row 1 (position 7) and has been displaced upward.
displaced = self.browser.execute_script("""
var grid = document.getElementById('id_tray_grid');
var el = grid.children[8];
return el ? el.className : null;
""")
self.assertIsNotNone(displaced)
self.assertIn("tray-cell", displaced)
# 4. Tray opened downward — top is less negative (closer to 0) than before.
current_top = self.browser.execute_script(
"return parseInt(arguments[0].style.top, 10)", wrap
# Tray is open.
self.assertTrue(
self.browser.execute_script("return Tray.isOpen()"),
"Tray should be open after role selection"
)
self.assertGreater(current_top, initial_top,
"Tray should have moved down (toward open) after role selection")
@tag('channels')
@@ -877,11 +741,10 @@ class RoleSelectChannelsTest(ChannelsFunctionalTest):
return b
# ------------------------------------------------------------------ #
# Test 5 — Turn passes to next gamer via WebSocket after selection #
# Test 5 — Tray closes on turn advance (portrait) #
# ------------------------------------------------------------------ #
@unittest.skip("tray obscures card-stack after role selection — needs tray-close-on-turn-change + grid ordering fixes first")
def test_turn_passes_after_selection(self):
def _make_turn_test_room(self):
founder, _ = User.objects.get_or_create(email="founder@test.io")
User.objects.get_or_create(email="friend@test.io")
room = Room.objects.create(name="Turn Test", owner=founder)
@@ -895,47 +758,80 @@ class RoleSelectChannelsTest(ChannelsFunctionalTest):
TableSeat.objects.create(
room=room, gamer=slot.gamer, slot_number=slot.slot_number,
)
room_url = f"{self.live_server_url}/gameboard/room/{room.id}/gate/"
return f"{self.live_server_url}/gameboard/room/{room.id}/gate/"
# 1. Founder (slot 1) — eligible
def test_portrait_tray_closes_on_turn_advance(self):
"""Portrait: after selecting a role the tray opens and the role card lands
in the topmost grid square. When turn_changed arrives via WS, the tray
force-closes so the next player's card-stack is not obscured."""
self.browser.set_window_size(390, 844)
room_url = self._make_turn_test_room()
self.create_pre_authenticated_session("founder@test.io")
self.browser.get(room_url)
self.wait_for(lambda: self.browser.find_element(
By.CSS_SELECTOR, ".card-stack[data-state='eligible']"
))
# 2. Friend (slot 2) — ineligible in second browser
self.browser2 = self._make_browser2("friend@test.io")
try:
self.browser2.get(room_url)
self.wait_for(lambda: self.browser2.find_element(
By.CSS_SELECTOR, ".card-stack[data-state='ineligible']"
))
# Select a role — tray opens and card lands in topmost square.
self.browser.find_element(By.CSS_SELECTOR, ".card-stack").click()
self.wait_for(lambda: self.browser.find_element(By.ID, "id_role_select"))
self.browser.find_element(By.CSS_SELECTOR, "#id_role_select .card").click()
self.confirm_guard()
# 3. Founder picks a role
self.browser.find_element(By.CSS_SELECTOR, ".card-stack").click()
self.wait_for(lambda: self.browser.find_element(By.ID, "id_role_select"))
self.browser.find_element(By.CSS_SELECTOR, "#id_role_select .card").click()
self.confirm_guard()
self.wait_for(lambda: self.assertTrue(
self.browser.execute_script("return Tray.isOpen()")
))
is_first = self.browser.execute_script("""
var card = document.querySelector('#id_tray_grid .tray-role-card');
return card !== null && card === card.parentElement.firstElementChild;
""")
self.assertTrue(is_first, "Role card should be first child (topmost) of grid")
# 4. Friend's stack becomes eligible via WebSocket — no page refresh
self.wait_for(lambda: self.browser2.find_element(
By.CSS_SELECTOR, ".card-stack[data-state='eligible']"
))
# Turn advances via WS — seat 2 becomes active.
self.wait_for(lambda: self.browser.find_element(
By.CSS_SELECTOR, ".table-seat.active[data-slot='2']"
))
# 5. Founder's stack is STILL ineligible — WS must not re-enable it
self.wait_for(lambda: self.assertEqual(
self.browser.find_element(
By.CSS_SELECTOR, ".card-stack"
).get_attribute("data-state"),
"ineligible",
))
# Tray must be closed after turn_changed.
self.assertFalse(
self.browser.execute_script("return Tray.isOpen()"),
"Tray should be closed after turn advances"
)
def test_landscape_tray_closes_on_turn_advance(self):
"""Landscape: same sequence — role card at leftmost grid square; tray
closes when turn_changed arrives."""
self.browser.set_window_size(844, 390)
room_url = self._make_turn_test_room()
self.create_pre_authenticated_session("founder@test.io")
self.browser.get(room_url)
self.wait_for(lambda: self.browser.find_element(
By.CSS_SELECTOR, ".card-stack[data-state='eligible']"
))
self.browser.find_element(By.CSS_SELECTOR, ".card-stack").click()
self.wait_for(lambda: self.browser.find_element(By.ID, "id_role_select"))
self.browser.find_element(By.CSS_SELECTOR, "#id_role_select .card").click()
self.confirm_guard()
self.wait_for(lambda: self.assertTrue(
self.browser.execute_script("return Tray.isOpen()")
))
is_first = self.browser.execute_script("""
var card = document.querySelector('#id_tray_grid .tray-role-card');
return card !== null && card === card.parentElement.firstElementChild;
""")
self.assertTrue(is_first, "Role card should be first child (leftmost) of grid")
# Turn advances via WS — seat 2 becomes active.
self.wait_for(lambda: self.browser.find_element(
By.CSS_SELECTOR, ".table-seat.active[data-slot='2']"
))
# Tray must be closed after turn_changed.
self.assertFalse(
self.browser.execute_script("return Tray.isOpen()"),
"Tray should be closed after turn advances"
)
# 6. Clicking founder's stack does not reopen the fan
self.browser.find_element(By.CSS_SELECTOR, ".card-stack").click()
self.wait_for(lambda: self.assertEqual(
len(self.browser.find_elements(By.ID, "id_role_select")), 0
))
finally:
self.browser2.quit()