diff --git a/src/components/actionbar/ComfyRunButton/CloudRunButtonWrapper.test.ts b/src/components/actionbar/ComfyRunButton/CloudRunButtonWrapper.test.ts index c1c3cd4e500..30e373cb01b 100644 --- a/src/components/actionbar/ComfyRunButton/CloudRunButtonWrapper.test.ts +++ b/src/components/actionbar/ComfyRunButton/CloudRunButtonWrapper.test.ts @@ -3,12 +3,17 @@ import { render, screen, waitFor } from '@testing-library/vue' import { beforeEach, describe, expect, it, vi } from 'vitest' import { nextTick, ref } from 'vue' +import { createI18n } from 'vue-i18n' + +import TopbarSubscribeButton from '@/components/topbar/TopbarSubscribeButton.vue' +import enMessages from '@/locales/en/main.json' with { type: 'json' } import type { BillingStatus } from '@/platform/workspace/api/workspaceApi' import { useDialogStore } from '@/stores/dialogStore' import CloudRunButtonWrapper from './CloudRunButtonWrapper.vue' const mockCanRunWorkflows = ref(true) +const mockIsFreeTier = ref(true) const mockIsInitialized = ref(true) const mockBillingStatus = ref('paid') const mockSubscriptionTier = ref(null) @@ -33,6 +38,7 @@ vi.mock( () => mockIsInitialized.value && !mockCanRunWorkflows.value ), billingStatus: mockBillingStatus, + isFreeTier: mockIsFreeTier, subscription: computed(() => mockSubscriptionTier.value ? { tier: mockSubscriptionTier.value } @@ -46,6 +52,17 @@ vi.mock( } ) +vi.mock(import('@/platform/distribution/types'), () => ({ + isCloud: true +})) + +vi.mock( + import('@/platform/cloud/subscription/composables/useSubscriptionDialog'), + () => ({ + useSubscriptionDialog: () => ({ showPricingTable: vi.fn() }) + }) +) + vi.mock(import('@/composables/useFeatureFlags'), () => ({ useFeatureFlags: () => ({ flags: { @@ -93,12 +110,17 @@ vi.mock( vi.mock( import('@/platform/cloud/subscription/components/SubscribeToRun.vue'), - () => ({ - default: { - name: 'SubscribeToRun', - template: '
' + async () => { + const { registerSubscribeToRunPrompt } = + await import('@/platform/cloud/subscription/composables/useSubscribeCtaPresence') + return { + default: { + name: 'SubscribeToRun', + setup: () => registerSubscribeToRunPrompt(), + template: '
' + } } - }) + } ) function renderWrapper() { @@ -113,6 +135,59 @@ describe('CloudRunButtonWrapper', () => { mockSubscriptionTier.value = null state.v1PaymentRecovery = true state.canManageSubscription = true + mockIsFreeTier.value = true + }) + + describe('one subscribe CTA at a time', () => { + const CtaSurface = { + components: { CloudRunButtonWrapper, TopbarSubscribeButton }, + template: '
' + } + + function renderCtaSurface() { + const i18n = createI18n({ + legacy: false, + locale: 'en', + messages: { en: enMessages } + }) + return render(CtaSurface, { global: { plugins: [i18n] } }) + } + + it('keeps the topbar CTA on a sales-managed plan, where the prompt never mounts', () => { + mockCanRunWorkflows.value = false + mockSubscriptionTier.value = 'ENTERPRISE' + + renderCtaSurface() + + expect( + screen.queryByTestId('subscribe-to-run-button') + ).not.toBeInTheDocument() + expect(screen.getByTestId('topbar-subscribe-button')).toBeInTheDocument() + }) + + it('keeps the topbar CTA under payment recovery, where the prompt never mounts', () => { + mockCanRunWorkflows.value = false + mockBillingStatus.value = 'paused' + + renderCtaSurface() + + expect( + screen.queryByTestId('subscribe-to-run-button') + ).not.toBeInTheDocument() + expect(screen.getByTestId('topbar-subscribe-button')).toBeInTheDocument() + }) + + it('yields the topbar CTA only while the prompt is actually mounted', async () => { + mockCanRunWorkflows.value = false + + renderCtaSurface() + await nextTick() + + expect(screen.getByTestId('subscribe-to-run-button')).toBeInTheDocument() + expect( + screen.queryByTestId('topbar-subscribe-button') + ).not.toBeInTheDocument() + }) }) it('renders the runnable queue button when the subscription is active', () => { diff --git a/src/components/topbar/TopbarSubscribeButton.test.ts b/src/components/topbar/TopbarSubscribeButton.test.ts index ecf4ae8cdbe..e63583bf102 100644 --- a/src/components/topbar/TopbarSubscribeButton.test.ts +++ b/src/components/topbar/TopbarSubscribeButton.test.ts @@ -1,5 +1,6 @@ -import { describe, expect, it, vi } from 'vitest' +import { beforeEach, describe, expect, it, vi } from 'vitest' import { getActivePinia } from 'pinia' +import { nextTick } from 'vue' import { createI18n } from 'vue-i18n' import { render, screen } from '@testing-library/vue' @@ -27,12 +28,35 @@ vi.mock( }) ) -vi.mock(import('@/composables/billing/useBillingContext'), () => ({ - useBillingContext: vi.fn(() => ({ - isFreeTier: { value: true } - })) +const mockState = vi.hoisted(() => ({ + holder: null as null | { isFreeTier: boolean; promptMounted: boolean } })) +vi.mock( + import('@/composables/billing/useBillingContext'), + async () => { + const { computed, reactive } = await import('vue') + mockState.holder ??= reactive({ isFreeTier: true, promptMounted: false }) + return { + useBillingContext: vi.fn(() => ({ + isFreeTier: computed(() => mockState.holder!.isFreeTier) + })) + } + } +) + +vi.mock( + import('@/platform/cloud/subscription/composables/useSubscribeCtaPresence'), + async () => { + const { computed, reactive } = await import('vue') + mockState.holder ??= reactive({ isFreeTier: true, promptMounted: false }) + return { + useSubscribeToRunPromptPresence: () => + computed(() => mockState.holder!.promptMounted) + } + } +) + vi.mock(import('firebase/app'), () => ({ initializeApp: vi.fn(), getApp: vi.fn() @@ -61,12 +85,30 @@ function renderComponent() { } describe('TopbarSubscribeButton', () => { + beforeEach(() => { + mockState.holder!.isFreeTier = true + mockState.holder!.promptMounted = false + }) + it('renders on cloud when isFreeTier is true', () => { mockIsCloud.value = true renderComponent() expect(screen.getByTestId('topbar-subscribe-button')).toBeInTheDocument() }) + it('yields while a Run-slot subscribe prompt is mounted, and returns when it unmounts', async () => { + mockIsCloud.value = true + mockState.holder!.promptMounted = true + renderComponent() + expect( + screen.queryByTestId('topbar-subscribe-button') + ).not.toBeInTheDocument() + + mockState.holder!.promptMounted = false + await nextTick() + expect(screen.getByTestId('topbar-subscribe-button')).toBeInTheDocument() + }) + it('hides on non-cloud distribution', () => { mockIsCloud.value = false renderComponent() diff --git a/src/components/topbar/TopbarSubscribeButton.vue b/src/components/topbar/TopbarSubscribeButton.vue index 634d01fb4ab..8e435a208ce 100644 --- a/src/components/topbar/TopbarSubscribeButton.vue +++ b/src/components/topbar/TopbarSubscribeButton.vue @@ -1,6 +1,6 @@