", html)
self.assertNoEscapedTags(html)
def test_add_session_form_has_timestamp_helpers(self):
html = self.get("games:add_session").content.decode()
self.assertIn("add_session.js", html)
for marker in [
"Set to now",
"Toggle text",
"Copy start value to end",
"Copy end value to start",
'data-target="timestamp_start"',
'data-type="now"',
'hx-boost="false"',
]:
self.assertIn(marker, html)
self.assertNoEscapedTags(html)
# --- detail pages --------------------------------------------------------
def test_view_game(self):
html = self.get("games:view_game", self.game.id).content.decode()
for marker in [
'id="game-info"',
"font-bold font-serif",
self.game.name,
"Total hours played", # stat popover tooltip
'id="popover-hours"',
"Original year",
"Status",
"Played",
"Platform",
'id="history-container"',
"status-changed from:body",
"createPlayEvent", # the played-row Alpine dropdown script
'hx-target="#global-modal-container"', # delete trigger
"Purchases",
"Sessions",
"Play Events",
"History",
]:
self.assertIn(marker, html)
self.assertNoEscapedTags(html)
self.assertEqual(html.count(""))
def test_view_game_empty_sections(self):
"""A game with no sessions/purchases/etc shows the empty messages."""
lonely = Game.objects.create(name="Lonely Game", platform=self.platform)
html = self.get("games:view_game", lonely.id).content.decode()
for marker in [
"No purchases yet.",
"No sessions yet.",
"No play events yet.",
]:
self.assertIn(marker, html)
self.assertNoEscapedTags(html)
# --- HTMX fragments ------------------------------------------------------
def test_delete_game_confirmation_modal(self):
html = self.get("games:delete_game_confirmation", self.game.id).content.decode()
# A fragment (no full-page layout).
self.assertNotIn("", html)
self.assertIn('id="delete-game-confirmation-modal"', html)
self.assertIn("hx-post", html)
self.assertIn(self.game.name, html)
self.assertIn("session(s)", html) # seeded session
self.assertIn("purchase(s)", html) # seeded purchase
self.assertNoEscapedTags(html)
def test_refund_confirmation_modal(self):
html = self.get(
"games:refund_purchase_confirmation", self.purchase.id
).content.decode()
self.assertIn('id="refund-confirmation-modal"', html)
self.assertIn(f"#purchase-row-{self.purchase.id}", html)
self.assertIn("Refund", html)
self.assertNoEscapedTags(html)
def test_session_row_fragment_via_htmx(self):
# The inline "finish session" endpoint returns a
fragment.
resp = self.client.get(
reverse("games:list_sessions_end_session", args=[self.session.id]),
HTTP_HX_REQUEST="true",
)
html = resp.content.decode()
self.assertTrue(html.lstrip().startswith("
", # full Page() layout
"Please log in to continue",
"csrfmiddlewaretoken",
'type="submit"',
'value="Login"',
"