From 8f95b9322a1cd7775991a1b2e5b04af7c4eb6d8e Mon Sep 17 00:00:00 2001 From: Glary-Bot Date: Mon, 20 Apr 2026 02:55:34 +0000 Subject: [PATCH 01/10] test: add FormattedNumberStepper coverage and TopUpCredits dialog E2E tests Add comprehensive Vitest component tests (24 cases) covering all 12 previously untested functions in FormattedNumberStepper.vue through behavioral user interactions. Add E2E integration smoke test for the TopUpCredits dialog with page object extending BaseDialog. --- .../fixtures/components/TopUpCreditsDialog.ts | 39 ++ .../tests/dialogs/topUpCreditsDialog.spec.ts | 96 +++++ .../ui/stepper/FormattedNumberStepper.test.ts | 334 ++++++++++++++++++ 3 files changed, 469 insertions(+) create mode 100644 src/components/ui/stepper/FormattedNumberStepper.test.ts diff --git a/browser_tests/fixtures/components/TopUpCreditsDialog.ts b/browser_tests/fixtures/components/TopUpCreditsDialog.ts index f7c0ccd5793..a7346546641 100644 --- a/browser_tests/fixtures/components/TopUpCreditsDialog.ts +++ b/browser_tests/fixtures/components/TopUpCreditsDialog.ts @@ -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 @@ -53,6 +65,29 @@ export class TopUpCreditsDialog extends BaseDialog { this.pricingLink = this.root.getByRole('link', { name: 'View pricing details' }) + + const steppers = this.root.locator('label') + const payStepper = steppers.first() + const creditsStepper = steppers.nth(1) + + 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.locator('button:has([class*="lucide--x"])') + this.minWarning = this.root.getByText(/minimum/i) + this.ceilingWarning = this.root.getByText(/maximum/i) } async open(options?: { isInsufficientCredits?: boolean }) { @@ -63,4 +98,8 @@ export class TopUpCreditsDialog extends BaseDialog { }, options) await this.waitForVisible() } + + getPresetButton(amount: number): Locator { + return this.root.getByRole('button', { name: `$${amount}`, exact: true }) + } } diff --git a/browser_tests/tests/dialogs/topUpCreditsDialog.spec.ts b/browser_tests/tests/dialogs/topUpCreditsDialog.spec.ts index 36efcde81d2..ccb3bf619ed 100644 --- a/browser_tests/tests/dialogs/topUpCreditsDialog.spec.ts +++ b/browser_tests/tests/dialogs/topUpCreditsDialog.spec.ts @@ -56,3 +56,99 @@ test.describe('TopUpCredits dialog', { tag: '@ui' }, () => { await expect(dialog.pricingLink).toHaveAttribute('target', '_blank') }) }) + +// 211 credits per USD (from src/base/credits/comfyCredits.ts) +// Step: $5 when pay < $100, $50 when pay < $1000, $100 otherwise +// MIN_AMOUNT = $5, MAX_AMOUNT = $10,000 + +test.describe('Top Up Credits Dialog', { 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' } + }) + } + ) + await comfyPage.page.route('**/customers/balance**', async (route) => { + await route.fulfill({ + json: { amount_micros: 1_000_000, currency: 'usd' } + }) + }) + + 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('5,275') + }) + + 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('6,330') + }) + + 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('9,495') + }) + + 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('105,500') + }) + + test('max ceiling warning appears when exceeding max', async () => { + await dialog.payInput.fill('') + await dialog.payInput.pressSequentially('99999') + + await expect(dialog.ceilingWarning).toBeVisible() + await expect(dialog.payInput).toHaveValue('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() + }) +}) diff --git a/src/components/ui/stepper/FormattedNumberStepper.test.ts b/src/components/ui/stepper/FormattedNumberStepper.test.ts new file mode 100644 index 00000000000..6d3db95ab9f --- /dev/null +++ b/src/components/ui/stepper/FormattedNumberStepper.test.ts @@ -0,0 +1,334 @@ +import { render, screen } from '@testing-library/vue' +import userEvent from '@testing-library/user-event' +import { nextTick } from 'vue' +import { createI18n } from 'vue-i18n' +import { describe, expect, it, vi } from 'vitest' + +import FormattedNumberStepper from '@/components/ui/stepper/FormattedNumberStepper.vue' + +const i18n = createI18n({ + legacy: false, + locale: 'en', + messages: { + en: { + g: { + decrement: 'Decrement', + increment: 'Increment' + } + } + } +}) + +async function flush() { + await nextTick() + await nextTick() +} + +function renderStepper( + props?: Partial<{ + modelValue: number + min: number + max: number + step: number | ((value: number) => number) + formatOptions: Intl.NumberFormatOptions + disabled: boolean + 'onUpdate:modelValue': (value: number) => void + onMaxReached: () => void + }> +) { + const user = userEvent.setup() + const result = render(FormattedNumberStepper, { + props: { modelValue: 0, ...props }, + global: { plugins: [i18n] } + }) + return { user, ...result } +} + +describe('FormattedNumberStepper', () => { + describe('rendering', () => { + it('renders increment and decrement buttons', () => { + renderStepper() + expect( + screen.getByRole('button', { name: 'Decrement' }) + ).toBeInTheDocument() + expect( + screen.getByRole('button', { name: 'Increment' }) + ).toBeInTheDocument() + }) + + it('renders formatted initial value', () => { + renderStepper({ modelValue: 1000 }) + expect(screen.getByRole('textbox')).toHaveValue('1,000') + }) + + it('renders prefix slot content', () => { + render(FormattedNumberStepper, { + props: { modelValue: 0 }, + slots: { prefix: '$' }, + global: { plugins: [i18n] } + }) + expect(screen.getByTestId('prefix')).toBeInTheDocument() + }) + + it('renders suffix slot content', () => { + render(FormattedNumberStepper, { + props: { modelValue: 0 }, + slots: { suffix: 'USD' }, + global: { plugins: [i18n] } + }) + expect(screen.getByTestId('suffix')).toBeInTheDocument() + }) + + it('applies disabled state to input and buttons', () => { + renderStepper({ disabled: true }) + expect(screen.getByRole('textbox')).toBeDisabled() + expect(screen.getByRole('button', { name: 'Decrement' })).toBeDisabled() + expect(screen.getByRole('button', { name: 'Increment' })).toBeDisabled() + }) + }) + + describe('handleStep', () => { + it('clicking + increments by step amount', async () => { + const onUpdate = vi.fn<(value: number) => void>() + const { user } = renderStepper({ + modelValue: 1, + step: 2, + 'onUpdate:modelValue': onUpdate + }) + + await user.click(screen.getByRole('button', { name: 'Increment' })) + + expect(onUpdate).toHaveBeenCalledWith(3) + expect(screen.getByRole('textbox')).toHaveValue('3') + }) + + it('clicking − decrements by step amount', async () => { + const onUpdate = vi.fn<(value: number) => void>() + const { user } = renderStepper({ + modelValue: 10, + min: 0, + step: 2, + 'onUpdate:modelValue': onUpdate + }) + + await user.click(screen.getByRole('button', { name: 'Decrement' })) + + expect(onUpdate).toHaveBeenCalledWith(8) + expect(screen.getByRole('textbox')).toHaveValue('8') + }) + + it('disables − button at min', () => { + renderStepper({ modelValue: 0, min: 0 }) + expect(screen.getByRole('button', { name: 'Decrement' })).toBeDisabled() + }) + + it('disables + button at max', () => { + renderStepper({ modelValue: 10, max: 10 }) + expect(screen.getByRole('button', { name: 'Increment' })).toBeDisabled() + }) + + it('clamps value to [min, max] range', async () => { + const onUpdate = vi.fn<(value: number) => void>() + const { user } = renderStepper({ + modelValue: 9, + min: 0, + max: 10, + step: 5, + 'onUpdate:modelValue': onUpdate + }) + + await user.click(screen.getByRole('button', { name: 'Increment' })) + + expect(onUpdate).toHaveBeenCalledWith(10) + expect(screen.getByRole('textbox')).toHaveValue('10') + }) + + it('calls function-based step prop with current value', async () => { + const onUpdate = vi.fn<(value: number) => void>() + const stepFn = vi.fn((value: number) => value + 1) + const { user } = renderStepper({ + modelValue: 4, + step: stepFn, + 'onUpdate:modelValue': onUpdate + }) + + await user.click(screen.getByRole('button', { name: 'Increment' })) + + expect(stepFn).toHaveBeenCalledWith(4) + expect(onUpdate).toHaveBeenCalledWith(9) + }) + }) + + describe('handleInputChange', () => { + it('typing digits updates modelValue', async () => { + const onUpdate = vi.fn<(value: number) => void>() + const { user } = renderStepper({ + modelValue: 0, + 'onUpdate:modelValue': onUpdate + }) + const input = screen.getByRole('textbox') + + await user.clear(input) + await user.type(input, '1234') + + expect(onUpdate).toHaveBeenLastCalledWith(1234) + }) + + it('strips non-numeric characters', async () => { + const onUpdate = vi.fn<(value: number) => void>() + const { user } = renderStepper({ + modelValue: 0, + 'onUpdate:modelValue': onUpdate + }) + const input = screen.getByRole('textbox') + + await user.clear(input) + await user.type(input, 'a1b2c3') + + expect(onUpdate).toHaveBeenLastCalledWith(123) + expect(input).toHaveValue('123') + }) + + it('formats input with grouping separators', async () => { + const { user } = renderStepper({ modelValue: 0 }) + const input = screen.getByRole('textbox') + + await user.clear(input) + await user.type(input, '1000') + + expect(input).toHaveValue('1,000') + }) + + it('emits max-reached when input exceeds max', async () => { + const onMaxReached = vi.fn() + const { user } = renderStepper({ + modelValue: 0, + max: 500, + onMaxReached + }) + const input = screen.getByRole('textbox') + + await user.clear(input) + await user.type(input, '999') + + expect(onMaxReached).toHaveBeenCalled() + }) + + it('clamps to max when input exceeds max', async () => { + const onUpdate = vi.fn<(value: number) => void>() + const { user } = renderStepper({ + modelValue: 0, + max: 500, + 'onUpdate:modelValue': onUpdate + }) + const input = screen.getByRole('textbox') + + await user.clear(input) + await user.type(input, '999') + + expect(onUpdate).toHaveBeenLastCalledWith(500) + expect(input).toHaveValue('500') + }) + + it('resolves empty input to 0', async () => { + const onUpdate = vi.fn<(value: number) => void>() + const { user } = renderStepper({ + modelValue: 123, + 'onUpdate:modelValue': onUpdate + }) + const input = screen.getByRole('textbox') + + await user.clear(input) + + expect(onUpdate).toHaveBeenLastCalledWith(0) + expect(input).toHaveValue('0') + }) + }) + + describe('handleInputBlur', () => { + it('clamps value below min to min on blur', async () => { + const onUpdate = vi.fn<(value: number) => void>() + const { user } = renderStepper({ + modelValue: 5, + min: 10, + 'onUpdate:modelValue': onUpdate + }) + const input = screen.getByRole('textbox') + + await user.click(input) + await user.tab() + + expect(onUpdate).toHaveBeenLastCalledWith(10) + expect(input).toHaveValue('10') + }) + + it('reformats display on blur', async () => { + const { user } = renderStepper({ modelValue: 1000 }) + const input = screen.getByRole('textbox') + + await user.click(input) + await user.tab() + + expect(input).toHaveValue('1,000') + }) + }) + + describe('handleInputFocus', () => { + it('moves cursor to end of input on focus', async () => { + const { user } = renderStepper({ modelValue: 1000 }) + const input = screen.getByRole('textbox') as HTMLInputElement + + input.setSelectionRange(0, 0) + await user.click(input) + await flush() + + expect(input.selectionStart).toBe(input.value.length) + expect(input.selectionEnd).toBe(input.value.length) + }) + }) + + describe('v-model reactivity', () => { + it('external modelValue change updates displayed text', async () => { + const { rerender } = renderStepper({ modelValue: 1000 }) + expect(screen.getByRole('textbox')).toHaveValue('1,000') + + await rerender({ modelValue: 2500 }) + await flush() + + expect(screen.getByRole('textbox')).toHaveValue('2,500') + }) + + it('external modelValue change does not overwrite while focused', async () => { + const { user, rerender } = renderStepper({ modelValue: 1000 }) + const input = screen.getByRole('textbox') + + await user.click(input) + await user.clear(input) + await user.type(input, '2') + await rerender({ modelValue: 9000 }) + await flush() + + expect(input).toHaveValue('2') + }) + }) + + describe('formatNumber', () => { + it('respects formatOptions prop', () => { + renderStepper({ + modelValue: 1000, + formatOptions: { + style: 'currency', + currency: 'USD', + maximumFractionDigits: 0 + } + }) + + expect(screen.getByRole('textbox')).toHaveValue('$1,000') + }) + + it('applies locale formatting with default options', () => { + renderStepper({ modelValue: 1234567 }) + expect(screen.getByRole('textbox')).toHaveValue('1,234,567') + }) + }) +}) From fb3829c7e0f39e40c4887d48190ef123eed8bf7e Mon Sep 17 00:00:00 2001 From: Glary-Bot Date: Mon, 20 Apr 2026 03:28:56 +0000 Subject: [PATCH 02/10] fix: type mock responses with satisfies and extract expectedCredits helper Address CodeRabbit review: type route.fulfill() payloads using CloudSubscriptionStatusResponse and GetCustomerBalanceResponse with satisfies, and replace hardcoded credit values with expectedCredits() helper using imported CREDITS_PER_USD constant. --- .../tests/dialogs/topUpCreditsDialog.spec.ts | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/browser_tests/tests/dialogs/topUpCreditsDialog.spec.ts b/browser_tests/tests/dialogs/topUpCreditsDialog.spec.ts index ccb3bf619ed..59bbf129cd7 100644 --- a/browser_tests/tests/dialogs/topUpCreditsDialog.spec.ts +++ b/browser_tests/tests/dialogs/topUpCreditsDialog.spec.ts @@ -1,8 +1,22 @@ +import type { operations } from '@comfyorg/registry-types' import { expect } from '@playwright/test' +import { CREDITS_PER_USD } from '@/base/credits/comfyCredits' +import type { CloudSubscriptionStatusResponse } from '@/platform/cloud/subscription/composables/useSubscription' + import { comfyPageFixture as test } from '@e2e/fixtures/ComfyPage' import { TopUpCreditsDialog } from '@e2e/fixtures/components/TopUpCreditsDialog' +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 @@ -57,10 +71,6 @@ test.describe('TopUpCredits dialog', { tag: '@ui' }, () => { }) }) -// 211 credits per USD (from src/base/credits/comfyCredits.ts) -// Step: $5 when pay < $100, $50 when pay < $1000, $100 otherwise -// MIN_AMOUNT = $5, MAX_AMOUNT = $10,000 - test.describe('Top Up Credits Dialog', { tag: '@ui' }, () => { let dialog: TopUpCreditsDialog @@ -69,13 +79,19 @@ test.describe('Top Up Credits Dialog', { tag: '@ui' }, () => { '**/cloud-subscription-status**', async (route) => { await route.fulfill({ - json: { is_active: true, subscription_tier: 'PRO' } + 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' } + json: { + amount_micros: 1_000_000, + currency: 'usd' + } satisfies GetCustomerBalanceResponse }) }) @@ -87,7 +103,7 @@ test.describe('Top Up Credits Dialog', { tag: '@ui' }, () => { await dialog.getPresetButton(25).click() await expect(dialog.payInput).toHaveValue('25') - await expect(dialog.creditsInput).toHaveValue('5,275') + await expect(dialog.creditsInput).toHaveValue(expectedCredits(25)) }) test('increment pay stepper updates credits', async () => { @@ -95,7 +111,7 @@ test.describe('Top Up Credits Dialog', { tag: '@ui' }, () => { await dialog.incrementPay.click() await expect(dialog.payInput).toHaveValue('30') - await expect(dialog.creditsInput).toHaveValue('6,330') + await expect(dialog.creditsInput).toHaveValue(expectedCredits(30)) }) test('decrement pay stepper updates credits', async () => { @@ -103,7 +119,7 @@ test.describe('Top Up Credits Dialog', { tag: '@ui' }, () => { await dialog.decrementPay.click() await expect(dialog.payInput).toHaveValue('45') - await expect(dialog.creditsInput).toHaveValue('9,495') + await expect(dialog.creditsInput).toHaveValue(expectedCredits(45)) }) test('typing in pay stepper updates credits', async () => { @@ -111,7 +127,7 @@ test.describe('Top Up Credits Dialog', { tag: '@ui' }, () => { await dialog.payInput.pressSequentially('500') await dialog.payInput.blur() - await expect(dialog.creditsInput).toHaveValue('105,500') + await expect(dialog.creditsInput).toHaveValue(expectedCredits(500)) }) test('max ceiling warning appears when exceeding max', async () => { From 44eb04dfa6ab78312427624c7ce433489b27bf89 Mon Sep 17 00:00:00 2001 From: Glary-Bot Date: Mon, 20 Apr 2026 03:36:17 +0000 Subject: [PATCH 03/10] =?UTF-8?q?test:=20add=20credits=E2=86=92pay=20rever?= =?UTF-8?q?se=20sync=20test=20and=20harden=20max-boundary=20assertion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add credits-driven sync test covering the creditsModel setter reverse path. Harden max-boundary test with blur + credits clamp assertion to catch pay/credits desync bugs. --- .../tests/dialogs/topUpCreditsDialog.spec.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/browser_tests/tests/dialogs/topUpCreditsDialog.spec.ts b/browser_tests/tests/dialogs/topUpCreditsDialog.spec.ts index 59bbf129cd7..9b1356ea9ae 100644 --- a/browser_tests/tests/dialogs/topUpCreditsDialog.spec.ts +++ b/browser_tests/tests/dialogs/topUpCreditsDialog.spec.ts @@ -130,12 +130,24 @@ test.describe('Top Up Credits Dialog', { tag: '@ui' }, () => { await expect(dialog.creditsInput).toHaveValue(expectedCredits(500)) }) + test('typing in credits stepper updates pay', async () => { + const credits = String(50 * CREDITS_PER_USD) + + 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 () => { From 898be7d78365e2db238a22baedcd065e457df36f Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Sun, 3 May 2026 21:52:11 -0700 Subject: [PATCH 04/10] =?UTF-8?q?test:=20extract=20expectedCreditsInput=20?= =?UTF-8?q?helper=20to=20dedup=20credits=E2=86=92pay=20conversion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- browser_tests/tests/dialogs/topUpCreditsDialog.spec.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/browser_tests/tests/dialogs/topUpCreditsDialog.spec.ts b/browser_tests/tests/dialogs/topUpCreditsDialog.spec.ts index 9b1356ea9ae..aa852c65c90 100644 --- a/browser_tests/tests/dialogs/topUpCreditsDialog.spec.ts +++ b/browser_tests/tests/dialogs/topUpCreditsDialog.spec.ts @@ -17,6 +17,10 @@ function expectedCredits(usd: number): string { return (usd * CREDITS_PER_USD).toLocaleString('en-US') } +function expectedCreditsInput(usd: number): string { + return expectedCredits(usd).replaceAll(',', '') +} + test.describe('TopUpCredits dialog', { tag: '@ui' }, () => { let dialog: TopUpCreditsDialog @@ -131,7 +135,7 @@ test.describe('Top Up Credits Dialog', { tag: '@ui' }, () => { }) test('typing in credits stepper updates pay', async () => { - const credits = String(50 * CREDITS_PER_USD) + const credits = expectedCreditsInput(50) await dialog.creditsInput.fill('') await dialog.creditsInput.pressSequentially(credits) From 109f2ff7dc4c7c987d408d277e519d0e3005365b Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Tue, 1 Sep 2026 09:30:42 +0000 Subject: [PATCH 05/10] test: select credit steppers by label Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/11458#discussion_r3222022682 --- browser_tests/fixtures/components/TopUpCreditsDialog.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/browser_tests/fixtures/components/TopUpCreditsDialog.ts b/browser_tests/fixtures/components/TopUpCreditsDialog.ts index a7346546641..0a73048a7bb 100644 --- a/browser_tests/fixtures/components/TopUpCreditsDialog.ts +++ b/browser_tests/fixtures/components/TopUpCreditsDialog.ts @@ -66,9 +66,10 @@ export class TopUpCreditsDialog extends BaseDialog { name: 'View pricing details' }) - const steppers = this.root.locator('label') - const payStepper = steppers.first() - const creditsStepper = steppers.nth(1) + 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"]') From 356ab8ae6027bba0b218dd14c8d1e5cd979efb51 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Tue, 1 Sep 2026 09:30:50 +0000 Subject: [PATCH 06/10] test: select top-up close button by accessible name Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/11458#discussion_r3222022686 --- browser_tests/fixtures/components/TopUpCreditsDialog.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/browser_tests/fixtures/components/TopUpCreditsDialog.ts b/browser_tests/fixtures/components/TopUpCreditsDialog.ts index 0a73048a7bb..25e7eac6be6 100644 --- a/browser_tests/fixtures/components/TopUpCreditsDialog.ts +++ b/browser_tests/fixtures/components/TopUpCreditsDialog.ts @@ -86,7 +86,7 @@ export class TopUpCreditsDialog extends BaseDialog { name: /continue to payment|add credits/i }) // Headless dialog uses its own X button, not PrimeVue's header close - this.closeButton = this.root.locator('button:has([class*="lucide--x"])') + this.closeButton = this.root.getByRole('button', { name: 'Close' }) this.minWarning = this.root.getByText(/minimum/i) this.ceilingWarning = this.root.getByText(/maximum/i) } From b316fc844c04846b20573f8378c1597f5dec351e Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Tue, 1 Sep 2026 09:30:59 +0000 Subject: [PATCH 07/10] test: distinguish billing-stub dialog suite Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/11458#discussion_r3222022691 --- browser_tests/tests/dialogs/topUpCreditsDialog.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/browser_tests/tests/dialogs/topUpCreditsDialog.spec.ts b/browser_tests/tests/dialogs/topUpCreditsDialog.spec.ts index aa852c65c90..4ab0f5a0468 100644 --- a/browser_tests/tests/dialogs/topUpCreditsDialog.spec.ts +++ b/browser_tests/tests/dialogs/topUpCreditsDialog.spec.ts @@ -75,7 +75,7 @@ test.describe('TopUpCredits dialog', { tag: '@ui' }, () => { }) }) -test.describe('Top Up Credits Dialog', { tag: '@ui' }, () => { +test.describe('TopUpCredits dialog - with billing stubs', { tag: '@ui' }, () => { let dialog: TopUpCreditsDialog test.beforeEach(async ({ comfyPage }) => { From 3045441b16971750f5220358caf83a13111066ae Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Tue, 1 Sep 2026 09:31:11 +0000 Subject: [PATCH 08/10] test: inline one-off credits input conversion Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/11458#discussion_r3222022696 --- browser_tests/tests/dialogs/topUpCreditsDialog.spec.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/browser_tests/tests/dialogs/topUpCreditsDialog.spec.ts b/browser_tests/tests/dialogs/topUpCreditsDialog.spec.ts index 4ab0f5a0468..bb14f421669 100644 --- a/browser_tests/tests/dialogs/topUpCreditsDialog.spec.ts +++ b/browser_tests/tests/dialogs/topUpCreditsDialog.spec.ts @@ -17,10 +17,6 @@ function expectedCredits(usd: number): string { return (usd * CREDITS_PER_USD).toLocaleString('en-US') } -function expectedCreditsInput(usd: number): string { - return expectedCredits(usd).replaceAll(',', '') -} - test.describe('TopUpCredits dialog', { tag: '@ui' }, () => { let dialog: TopUpCreditsDialog @@ -135,7 +131,7 @@ test.describe('TopUpCredits dialog - with billing stubs', { tag: '@ui' }, () => }) test('typing in credits stepper updates pay', async () => { - const credits = expectedCreditsInput(50) + const credits = expectedCredits(50).replaceAll(',', '') await dialog.creditsInput.fill('') await dialog.creditsInput.pressSequentially(credits) From 17b58d8036c05666631c510f7d706caa44be566e Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Tue, 1 Sep 2026 09:34:53 +0000 Subject: [PATCH 09/10] style: format accessible stepper selector Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/11458#discussion_r3222022682 --- browser_tests/fixtures/components/TopUpCreditsDialog.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/browser_tests/fixtures/components/TopUpCreditsDialog.ts b/browser_tests/fixtures/components/TopUpCreditsDialog.ts index 25e7eac6be6..44afd8c3bca 100644 --- a/browser_tests/fixtures/components/TopUpCreditsDialog.ts +++ b/browser_tests/fixtures/components/TopUpCreditsDialog.ts @@ -66,7 +66,9 @@ export class TopUpCreditsDialog extends BaseDialog { name: 'View pricing details' }) - const payStepper = this.root.getByText('You Pay', { exact: true }).locator('..') + const payStepper = this.root + .getByText('You Pay', { exact: true }) + .locator('..') const creditsStepper = this.root .getByText('You Get', { exact: true }) .locator('..') From f4ca3ee864afdfa2ed68a4bbcc60662e755c47f6 Mon Sep 17 00:00:00 2001 From: Pipeline Agent Date: Wed, 2 Sep 2026 09:54:44 +0000 Subject: [PATCH 10/10] fix: align top-up credits tests with current types --- .../tests/dialogs/topUpCreditsDialog.spec.ts | 177 +++++++++--------- 1 file changed, 92 insertions(+), 85 deletions(-) diff --git a/browser_tests/tests/dialogs/topUpCreditsDialog.spec.ts b/browser_tests/tests/dialogs/topUpCreditsDialog.spec.ts index bb14f421669..21fb5e3f9c9 100644 --- a/browser_tests/tests/dialogs/topUpCreditsDialog.spec.ts +++ b/browser_tests/tests/dialogs/topUpCreditsDialog.spec.ts @@ -2,11 +2,14 @@ import type { operations } from '@comfyorg/registry-types' import { expect } from '@playwright/test' import { CREDITS_PER_USD } from '@/base/credits/comfyCredits' -import type { CloudSubscriptionStatusResponse } from '@/platform/cloud/subscription/composables/useSubscription' 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'] @@ -71,112 +74,116 @@ test.describe('TopUpCredits dialog', { tag: '@ui' }, () => { }) }) -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) => { +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: { - is_active: true, - subscription_tier: 'PRO' - } satisfies CloudSubscriptionStatusResponse + amount_micros: 1_000_000, + currency: 'usd' + } satisfies GetCustomerBalanceResponse }) - } - ) - 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() - }) + dialog = new TopUpCreditsDialog(comfyPage.page) + await dialog.open() + }) - test('preset buttons update both steppers', async () => { - await dialog.getPresetButton(25).click() + 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)) - }) + 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() + 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)) - }) + 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() + 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)) - }) + 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() + 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)) - }) + await expect(dialog.creditsInput).toHaveValue(expectedCredits(500)) + }) - test('typing in credits stepper updates pay', async () => { - const credits = expectedCredits(50).replaceAll(',', '') + 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 dialog.creditsInput.fill('') + await dialog.creditsInput.pressSequentially(credits) + await dialog.creditsInput.blur() - await expect(dialog.payInput).toHaveValue('50') - }) + 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() + 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)) - }) + 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() + 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() - }) + 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() + 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() - }) + 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() + 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() - }) + await expect(dialog.buyButton).toBeDisabled() + }) - test('dialog closes via close button', async () => { - await dialog.closeButton.click() - await expect(dialog.root).toBeHidden() - }) -}) + test('dialog closes via close button', async () => { + await dialog.closeButton.click() + await expect(dialog.root).toBeHidden() + }) + } +)