Files
ComfyUI_frontend/src/components/topbar/TopbarSubscribeButton.test.ts
Christian Byrne 513510104c fix: prevent subscription UI from rendering on non-cloud distributions (#9958)
## Summary

Prevent Plans & Pricing dialog, subscription buttons, and cloud-only
menu items from appearing on desktop/localhost distributions.

## Changes

- **What**: Add `isCloud` guards to
`useSubscriptionDialog.showPricingTable`, `TopbarSubscribeButton`, and
`CurrentUserPopoverLegacy` so subscription UI only renders on cloud
- **Tests**: 24 tests across 3 test files (1 modified, 2 new) covering
cloud/non-cloud behavior

## Review Focus

- Guard placement in `CurrentUserPopoverLegacy.vue` — multiple `v-if`
conditions updated to include `isCloud`
- Early-return in `showPricingTable` as a defense-in-depth measure

Fixes COM-16820

┆Issue is synchronized with this [Notion
page](https://www.notion.so/PR-9958-fix-prevent-subscription-UI-from-rendering-on-non-cloud-distributions-3246d73d365081559a9ee8650409c5b4)
by [Unito](https://www.unito.io)

Co-authored-by: Benjamin Lu <benjaminlu1107@gmail.com>
2026-03-16 02:21:40 -07:00

80 lines
1.7 KiB
TypeScript

import { mount } from '@vue/test-utils'
import { describe, expect, it, vi } from 'vitest'
import { createI18n } from 'vue-i18n'
import enMessages from '@/locales/en/main.json' with { type: 'json' }
import TopbarSubscribeButton from './TopbarSubscribeButton.vue'
const mockIsCloud = vi.hoisted(() => ({ value: true }))
vi.mock('@/platform/distribution/types', () => ({
get isCloud() {
return mockIsCloud.value
}
}))
const mockShowPricingTable = vi.fn()
vi.mock(
'@/platform/cloud/subscription/composables/useSubscriptionDialog',
() => ({
useSubscriptionDialog: vi.fn(() => ({
showPricingTable: mockShowPricingTable
}))
})
)
vi.mock('@/composables/billing/useBillingContext', () => ({
useBillingContext: vi.fn(() => ({
isFreeTier: { value: true }
}))
}))
vi.mock('pinia')
vi.mock('firebase/app', () => ({
initializeApp: vi.fn(),
getApp: vi.fn()
}))
vi.mock('firebase/auth', () => ({
getAuth: vi.fn(),
setPersistence: vi.fn(),
browserLocalPersistence: {},
onAuthStateChanged: vi.fn(),
signOut: vi.fn()
}))
function mountComponent() {
const i18n = createI18n({
legacy: false,
locale: 'en',
messages: { en: enMessages }
})
return mount(TopbarSubscribeButton, {
global: {
plugins: [i18n]
}
})
}
describe('TopbarSubscribeButton', () => {
it('renders on cloud when isFreeTier is true', () => {
mockIsCloud.value = true
const wrapper = mountComponent()
expect(
wrapper.find('[data-testid="topbar-subscribe-button"]').exists()
).toBe(true)
})
it('hides on non-cloud distribution', () => {
mockIsCloud.value = false
const wrapper = mountComponent()
expect(
wrapper.find('[data-testid="topbar-subscribe-button"]').exists()
).toBe(false)
})
})