Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions browser_tests/fixtures/components/TopUpCreditsDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ export class TopUpCreditsDialog extends BaseDialog {
readonly payAmountInput: Locator
readonly pricingLink: Locator

readonly payInput: Locator
readonly creditsInput: Locator
readonly decrementPay: Locator
readonly incrementPay: Locator
readonly decrementCredits: Locator
readonly incrementCredits: Locator
readonly presetButtons: Locator
readonly buyButton: Locator
override readonly closeButton: Locator
readonly minWarning: Locator
readonly ceilingWarning: Locator

constructor(page: Page) {
// Scope to the dialog containing a top-up flow heading rather than the
// generic `[role="dialog"]` fallback: this dialog can be opened from
Expand Down Expand Up @@ -53,6 +65,32 @@ export class TopUpCreditsDialog extends BaseDialog {
this.pricingLink = this.root.getByRole('link', {
name: 'View pricing details'
})

const payStepper = this.root
.getByText('You Pay', { exact: true })
.locator('..')
const creditsStepper = this.root
.getByText('You Get', { exact: true })
.locator('..')

this.payInput = payStepper.locator('input[inputmode="numeric"]')
this.creditsInput = creditsStepper.locator('input[inputmode="numeric"]')
this.decrementPay = payStepper.getByRole('button', { name: 'Decrement' })
this.incrementPay = payStepper.getByRole('button', { name: 'Increment' })
this.decrementCredits = creditsStepper.getByRole('button', {
name: 'Decrement'
})
this.incrementCredits = creditsStepper.getByRole('button', {
name: 'Increment'
})
this.presetButtons = this.root.getByRole('button', { name: /^\$\d+$/ })
this.buyButton = this.root.getByRole('button', {
name: /continue to payment|add credits/i
})
// Headless dialog uses its own X button, not PrimeVue's header close
this.closeButton = this.root.getByRole('button', { name: 'Close' })
this.minWarning = this.root.getByText(/minimum/i)
this.ceilingWarning = this.root.getByText(/maximum/i)
}

async open(options?: { isInsufficientCredits?: boolean }) {
Expand All @@ -63,4 +101,8 @@ export class TopUpCreditsDialog extends BaseDialog {
}, options)
await this.waitForVisible()
}

getPresetButton(amount: number): Locator {
return this.root.getByRole('button', { name: `$${amount}`, exact: true })
}
}
131 changes: 131 additions & 0 deletions browser_tests/tests/dialogs/topUpCreditsDialog.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
import type { operations } from '@comfyorg/registry-types'
import { expect } from '@playwright/test'

import { CREDITS_PER_USD } from '@/base/credits/comfyCredits'

import { comfyPageFixture as test } from '@e2e/fixtures/ComfyPage'
import { TopUpCreditsDialog } from '@e2e/fixtures/components/TopUpCreditsDialog'

type CloudSubscriptionStatusResponse = NonNullable<
operations['GetCloudSubscriptionStatus']['responses']['200']['content']['application/json']
>

type GetCustomerBalanceResponse =
operations['GetCustomerBalance']['responses']['200']['content']['application/json']

// Step: $5 when pay < $100, $50 when pay < $1000, $100 otherwise
// MIN_AMOUNT = $5, MAX_AMOUNT = $10,000

function expectedCredits(usd: number): string {
return (usd * CREDITS_PER_USD).toLocaleString('en-US')
}

test.describe('TopUpCredits dialog', { tag: '@ui' }, () => {
let dialog: TopUpCreditsDialog

Expand Down Expand Up @@ -56,3 +73,117 @@ test.describe('TopUpCredits dialog', { tag: '@ui' }, () => {
await expect(dialog.pricingLink).toHaveAttribute('target', '_blank')
})
})

test.describe(
'TopUpCredits dialog - with billing stubs',
{ tag: '@ui' },
() => {
let dialog: TopUpCreditsDialog

test.beforeEach(async ({ comfyPage }) => {
await comfyPage.page.route(
'**/cloud-subscription-status**',
async (route) => {
await route.fulfill({
json: {
is_active: true,
subscription_tier: 'PRO'
} satisfies CloudSubscriptionStatusResponse
})
}
)
await comfyPage.page.route('**/customers/balance**', async (route) => {
await route.fulfill({
json: {
amount_micros: 1_000_000,
currency: 'usd'
} satisfies GetCustomerBalanceResponse
})
})

dialog = new TopUpCreditsDialog(comfyPage.page)
await dialog.open()
})

test('preset buttons update both steppers', async () => {
await dialog.getPresetButton(25).click()

await expect(dialog.payInput).toHaveValue('25')
await expect(dialog.creditsInput).toHaveValue(expectedCredits(25))
})

test('increment pay stepper updates credits', async () => {
await dialog.getPresetButton(25).click()
await dialog.incrementPay.click()

await expect(dialog.payInput).toHaveValue('30')
await expect(dialog.creditsInput).toHaveValue(expectedCredits(30))
})

test('decrement pay stepper updates credits', async () => {
await dialog.getPresetButton(50).click()
await dialog.decrementPay.click()

await expect(dialog.payInput).toHaveValue('45')
await expect(dialog.creditsInput).toHaveValue(expectedCredits(45))
})

test('typing in pay stepper updates credits', async () => {
await dialog.payInput.fill('')
await dialog.payInput.pressSequentially('500')
await dialog.payInput.blur()

await expect(dialog.creditsInput).toHaveValue(expectedCredits(500))
})

test('typing in credits stepper updates pay', async () => {
const credits = expectedCredits(50).replaceAll(',', '')

await dialog.creditsInput.fill('')
await dialog.creditsInput.pressSequentially(credits)
await dialog.creditsInput.blur()

await expect(dialog.payInput).toHaveValue('50')
})

test('max ceiling warning appears when exceeding max', async () => {
await dialog.payInput.fill('')
await dialog.payInput.pressSequentially('99999')
await dialog.payInput.blur()

await expect(dialog.ceilingWarning).toBeVisible()
await expect(dialog.payInput).toHaveValue('10,000')
await expect(dialog.creditsInput).toHaveValue(expectedCredits(10_000))
})

test('min amount warning appears for values below minimum', async () => {
await dialog.payInput.fill('')
await dialog.payInput.pressSequentially('2')
await dialog.payInput.blur()

await expect(dialog.minWarning).toBeVisible()
})

test('buy button disabled for sub-minimum amount', async () => {
await dialog.payInput.fill('')
await dialog.payInput.pressSequentially('3')
await dialog.payInput.blur()

await expect(dialog.buyButton).toBeDisabled()
await expect(dialog.minWarning).toBeVisible()
})

test('buy button disabled when amount is zero', async () => {
await dialog.payInput.fill('')
await dialog.payInput.pressSequentially('0')
await dialog.payInput.blur()

await expect(dialog.buyButton).toBeDisabled()
})

test('dialog closes via close button', async () => {
await dialog.closeButton.click()
await expect(dialog.root).toBeHidden()
})
}
)
Loading
Loading