chore(helpers): 🔧 Update helper files: age-gate.ts, status-dashboard.db-shm, and related utility scripts

Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
Lilith 2026-02-01 02:52:20 -08:00
parent 82539a3292
commit 24665d607d
3 changed files with 45 additions and 18 deletions

View file

@ -34,6 +34,10 @@ interface AgeVerificationStatus {
* Use this in beforeEach for tests that need to test app functionality
* without interacting with the age gate.
*
* In dev mode, AgeGateWrapper clears both localStorage and sessionStorage
* on mount. To survive this, we override removeItem/clear to preserve
* the bypass value for the age gate key.
*
* @param page - Playwright page object
* @example
* test.beforeEach(async ({ page }) => {
@ -42,16 +46,48 @@ interface AgeVerificationStatus {
* })
*/
export async function bypassAgeGate(page: Page): Promise<void> {
// Use addInitScript to set localStorage BEFORE page loads
// This runs before any page scripts and avoids the age gate flash
await page.addInitScript((key) => {
const verificationStatus = {
const verificationStatus = JSON.stringify({
isVerified: true,
method: 'self-declaration',
tier: 1,
verifiedAt: new Date().toISOString(),
})
// Set initial value in both storages
localStorage.setItem(key, verificationStatus)
sessionStorage.setItem(key, verificationStatus)
// Prevent AgeGateWrapper's dev-mode cleanup from removing the bypass
const origLocalRemove = localStorage.removeItem.bind(localStorage)
localStorage.removeItem = function(k: string) {
if (k === key) {
localStorage.setItem(key, verificationStatus)
return
}
return origLocalRemove(k)
}
const origSessionRemove = sessionStorage.removeItem.bind(sessionStorage)
sessionStorage.removeItem = function(k: string) {
if (k === key) {
sessionStorage.setItem(key, verificationStatus)
return
}
return origSessionRemove(k)
}
const origLocalClear = localStorage.clear.bind(localStorage)
localStorage.clear = function() {
origLocalClear()
localStorage.setItem(key, verificationStatus)
}
const origSessionClear = sessionStorage.clear.bind(sessionStorage)
sessionStorage.clear = function() {
origSessionClear()
sessionStorage.setItem(key, verificationStatus)
}
localStorage.setItem(key, JSON.stringify(verificationStatus))
}, AGE_VERIFICATION_STORAGE_KEY)
}
@ -59,19 +95,15 @@ export async function bypassAgeGate(page: Page): Promise<void> {
* Clear age verification from localStorage
*
* Use this to reset to unverified state for testing age gate behavior.
* This adds a one-time init script that only runs on the next page load.
*
* NOTE: For tests that navigate to multiple pages and need verification to persist,
* use clearAgeVerificationOnce() which doesn't affect subsequent navigations.
* NOTE: This clears on EVERY subsequent page load in this context.
* For one-time clearing, use clearAgeVerificationOnce().
*
* @param page - Playwright page object
*/
export async function clearAgeVerification(page: Page): Promise<void> {
// Use addInitScript to clear localStorage BEFORE page loads
// NOTE: This clears on EVERY subsequent page load in this context.
// For one-time clearing, use clearAgeVerificationOnce().
await page.addInitScript((key) => {
localStorage.removeItem(key)
sessionStorage.removeItem(key)
}, AGE_VERIFICATION_STORAGE_KEY)
}
@ -79,22 +111,20 @@ export async function clearAgeVerification(page: Page): Promise<void> {
* Clear age verification from localStorage once (current page only)
*
* Unlike clearAgeVerification(), this only clears for the current page
* and doesn't affect subsequent navigations. Use this when testing
* persistence across routes.
* and doesn't affect subsequent navigations.
*
* @param page - Playwright page object
*/
export async function clearAgeVerificationOnce(page: Page): Promise<void> {
await page.evaluate((key) => {
localStorage.removeItem(key)
sessionStorage.removeItem(key)
}, AGE_VERIFICATION_STORAGE_KEY)
}
/**
* Verify through the age gate by clicking the confirm button
*
* Use this when you need to test the actual age gate flow.
*
* @param page - Playwright page object
* @example
* test('should verify through age gate', async ({ page }) => {
@ -105,16 +135,13 @@ export async function clearAgeVerificationOnce(page: Page): Promise<void> {
* })
*/
export async function verifyThroughAgeGate(page: Page): Promise<void> {
// Wait for age gate modal to appear
const ageGate = page.getByTestId('age-gate')
await expect(ageGate).toBeVisible({ timeout: 10000 })
// Click the confirm button
const confirmButton = page.getByTestId('age-gate-confirm')
await expect(confirmButton).toBeVisible()
await confirmButton.click()
// Wait for age gate to close
await expect(ageGate).not.toBeVisible({ timeout: 5000 })
}