- Added `useRateLimit` hook - Integrated hook into `Contact.tsx` - Added translations for rate limit error - Added unit tests - Fixed type error in `Button.tsx` to allow build to pass
61 lines
2.1 KiB
Python
61 lines
2.1 KiB
Python
from playwright.sync_api import sync_playwright, expect
|
|
import time
|
|
|
|
def verify_rate_limit():
|
|
with sync_playwright() as p:
|
|
browser = p.chromium.launch(headless=True)
|
|
page = browser.new_page()
|
|
|
|
print("Navigating to home...")
|
|
page.goto("http://localhost:3000")
|
|
|
|
print("Navigating to Contact...")
|
|
# Try both English and German just in case
|
|
try:
|
|
page.get_by_role("link", name="Contact").click()
|
|
except:
|
|
page.get_by_role("link", name="Kontakt").click()
|
|
|
|
# Fill form
|
|
print("Filling form...")
|
|
# Use placeholders from en.ts
|
|
page.get_by_placeholder("Your name").fill("Test User")
|
|
page.get_by_placeholder("your@email.com").fill("test@example.com")
|
|
page.get_by_placeholder("What is it about?").fill("Test Subject")
|
|
page.get_by_placeholder("Your message...").fill("Test Message")
|
|
|
|
# Submit 1
|
|
print("Submitting first time...")
|
|
submit_btn = page.get_by_role("button", name="Send Message")
|
|
submit_btn.click()
|
|
|
|
# Wait for result (likely error due to missing keys/network)
|
|
# We expect either success or error message
|
|
print("Waiting for response...")
|
|
# Allow some time for EmailJS timeout
|
|
try:
|
|
expect(page.get_by_text("Error sending message").or_(page.get_by_text("Message sent successfully"))).to_be_visible(timeout=10000)
|
|
except:
|
|
print("Timed out waiting for first response, checking if button is enabled...")
|
|
|
|
# Ensure button is enabled before clicking again
|
|
# If it's disabled, we can't click
|
|
expect(submit_btn).not_to_be_disabled()
|
|
|
|
# Submit 2
|
|
print("Submitting second time...")
|
|
submit_btn.click()
|
|
|
|
# Check for rate limit message
|
|
print("Checking for rate limit message...")
|
|
expect(page.get_by_text("Too many requests")).to_be_visible()
|
|
|
|
# Screenshot
|
|
print("Taking screenshot...")
|
|
page.screenshot(path="verification.png")
|
|
|
|
browser.close()
|
|
|
|
if __name__ == "__main__":
|
|
verify_rate_limit()
|