This commit is contained in:
retoor 2025-11-11 01:06:10 +01:00
parent ba73b8bdf7
commit 1df5621c90
2 changed files with 129 additions and 0 deletions

2
.gitignore vendored
View File

@ -1,4 +1,6 @@
__pycache__/ __pycache__/
*.png
*.sqlite*
*.py[cod] *.py[cod]
*$py.class *$py.class
*.md *.md

View File

@ -0,0 +1,127 @@
import pytest
import asyncio
from playwright.async_api import expect, Page
@pytest.mark.asyncio
class TestBillingUserFlowRefactored:
async def test_navigate_to_billing_dashboard(self, page: Page):
await page.click('a.nav-link[data-view="billing"]')
await expect(page.locator('h1:has-text("Billing & Usage")')).to_be_visible(timeout=5000)
await expect(page.locator('billing-dashboard')).to_be_visible()
async def test_view_current_usage(self, page: Page):
await page.click('a.nav-link[data-view="billing"]')
await expect(page.locator('h1:has-text("Billing & Usage")')).to_be_visible(timeout=5000)
await expect(page.locator('.usage-card')).to_be_visible()
await expect(page.locator('text=Current Usage')).to_be_visible()
await expect(page.locator('.usage-label:has-text("Storage")')).to_be_visible()
await expect(page.locator('.usage-label:has-text("Bandwidth")')).to_be_visible()
async def test_view_estimated_cost(self, page: Page):
await page.click('a.nav-link[data-view="billing"]')
await expect(page.locator('h1:has-text("Billing & Usage")')).to_be_visible(timeout=5000)
await expect(page.locator('.cost-card')).to_be_visible()
await expect(page.locator('text=Estimated Monthly Cost')).to_be_visible()
await expect(page.locator('.estimated-cost')).to_be_visible()
cost_text = await page.locator('.estimated-cost').text_content()
assert '$' in cost_text
async def test_view_pricing_information(self, page: Page):
await page.click('a.nav-link[data-view="billing"]')
await expect(page.locator('h1:has-text("Billing & Usage")')).to_be_visible(timeout=5000)
await expect(page.locator('.pricing-card')).to_be_visible()
await expect(page.locator('text=Current Pricing')).to_be_visible()
await expect(page.locator('.pricing-item:has-text("Storage")')).to_be_visible()
await expect(page.locator('.pricing-item:has-text("Bandwidth")')).to_be_visible()
await expect(page.locator('.pricing-item:has-text("Free Tier")')).to_be_visible()
async def test_view_invoice_history_empty(self, page: Page):
await page.click('a.nav-link[data-view="billing"]')
await expect(page.locator('h1:has-text("Billing & Usage")')).to_be_visible(timeout=5000)
await expect(page.locator('.invoices-section')).to_be_visible()
await expect(page.locator('text=Recent Invoices')).to_be_visible()
no_invoices = page.locator('.no-invoices')
if await no_invoices.is_visible():
await expect(no_invoices).to_contain_text('No invoices yet')
async def test_upload_file_to_track_usage(self, page: Page):
# Navigate back to files view
await page.click('a.nav-link[data-view="files"]')
await expect(page.locator('h2:has-text("Files")')).to_be_visible(timeout=5000)
await page.set_input_files('input[type="file"]', {
'name': 'test-file.txt',
'mimeType': 'text/plain',
'buffer': b'This is a test file for billing usage tracking.'
})
await page.click('button:has-text("Upload")')
await expect(page.locator('text=test-file.txt')).to_be_visible(timeout=10000)
async def test_verify_usage_updated_after_upload(self, page: Page):
await page.click('a.nav-link[data-view="billing"]')
await expect(page.locator('h1:has-text("Billing & Usage")')).to_be_visible(timeout=5000)
storage_value_locator = page.locator('.usage-item:has(.usage-label:has-text("Storage")) .usage-value')
await expect(storage_value_locator).not_to_contain_text("0 B", timeout=10000)
async def test_add_payment_method_button(self, page: Page):
await page.click('a.nav-link[data-view="billing"]')
await expect(page.locator('h1:has-text("Billing & Usage")')).to_be_visible(timeout=5000)
await expect(page.locator('.payment-methods-section')).to_be_visible()
await expect(page.locator('text=Payment Methods')).to_be_visible()
await expect(page.locator('#addPaymentMethod')).to_be_visible()
async def test_click_add_payment_method(self, page: Page):
await page.click('a.nav-link[data-view="billing"]')
await expect(page.locator('h1:has-text("Billing & Usage")')).to_be_visible(timeout=5000)
page.on('dialog', lambda dialog: dialog.accept())
await page.click('#addPaymentMethod')
# We can't assert much here as it likely navigates to Stripe
await page.wait_for_timeout(1000) # Allow time for navigation
async def test_view_subscription_status(self, page: Page):
await page.click('a.nav-link[data-view="billing"]')
await expect(page.locator('h1:has-text("Billing & Usage")')).to_be_visible(timeout=5000)
await expect(page.locator('.subscription-badge')).to_be_visible()
badge_text = await page.locator('.subscription-badge').text_content()
assert badge_text in ['Pay As You Go', 'Free', 'Active']
async def test_verify_free_tier_display(self, page: Page):
await page.click('a.nav-link[data-view="billing"]')
await expect(page.locator('h1:has-text("Billing & Usage")')).to_be_visible(timeout=5000)
await expect(page.locator('.usage-info:has-text("GB included free")')).to_be_visible()
free_tier_info = await page.locator('.usage-info').text_content()
assert '15' in free_tier_info or 'GB' in free_tier_info
async def test_verify_progress_bar(self, page: Page):
await page.click('a.nav-link[data-view="billing"]')
await expect(page.locator('h1:has-text("Billing & Usage")')).to_be_visible(timeout=5000)
await expect(page.locator('.usage-progress')).to_be_visible()
await expect(page.locator('.usage-progress-bar')).to_be_visible()
async def test_verify_cost_breakdown(self, page: Page):
await page.click('a.nav-link[data-view="billing"]')
await expect(page.locator('h1:has-text("Billing & Usage")')).to_be_visible(timeout=5000)
await expect(page.locator('.cost-breakdown')).to_be_visible()
await expect(page.locator('.cost-item:has-text("Storage")')).to_be_visible()
await expect(page.locator('.cost-item:has-text("Bandwidth")')).to_be_visible()