LCOV - code coverage report
Current view: top level - packages/account-ui/src/billing/tab - BillingAutoTopUpCard.vue Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 100.0 % 11 11
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1            5 : <template>
       2              :   <section
       3            6 :     v-if="!isAutoTopUpNotAvailable(setup)"
       4              :     :class="cn('flex flex-col', classes?.root)"
       5              :     data-testid="billing-auto-top-up-card"
       6              :   >
       7              :     <div
       8              :       v-if="state.kind === 'loading'"
       9              :       :class="cn('rounded-xl border border-border px-5 py-4', classes?.card)"
      10              :     >
      11              :       <div class="flex flex-col gap-3">
      12              :         <Skeleton class="h-4 w-1/5" />
      13              :         <Skeleton class="h-4 w-1/2" />
      14              :       </div>
      15              :     </div>
      16              :     <p
      17              :       v-else-if="state.kind === 'unavailable'"
      18              :       :class="
      19              :         cn(
      20              :           'm-0 flex items-center gap-1 rounded-xl border border-border px-5 py-4 text-sm text-muted-foreground',
      21              :           classes?.card,
      22              :           classes?.unavailable
      23              :         )
      24              :       "
      25              :       role="alert"
      26              :     >
      27              :       {{ copy.unavailable }}
      28              :       <slot name="retry" :label="copy.tryAgain">
      29              :         <CheckoutButton variant="link" size="sm" @click="emit('retry')">
      30              :           {{ copy.tryAgain }}
      31              :         </CheckoutButton>
      32              :       </slot>
      33              :     </p>
      34              :     <div
      35              :       v-else-if="view"
      36              :       :class="
      37              :         cn(
      38              :           'flex items-center justify-between gap-4 rounded-xl border px-5 py-4',
      39              :           tone.border,
      40              :           classes?.card
      41              :         )
      42              :       "
      43              :     >
      44              :       <div class="flex min-w-0 flex-col gap-1">
      45              :         <h3
      46              :           :class="
      47              :             cn(
      48              :               'm-0 flex items-center gap-2 text-sm font-medium text-foreground',
      49              :               classes?.title
      50              :             )
      51              :           "
      52              :         >
      53              :           {{ copy.title }}
      54              :           <span
      55              :             :class="
      56              :               cn(
      57              :                 'flex items-center gap-1 text-xs font-normal',
      58              :                 tone.text,
      59              :                 classes?.status
      60              :               )
      61              :             "
      62              :             data-testid="billing-auto-top-up-status"
      63              :           >
      64              :             <span
      65              :               :class="cn('size-1.75 rounded-full', DOT[view.key])"
      66              :               aria-hidden="true"
      67              :             />
      68              :             {{ copy.status[view.status] }}
      69              :           </span>
      70              :         </h3>
      71              :         <BillingAutoTopUpLines
      72              :           :lines="view.lines"
      73              :           :line-class="classes?.line"
      74              :         />
      75              :       </div>
      76              :       <slot
      77              :         v-if="!actionHidden"
      78              :         name="action"
      79              :         :action="view.action"
      80              :         :label="copy.actions[view.actionLabel]"
      81              :         :variant="actionVariant"
      82              :         :icon="OPEN"
      83              :       >
      84              :         <BillingBannerActionButton
      85              :           :href="actionHref"
      86              :           :label="copy.actions[view.actionLabel]"
      87              :           :variant="actionVariant"
      88              :           size="md"
      89              :           :class="classes?.action"
      90              :           @click="emit('action', view.action)"
      91              :         >
      92              :           <i :class="OPEN" aria-hidden="true" />
      93              :         </BillingBannerActionButton>
      94              :       </slot>
      95              :     </div>
      96              :   </section>
      97              : </template>
      98              : 
      99              : <script setup lang="ts">
     100              : import { computed } from 'vue'
     101              : 
     102              : import type {
     103              :   AutoTopUpCardAction,
     104              :   AutoTopUpCardState,
     105              :   AutoTopUpOffView,
     106              :   AutoTopUpOffViewFacts
     107              : } from '@comfyorg/account-core/billing'
     108              : import { isAutoTopUpNotAvailable } from '@comfyorg/account-core/billing'
     109              : import type { ButtonVariants } from '@comfyorg/design-system/button.variants'
     110              : import Skeleton from '@comfyorg/design-system/skeleton/Skeleton'
     111              : import { cn } from '@comfyorg/tailwind-utils'
     112              : 
     113              : import CheckoutButton from '#/billing/checkout/CheckoutButton.vue'
     114              : import BillingBannerActionButton from './BillingBannerActionButton.vue'
     115              : import BillingAutoTopUpLines from './BillingAutoTopUpLines.vue'
     116              : import { autoTopUpCardView } from './autoTopUpCardView'
     117              : import type { AutoTopUpCardCopy, AutoTopUpViewKey } from './autoTopUpCardView'
     118              : 
     119              : type ActionVariant = ButtonVariants['variant']
     120              : 
     121            5 : const OPEN = 'icon-[lucide--arrow-up-right]'
     122              : 
     123            2 : const NEUTRAL = { border: 'border-border', text: 'text-muted-foreground' }
     124            2 : const DANGER = { border: 'border-destructive', text: 'text-destructive' }
     125              : 
     126            2 : const DOT: Record<AutoTopUpViewKey, string> = {
     127              :   failed: 'bg-destructive',
     128              :   turnedOff: 'bg-destructive',
     129              :   off: 'bg-muted-foreground',
     130              :   on_hold: 'bg-warning',
     131              :   paused_by_budget: 'bg-warning',
     132              :   maximumReached: 'bg-warning-background',
     133              :   noPaymentMethod: 'bg-muted-foreground',
     134              :   noDefaultPaymentMethod: 'bg-muted-foreground',
     135              :   on: 'bg-success'
     136              : }
     137              : 
     138            2 : const DEFAULT_VARIANTS: Record<AutoTopUpViewKey, ActionVariant> = {
     139              :   failed: 'inverted',
     140              :   turnedOff: 'inverted',
     141              :   off: 'secondary',
     142              :   on_hold: 'inverted',
     143              :   paused_by_budget: 'secondary',
     144              :   maximumReached: 'secondary',
     145              :   noPaymentMethod: 'secondary',
     146              :   noDefaultPaymentMethod: 'secondary',
     147              :   on: 'secondary'
     148              : }
     149              : 
     150              : const {
     151              :   state,
     152              :   offView,
     153              :   setup,
     154              :   copy,
     155              :   locale,
     156              :   actionHref = null,
     157              :   actionHidden = false,
     158              :   variants,
     159              :   classes
     160              : } = defineProps<{
     161              :   state: AutoTopUpCardState
     162              :   offView: AutoTopUpOffView
     163              :   setup: AutoTopUpOffViewFacts['setup']
     164              :   copy: AutoTopUpCardCopy
     165              :   locale: string
     166              :   actionHref?: string | null
     167              :   actionHidden?: boolean
     168              :   variants?: Partial<Record<AutoTopUpViewKey, ActionVariant>>
     169              :   classes?: Partial<
     170              :     Record<
     171              :       'root' | 'card' | 'unavailable' | 'title' | 'status' | 'line' | 'action',
     172              :       string
     173              :     >
     174              :   >
     175              : }>()
     176              : 
     177            2 : const emit = defineEmits<{
     178              :   action: [action: AutoTopUpCardAction]
     179              :   retry: []
     180              : }>()
     181              : 
     182            2 : const view = computed(() =>
     183              :   state.kind === 'loaded'
     184              :     ? autoTopUpCardView(state.settings, offView, copy, locale)
     185              :     : null
     186              : )
     187              : 
     188            2 : const tone = computed(() =>
     189              :   view.value?.key === 'failed' || view.value?.key === 'turnedOff'
     190              :     ? DANGER
     191              :     : NEUTRAL
     192              : )
     193              : 
     194            2 : const actionVariant = computed(() =>
     195              :   view.value
     196              :     ? (variants?.[view.value.key] ?? DEFAULT_VARIANTS[view.value.key])
     197              :     : undefined
     198              : )
     199              : </script>
        

Generated by: LCOV version 2.0-1