Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,15 @@ describe('TopUpCreditsDialogContentLegacy', () => {
mockShouldUseWorkspaceBilling.value = false
})

it('shows the subscription settings panel after a successful purchase', async () => {
it('shows Plan & Credits after a successful Cloud purchase', async () => {
mockPurchaseCreditsDirect.mockResolvedValue(undefined)

renderDialog()
await clickBuyCredits()

expect(mockPurchaseCreditsDirect).toHaveBeenCalledWith(50)
expect(mockCloseDialog).toHaveBeenCalled()
expect(mockShowSettings).toHaveBeenCalledWith('subscription')
expect(mockShowSettings).toHaveBeenCalledWith('workspace')
})

it('shows the credits settings panel when subscriptions are disabled', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,9 @@ async function handleBuy() {
// Close top-up dialog (keep tracking) and open credits panel to show updated balance
handleClose(false)

// On the consolidated (workspace) billing flow, show the workspace settings
// panel; otherwise show the legacy subscription/credits panel.
const settingsPanel = shouldUseWorkspaceBilling.value
? 'workspace'
: isSubscriptionEnabled()
? 'subscription'
const settingsPanel =
shouldUseWorkspaceBilling.value || isSubscriptionEnabled()
? 'workspace'
: 'credits'
settingsDialog.show(settingsPanel)
} catch (error) {
Expand Down
157 changes: 4 additions & 153 deletions src/components/topbar/CurrentUserPopoverLegacy.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { render, screen } from '@testing-library/vue'
import userEvent from '@testing-library/user-event'
import { afterAll, beforeEach, describe, expect, it, vi } from 'vitest'
import { defineComponent, h, ref } from 'vue'
import { h, ref } from 'vue'
import { createI18n } from 'vue-i18n'

import { formatCreditsFromCents } from '@/base/credits/comfyCredits'
Expand Down Expand Up @@ -62,10 +62,8 @@ function makeSubscription(
}
}

const mockFetchStatus = vi.fn().mockResolvedValue(undefined)
const mockFetchBalance = vi.fn().mockResolvedValue(undefined)
const mockCanAccessSubscriptionFeatures = ref(true)
const mockIsFreeTier = ref(false)
const mockTier = ref<SubscriptionInfo['tier']>('CREATOR')
const mockSubscription = ref<SubscriptionInfo | null>(makeSubscription())
const mockBalance = ref<BalanceInfo | null>(null)
Expand All @@ -74,28 +72,14 @@ const mockIsLoading = ref(false)
vi.mock('@/composables/billing/useBillingContext', () => ({
useBillingContext: vi.fn(() => ({
canAccessSubscriptionFeatures: mockCanAccessSubscriptionFeatures,
isFreeTier: mockIsFreeTier,
tier: mockTier,
subscription: mockSubscription,
balance: mockBalance,
isLoading: mockIsLoading,
fetchStatus: mockFetchStatus,
fetchBalance: mockFetchBalance
}))
}))

const mockShowPricingTable = vi.fn()
vi.mock(
'@/platform/cloud/subscription/composables/useSubscriptionDialog',
() => ({
useSubscriptionDialog: vi.fn(() => ({
show: vi.fn(),
showPricingTable: mockShowPricingTable,
hide: vi.fn()
}))
})
)

vi.mock('@/components/common/UserAvatar.vue', () => ({
default: {
name: 'UserAvatarMock',
Expand Down Expand Up @@ -124,36 +108,9 @@ vi.mock('@/platform/telemetry', () => ({
}))
}))

const mockIsCloud = vi.hoisted(() => ({ value: true }))
vi.mock('@/platform/distribution/types', () => ({
get isCloud() {
return mockIsCloud.value
}
}))

vi.mock('@/platform/cloud/subscription/components/SubscribeButton.vue', () => ({
default: defineComponent({
name: 'SubscribeButtonMock',
emits: ['subscribed'],
setup(_, { emit }) {
return () =>
h(
'button',
{
'data-testid': 'subscribe-button-mock',
onClick: () => emit('subscribed')
},
'Subscribe Button'
)
}
})
}))

describe('CurrentUserPopoverLegacy', () => {
beforeEach(() => {
mockIsCloud.value = true
mockCanAccessSubscriptionFeatures.value = true
mockIsFreeTier.value = false
mockTier.value = 'CREATOR'
mockSubscription.value = makeSubscription()
mockBalance.value = {
Expand Down Expand Up @@ -201,15 +158,6 @@ describe('CurrentUserPopoverLegacy', () => {
expect(mockFetchBalance).toHaveBeenCalled()
})

it('refreshes subscription status through the billing facade after subscribing', async () => {
mockCanAccessSubscriptionFeatures.value = false
const { user } = renderComponent()

await user.click(screen.getByTestId('subscribe-button-mock'))

expect(mockFetchStatus).toHaveBeenCalled()
})

describe('subscription tier badge', () => {
it('renders the tier name derived from the facade tier', () => {
renderComponent()
Expand Down Expand Up @@ -326,26 +274,15 @@ describe('CurrentUserPopoverLegacy', () => {
expect(onClose).toHaveBeenCalledTimes(1)
})

it('opens subscription dialog and emits close event when plans & pricing item is clicked', async () => {
const { user, onClose } = renderComponent()

expect(screen.getByTestId('plans-pricing-menu-item')).toBeInTheDocument()

await user.click(screen.getByTestId('plans-pricing-menu-item'))

expect(mockShowPricingTable).toHaveBeenCalled()
expect(onClose).toHaveBeenCalledTimes(1)
})

it('offers plan management on cloud', async () => {
it('opens credits settings from the legacy account menu', async () => {
const { user, onClose } = renderComponent()

const menuItem = screen.getByTestId('manage-plan-menu-item')
expect(menuItem).toHaveTextContent(enMessages.subscription.managePlan)
expect(menuItem).toHaveTextContent(enMessages.credits.credits)

await user.click(menuItem)

expect(mockShowSettingsDialog).toHaveBeenCalledWith('subscription')
expect(mockShowSettingsDialog).toHaveBeenCalledWith('credits')
Comment thread
coderabbitai[bot] marked this conversation as resolved.
expect(onClose).toHaveBeenCalledTimes(1)
})

Expand Down Expand Up @@ -445,90 +382,4 @@ describe('CurrentUserPopoverLegacy', () => {
expect(screen.getByText('0')).toBeInTheDocument()
})
})

describe('cloud free tier', () => {
beforeEach(() => {
mockIsCloud.value = true
mockIsFreeTier.value = true
})

it('shows upgrade-to-add-credits button and hides add-credits button', () => {
renderComponent()
expect(
screen.getByTestId('upgrade-to-add-credits-button')
).toBeInTheDocument()
expect(screen.queryByTestId('add-credits-button')).not.toBeInTheDocument()
})
})

describe('non-cloud distribution', () => {
beforeEach(() => {
mockIsCloud.value = false
})

it('still shows credits balance', () => {
renderComponent()
expect(screen.getByText('1000')).toBeInTheDocument()
})

it('shows add-credits button and hides upgrade-to-add-credits button', () => {
renderComponent()
expect(screen.getByTestId('add-credits-button')).toBeInTheDocument()
expect(
screen.queryByTestId('upgrade-to-add-credits-button')
).not.toBeInTheDocument()
})

it('hides upgrade-to-add-credits button even when on free tier', () => {
mockIsFreeTier.value = true
renderComponent()
expect(screen.getByTestId('add-credits-button')).toBeInTheDocument()
expect(
screen.queryByTestId('upgrade-to-add-credits-button')
).not.toBeInTheDocument()
})

it('hides subscribe button', () => {
mockCanAccessSubscriptionFeatures.value = false
renderComponent()
expect(
screen.queryByTestId('subscribe-button-mock')
).not.toBeInTheDocument()
})

it('still shows partner nodes menu item', () => {
renderComponent()
expect(screen.getByTestId('partner-nodes-menu-item')).toBeInTheDocument()
})

it('hides plans & pricing menu item', () => {
renderComponent()
expect(
screen.queryByTestId('plans-pricing-menu-item')
).not.toBeInTheDocument()
})

it('offers credits and opens the credits panel', async () => {
const { user, onClose } = renderComponent()

const menuItem = screen.getByTestId('manage-plan-menu-item')
expect(menuItem).toHaveTextContent(enMessages.credits.credits)
expect(menuItem).not.toHaveTextContent(enMessages.subscription.managePlan)

await user.click(menuItem)

expect(mockShowSettingsDialog).toHaveBeenCalledWith('credits')
expect(onClose).toHaveBeenCalledTimes(1)
})

it('still shows user settings menu item', () => {
renderComponent()
expect(screen.getByTestId('user-settings-menu-item')).toBeInTheDocument()
})

it('still shows logout menu item', () => {
renderComponent()
expect(screen.getByTestId('logout-menu-item')).toBeInTheDocument()
})
})
})
Loading
Loading