LCOV - code coverage report
Current view: top level - src/platform/billing/components/billingTab - BillingPlanLifecycle.vue Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 34.8 % 23 8
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1            5 : <template>
       2              :   <template v-if="canRevertScheduledChange">
       3              :     <Button
       4              :       v-if="stay"
       5              :       variant="secondary"
       6              :       size="md"
       7              :       class="shrink-0"
       8              :       @click="dispatch({ type: 'opened', intent: stay })"
       9              :     >
      10              :       {{
      11              :         $t('workspacePanel.billingTab.plan.actions.stay', {
      12              :           plan: stay.planName
      13              :         })
      14              :       }}
      15              :     </Button>
      16              :   </template>
      17              :   <template v-if="canReactivate">
      18              :     <Button
      19              :       v-if="resume"
      20              :       variant="secondary"
      21              :       size="md"
      22              :       class="shrink-0"
      23              :       @click="dispatch({ type: 'opened', intent: resume })"
      24              :     >
      25              :       {{ $t('workspacePanel.billingTab.plan.actions.resume') }}
      26              :     </Button>
      27              :   </template>
      28              : 
      29              :   <Dialog :open="confirm.phase !== 'closed'" @update:open="onOpenChange">
      30              :     <DialogPortal>
      31              :       <DialogOverlay />
      32              :       <DialogContent
      33              :         v-if="confirm.phase !== 'closed'"
      34              :         size="sm"
      35              :         data-testid="billing-plan-confirm"
      36              :       >
      37              :         <DialogHeader>
      38              :           <DialogTitle>{{ copy.title }}</DialogTitle>
      39              :           <DialogClose :aria-label="$t('g.close')" />
      40              :         </DialogHeader>
      41              :         <div class="flex flex-col gap-2 px-4 py-2">
      42              :           <DialogDescription>{{ copy.body }}</DialogDescription>
      43              :           <p
      44              :             v-if="confirm.phase === 'refused'"
      45              :             role="alert"
      46              :             class="m-0 text-sm wrap-break-word text-destructive"
      47              :           >
      48              :             {{
      49              :               confirm.serverMessage ??
      50              :               $t('workspacePanel.billingTab.plan.lifecycleRefused')
      51              :             }}
      52              :           </p>
      53              :         </div>
      54              :         <DialogFooter>
      55              :           <Button
      56              :             variant="secondary"
      57              :             :loading="confirm.phase === 'submitting'"
      58              :             @click="submit"
      59              :           >
      60              :             {{ copy.confirm }}
      61              :           </Button>
      62              :         </DialogFooter>
      63              :       </DialogContent>
      64              :     </DialogPortal>
      65              :   </Dialog>
      66              : </template>
      67              : 
      68              : <script setup lang="ts">
      69              : import { computed, shallowRef } from 'vue'
      70              : import { useI18n } from 'vue-i18n'
      71              : 
      72              : import Button from '@comfyorg/design-system/button/Button'
      73              : import Dialog from '@comfyorg/design-system/dialog/Dialog'
      74              : import DialogClose from '@comfyorg/design-system/dialog/DialogClose'
      75              : import DialogContent from '@comfyorg/design-system/dialog/DialogContent'
      76              : import DialogDescription from '@comfyorg/design-system/dialog/DialogDescription'
      77              : import DialogFooter from '@comfyorg/design-system/dialog/DialogFooter'
      78              : import DialogHeader from '@comfyorg/design-system/dialog/DialogHeader'
      79              : import DialogOverlay from '@comfyorg/design-system/dialog/DialogOverlay'
      80              : import DialogPortal from '@comfyorg/design-system/dialog/DialogPortal'
      81              : import DialogTitle from '@comfyorg/design-system/dialog/DialogTitle'
      82              : import {
      83              :   formatPlanDate,
      84              :   PLAN_CONFIRM_CLOSED,
      85              :   reducePlanConfirm,
      86              :   resumeIntent,
      87              :   stayIntent
      88              : } from '@comfyorg/account-core/billing'
      89              : import type {
      90              :   PlanConfirmEvent,
      91              :   PlanConfirmState,
      92              :   PlanLifecycleIntent,
      93              :   PlanRowState
      94              : } from '@comfyorg/account-core/billing'
      95              : import { usePlanLifecycleCommands } from '@/platform/billing/components/billingTab/usePlanLifecycleCommands'
      96              : import { useBillingCapabilities } from '@/platform/billing/composables/useBillingCapabilities'
      97              : 
      98              : const { state } = defineProps<{ state: PlanRowState }>()
      99              : 
     100            5 : const { t, locale } = useI18n()
     101            5 : const { canRevertScheduledChange, canReactivate } = useBillingCapabilities()
     102            5 : const { revertScheduledChange, resumePlan } = usePlanLifecycleCommands()
     103              : 
     104            5 : const confirm = shallowRef<PlanConfirmState>(PLAN_CONFIRM_CLOSED)
     105              : 
     106            5 : const stay = computed(() => stayIntent(state))
     107            5 : const resume = computed(() => resumeIntent(state))
     108              : 
     109            0 : function dispatch(event: PlanConfirmEvent) {
     110            0 :   confirm.value = reducePlanConfirm(confirm.value, event)
     111              : }
     112              : 
     113            0 : function copyFor(intent: PlanLifecycleIntent) {
     114            0 :   const key = 'workspacePanel.billingTab.plan'
     115            0 :   if (intent.kind === 'stay') {
     116            0 :     const date = formatPlanDate(intent.effectiveAt, locale.value, null)
     117            0 :     return {
     118              :       title: t(`${key}.stayConfirm.title`, { plan: intent.targetPlanName }),
     119              :       body: date
     120              :         ? t(`${key}.stayConfirm.body`, { current: intent.planName, date })
     121              :         : t(`${key}.stayConfirm.bodyNoAmount`, { current: intent.planName }),
     122              :       confirm: t(`${key}.actions.stay`, { plan: intent.planName })
     123              :     }
     124              :   }
     125            0 :   return {
     126              :     title: t(`${key}.resumeConfirm.title`, { plan: intent.planName }),
     127              :     body: t(`${key}.resumeConfirm.body`, {
     128              :       date: formatPlanDate(intent.renewsAt, locale.value, null)
     129              :     }),
     130              :     confirm: t(`${key}.actions.resume`)
     131              :   }
     132              : }
     133              : 
     134            5 : const copy = computed(() =>
     135              :   confirm.value.phase === 'closed'
     136              :     ? { title: '', body: '', confirm: '' }
     137              :     : copyFor(confirm.value.intent)
     138              : )
     139              : 
     140            0 : function onOpenChange(open: boolean) {
     141            0 :   if (!open) dispatch({ type: 'dismissed' })
     142              : }
     143              : 
     144            0 : async function submit() {
     145            0 :   const current = confirm.value
     146            0 :   if (current.phase !== 'confirming' && current.phase !== 'refused') return
     147            0 :   dispatch({ type: 'submitted' })
     148              :   const outcome =
     149              :     current.intent.kind === 'stay'
     150              :       ? await revertScheduledChange()
     151              :       : await resumePlan()
     152            0 :   dispatch({ type: 'settled', outcome })
     153              : }
     154              : </script>
        

Generated by: LCOV version 2.0-1