LCOV - code coverage report
Current view: top level - src/platform/billing/composables - useBillingBannerCopy.ts Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 61.5 % 13 8
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : import type {
       2              :   BillingBannerCopy,
       3              :   BillingBannerView
       4              : } from '@comfyorg/account-ui/billing'
       5              : import { computed } from 'vue'
       6              : import { useI18n } from 'vue-i18n'
       7              : 
       8              : import { formatUsdFromCents } from '@/base/credits/comfyCredits'
       9              : import { pausedBannerCopy } from '@/platform/billing/composables/usePausedBanner'
      10              : 
      11            5 : const bs = 'workspacePanel.billingStatus'
      12            5 : const tc = 'workspacePanel.billingTab.topupCheckout'
      13            5 : const CONTACT_SUPPORT_URL = 'https://comfy.org/contact/'
      14              : 
      15              : /** The Billing tab banner strings in the app locale, with the paused and parked views. */
      16            5 : export function useBillingBannerCopy() {
      17            5 :   const { t, locale } = useI18n()
      18              : 
      19            0 :   function usd(cents: number) {
      20            0 :     return formatUsdFromCents({
      21              :       cents,
      22              :       locale: locale.value,
      23              :       numberOptions: {
      24              :         style: 'currency',
      25              :         currency: 'USD',
      26              :         minimumFractionDigits: cents % 100 === 0 ? 0 : 2
      27              :       }
      28              :     })
      29              :   }
      30              : 
      31            5 :   const copy = computed<BillingBannerCopy>(() => ({
      32              :     dismiss: t(`${bs}.planCheckout.dismiss`),
      33              :     actions: {
      34              :       addCredits: t('workspacePanel.billingTab.credits.addCredits'),
      35              :       updatePayment: t(`${bs}.updatePayment`),
      36              :       verifyPayment: t(`${bs}.planCheckout.verifyPayment.action`),
      37              :       contactSupport: t(`${bs}.parked.contactSupport`),
      38              :       resumePlan: t(`${bs}.ending.reactivate`),
      39              :       choosePlan: t('workspacePanel.billingTab.plan.actions.choosePlan'),
      40              :       contactSales: t(`${bs}.ending.contactSales`)
      41              :     },
      42              :     planCheckout: {
      43              :       verifyPayment: {
      44              :         title: t(`${bs}.planCheckout.verifyPayment.title`),
      45              :         body: t(`${bs}.planCheckout.verifyPayment.body`)
      46              :       },
      47              :       paymentReceived: {
      48              :         title: t(`${bs}.planCheckout.paymentReceived.title`),
      49              :         body: t(`${bs}.planCheckout.paymentReceived.body`)
      50              :       }
      51              :     },
      52              :     topupCheckout: {
      53              :       failedTitle: (cents) =>
      54              :         cents === null
      55              :           ? t(`${tc}.failed.titleNoAmount`)
      56              :           : t(`${tc}.failed.title`, { amount: usd(cents) }),
      57              :       failedBody: t(`${tc}.failed.body`),
      58              :       creditsApplying: {
      59              :         title: t(`${tc}.creditsApplying.title`),
      60              :         body: t(`${tc}.creditsApplying.body`)
      61              :       },
      62              :       processing: {
      63              :         title: t(`${tc}.processing.title`),
      64              :         body: t(`${tc}.processing.body`)
      65              :       }
      66              :     }
      67              :   }))
      68              : 
      69            5 :   const topupCopy = computed<BillingBannerCopy>(() => ({
      70              :     ...copy.value,
      71              :     dismiss: t(`${tc}.dismiss`)
      72              :   }))
      73              : 
      74            0 :   function pausedView(canManageBilling: boolean): BillingBannerView {
      75            0 :     const shown = pausedBannerCopy(canManageBilling)
      76            0 :     return {
      77              :       kind: 'paused',
      78              :       title: t(shown.titleKey),
      79              :       body: t(shown.bodyKey),
      80              :       muted: shown.muted,
      81              :       action: shown.action
      82              :     }
      83              :   }
      84              : 
      85              :   const parkedView = computed<BillingBannerView>(() => ({
      86              :     kind: 'parked',
      87              :     title: t(`${bs}.parked.title`),
      88              :     body: t(`${bs}.parked.body`),
      89              :     action: 'contactSupport',
      90              :     href: CONTACT_SUPPORT_URL
      91              :   }))
      92              : 
      93            5 :   return { copy, topupCopy, pausedView, parkedView }
      94              : }
        

Generated by: LCOV version 2.0-1