From b40bf9abc331aa0b2ce4a972ffcb1ccb07bbd2ff Mon Sep 17 00:00:00 2001 From: dante01yoon Date: Tue, 4 Aug 2026 16:32:30 +0000 Subject: [PATCH 1/6] feat: add flagged payment recovery UI Co-authored-by: Amp Amp-Thread-ID: https://ampcode.com/threads/T-019fcd78-f172-70fb-9190-7fb1960fa77b --- .../CloudRunButtonWrapper.test.ts | 111 +++++++++++++++++- .../ComfyRunButton/CloudRunButtonWrapper.vue | 56 ++++++++- .../ComfyRunButton/ComfyQueueButton.test.ts | 42 ++++++- .../ComfyRunButton/ComfyQueueButton.vue | 54 ++++++++- src/composables/useFeatureFlags.test.ts | 20 +++- src/composables/useFeatureFlags.ts | 9 ++ src/locales/en/main.json | 19 ++- .../remoteConfig/refreshRemoteConfig.ts | 2 + src/platform/remoteConfig/remoteConfig.ts | 5 + src/platform/remoteConfig/types.ts | 1 + .../SubscriptionPausedDialog.test.ts | 68 +++++++++++ .../components/SubscriptionPausedDialog.vue | 59 ++++++++++ .../settings/BillingStatusBanner.test.ts | 37 ++++-- .../composables/deriveBillingBanner.test.ts | 20 +++- .../composables/useBillingBanner.test.ts | 42 ++++++- .../workspace/composables/useBillingBanner.ts | 42 ++++--- src/storybook/mocks/useFeatureFlags.ts | 6 +- 17 files changed, 543 insertions(+), 50 deletions(-) create mode 100644 src/platform/workspace/components/SubscriptionPausedDialog.test.ts create mode 100644 src/platform/workspace/components/SubscriptionPausedDialog.vue diff --git a/src/components/actionbar/ComfyRunButton/CloudRunButtonWrapper.test.ts b/src/components/actionbar/ComfyRunButton/CloudRunButtonWrapper.test.ts index 65dce0c9c8a..07158fa9eab 100644 --- a/src/components/actionbar/ComfyRunButton/CloudRunButtonWrapper.test.ts +++ b/src/components/actionbar/ComfyRunButton/CloudRunButtonWrapper.test.ts @@ -1,3 +1,4 @@ +import userEvent from '@testing-library/user-event' import { render, screen } from '@testing-library/vue' import { beforeEach, describe, expect, it, vi } from 'vitest' import { nextTick, ref } from 'vue' @@ -5,17 +6,59 @@ import { nextTick, ref } from 'vue' import CloudRunButtonWrapper from './CloudRunButtonWrapper.vue' const mockCanRunWorkflows = ref(true) +const mockBillingStatus = ref('paid') +const state = vi.hoisted(() => ({ + v1PaymentRecovery: true, + canManageSubscription: true, + manageSubscription: vi.fn(), + showLayoutDialog: vi.fn(), + closeDialog: vi.fn() +})) vi.mock('@/composables/billing/useBillingContext', () => ({ useBillingContext: () => ({ - canRunWorkflows: mockCanRunWorkflows + canRunWorkflows: mockCanRunWorkflows, + billingStatus: mockBillingStatus, + manageSubscription: state.manageSubscription }) })) +vi.mock('@/composables/useFeatureFlags', () => ({ + useFeatureFlags: () => ({ + flags: { + get v1PaymentRecovery() { + return state.v1PaymentRecovery + } + } + }) +})) + +vi.mock('@/platform/workspace/composables/useWorkspaceUI', async () => { + const { computed } = await import('vue') + return { + useWorkspaceUI: () => ({ + permissions: computed(() => ({ + canManageSubscription: state.canManageSubscription + })) + }) + } +}) + +vi.mock('@/services/dialogService', () => ({ + useDialogService: () => ({ showLayoutDialog: state.showLayoutDialog }) +})) + +vi.mock('@/stores/dialogStore', () => ({ + useDialogStore: () => ({ closeDialog: state.closeDialog }) +})) + vi.mock('@/components/actionbar/ComfyRunButton/ComfyQueueButton.vue', () => ({ default: { name: 'ComfyQueueButton', - template: '
' + props: ['paymentRecoveryLock'], + emits: ['paymentRecoveryClick'], + template: + '
' } })) @@ -33,6 +76,10 @@ function renderWrapper() { describe('CloudRunButtonWrapper', () => { beforeEach(() => { mockCanRunWorkflows.value = true + mockBillingStatus.value = 'paid' + state.v1PaymentRecovery = true + state.canManageSubscription = true + vi.clearAllMocks() }) it('renders the runnable queue button when the subscription is active', () => { @@ -66,4 +113,64 @@ describe('CloudRunButtonWrapper', () => { screen.queryByTestId('subscribe-to-run-button') ).not.toBeInTheDocument() }) + + it('preserves queue controls and opens the owner recovery flow when paused', async () => { + mockCanRunWorkflows.value = false + mockBillingStatus.value = 'paused' + renderWrapper() + + expect(screen.getByTestId('batch-count')).toBeInTheDocument() + expect(screen.getByTestId('queue-dropdown')).toBeInTheDocument() + expect(screen.getByTestId('queue-button')).toHaveTextContent('owner') + expect( + screen.queryByTestId('subscribe-to-run-button') + ).not.toBeInTheDocument() + + await userEvent.click(screen.getByTestId('queue-button')) + const dialogOptions = state.showLayoutDialog.mock.calls[0][0] + expect(dialogOptions.props.canManage).toBe(true) + + dialogOptions.props.onUpdatePayment() + expect(state.closeDialog).toHaveBeenCalledWith({ + key: 'subscription-paused' + }) + expect(state.manageSubscription).toHaveBeenCalledOnce() + }) + + it('opens member-safe recovery copy without a payment action', async () => { + mockCanRunWorkflows.value = false + mockBillingStatus.value = 'paused' + state.canManageSubscription = false + renderWrapper() + + expect(screen.getByTestId('queue-button')).toHaveTextContent('member') + await userEvent.click(screen.getByTestId('queue-button')) + + const dialogOptions = state.showLayoutDialog.mock.calls[0][0] + expect(dialogOptions.props.canManage).toBe(false) + dialogOptions.props.onClose() + expect(state.closeDialog).toHaveBeenCalledWith({ + key: 'subscription-paused' + }) + expect(state.manageSubscription).not.toHaveBeenCalled() + }) + + it('keeps generic inactive behavior when payment recovery is disabled', () => { + mockCanRunWorkflows.value = false + mockBillingStatus.value = 'paused' + state.v1PaymentRecovery = false + renderWrapper() + + expect(screen.getByTestId('subscribe-to-run-button')).toBeInTheDocument() + expect(screen.queryByTestId('queue-group')).not.toBeInTheDocument() + }) + + it('keeps generic inactive behavior for non-paused statuses', () => { + mockCanRunWorkflows.value = false + mockBillingStatus.value = 'inactive' + renderWrapper() + + expect(screen.getByTestId('subscribe-to-run-button')).toBeInTheDocument() + expect(screen.queryByTestId('queue-group')).not.toBeInTheDocument() + }) }) diff --git a/src/components/actionbar/ComfyRunButton/CloudRunButtonWrapper.vue b/src/components/actionbar/ComfyRunButton/CloudRunButtonWrapper.vue index e5e8922a94a..fc4213c52d3 100644 --- a/src/components/actionbar/ComfyRunButton/CloudRunButtonWrapper.vue +++ b/src/components/actionbar/ComfyRunButton/CloudRunButtonWrapper.vue @@ -1,19 +1,63 @@ diff --git a/src/components/actionbar/ComfyRunButton/ComfyQueueButton.test.ts b/src/components/actionbar/ComfyRunButton/ComfyQueueButton.test.ts index e4d940a850b..0aa8155658e 100644 --- a/src/components/actionbar/ComfyRunButton/ComfyQueueButton.test.ts +++ b/src/components/actionbar/ComfyRunButton/ComfyQueueButton.test.ts @@ -56,6 +56,15 @@ const i18n = createI18n({ runWorkflow: 'Run workflow', runWorkflowFront: 'Run workflow front', runWorkflowMissingResources: 'Workflow contains missing resources' + }, + subscription: { + paymentRecovery: { + ownerRunLabel: 'Update payment to run', + memberRunLabel: 'Run', + ownerRunTooltip: 'Update payment to restore this subscription', + memberRunTooltip: + 'Ask your workspace owner to restore this subscription' + } } } } @@ -136,7 +145,9 @@ const stubs = { DropdownMenuItem: { template: '
' } } -function renderQueueButton() { +function renderQueueButton( + props: { paymentRecoveryLock?: 'owner' | 'member' } = {} +) { const pinia = createTestingPinia({ createSpy: vi.fn, stubActions: (actionName) => actionName !== 'recordPromptError' @@ -144,6 +155,7 @@ function renderQueueButton() { const user = userEvent.setup() const result = render(ComfyQueueButton, { + props, global: { plugins: [pinia, i18n], directives: { @@ -165,6 +177,34 @@ describe('ComfyQueueButton', () => { expect(controls[1]).toHaveAttribute('data-testid', 'queue-button') }) + it.for([ + { + paymentRecoveryLock: 'owner', + label: 'Update payment to run', + variant: 'subscribe' + }, + { paymentRecoveryLock: 'member', label: 'Run', variant: 'secondary' } + ] as const)( + 'keeps the queue group mounted for a paused $paymentRecoveryLock and blocks execution', + async ({ paymentRecoveryLock, label, variant }) => { + useQueueSettingsStore().mode = 'change' + const { user, emitted } = renderQueueButton({ paymentRecoveryLock }) + const commandStore = useCommandStore() + + expect(screen.getByTestId('batch-count-edit')).toBeInTheDocument() + expect(screen.getByTestId('queue-mode-menu-trigger')).toBeDisabled() + expect(useQueueSettingsStore().mode).toBe('disabled') + const button = screen.getByTestId('queue-button') + expect(button).toHaveTextContent(label) + expect(button).toHaveAttribute('data-variant', variant) + + await user.click(button) + + expect(commandStore.execute).not.toHaveBeenCalled() + expect(emitted()).toHaveProperty('paymentRecoveryClick') + } + ) + it.for(missingResourceCases)( 'clears the warning icon when missing $label are resolved', async ({ setMissing, clearMissing }) => { diff --git a/src/components/actionbar/ComfyRunButton/ComfyQueueButton.vue b/src/components/actionbar/ComfyRunButton/ComfyQueueButton.vue index 2b156f70fe0..017c272d02c 100644 --- a/src/components/actionbar/ComfyRunButton/ComfyQueueButton.vue +++ b/src/components/actionbar/ComfyRunButton/ComfyQueueButton.vue @@ -24,6 +24,7 @@
' + '
' } })) @@ -126,12 +130,16 @@ describe('CloudRunButtonWrapper', () => { expect(screen.getByTestId('batch-count')).toBeInTheDocument() expect(screen.getByTestId('queue-dropdown')).toBeInTheDocument() - expect(screen.getByTestId('queue-button')).toHaveTextContent('owner') + expect(screen.getByTestId('queue-button')).toHaveTextContent( + 'Update payment to run' + ) expect( screen.queryByTestId('subscribe-to-run-button') ).not.toBeInTheDocument() - await userEvent.click(screen.getByTestId('queue-button')) + await userEvent.click( + screen.getByRole('button', { name: 'Update payment to run' }) + ) const dialogOptions = state.showLayoutDialog.mock.calls[0][0] expect(dialogOptions.props.canManage).toBe(true) @@ -157,13 +165,51 @@ describe('CloudRunButtonWrapper', () => { expect(state.closeDialog).not.toHaveBeenCalled() }) + it('reuses a pending portal request across rapid clicks and reopen', async () => { + let resolvePortal!: () => void + state.manageSubscription.mockImplementationOnce( + () => + new Promise((resolve) => { + resolvePortal = resolve + }) + ) + mockCanRunWorkflows.value = false + mockBillingStatus.value = 'paused' + renderWrapper() + + await userEvent.click( + screen.getByRole('button', { name: 'Update payment to run' }) + ) + const firstDialog = state.showLayoutDialog.mock.calls[0][0] + const firstRequest = firstDialog.props.onUpdatePayment() + const repeatedRequest = firstDialog.props.onUpdatePayment() + expect(state.manageSubscription).toHaveBeenCalledOnce() + + firstDialog.props.onClose() + await userEvent.click( + screen.getByRole('button', { name: 'Update payment to run' }) + ) + const reopenedDialog = state.showLayoutDialog.mock.calls.at(-1)?.[0] + expect(reopenedDialog.props.isUpdatingPayment).toBe(true) + expect(reopenedDialog.props.onUpdatePayment()).toBe(firstRequest) + expect(repeatedRequest).toBe(firstRequest) + expect(state.manageSubscription).toHaveBeenCalledOnce() + + resolvePortal() + await firstRequest + expect(state.updateDialog).toHaveBeenLastCalledWith({ + key: 'subscription-paused', + contentProps: { isUpdatingPayment: false } + }) + }) + it('opens member-safe recovery copy without a payment action', async () => { mockCanRunWorkflows.value = false mockBillingStatus.value = 'paused' state.canManageSubscription = false renderWrapper() - expect(screen.getByTestId('queue-button')).toHaveTextContent('member') + expect(screen.getByTestId('queue-button')).toHaveTextContent('Run') await userEvent.click(screen.getByTestId('queue-button')) const dialogOptions = state.showLayoutDialog.mock.calls[0][0] diff --git a/src/components/actionbar/ComfyRunButton/CloudRunButtonWrapper.vue b/src/components/actionbar/ComfyRunButton/CloudRunButtonWrapper.vue index 1a6833403d7..f6b9de1f947 100644 --- a/src/components/actionbar/ComfyRunButton/CloudRunButtonWrapper.vue +++ b/src/components/actionbar/ComfyRunButton/CloudRunButtonWrapper.vue @@ -7,7 +7,7 @@