Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -6,6 +6,7 @@ import { nextTick, ref } from 'vue'
import CloudRunButtonWrapper from './CloudRunButtonWrapper.vue'

const mockCanRunWorkflows = ref(true)
const mockIsInitialized = ref(true)
const mockBillingStatus = ref<string | null>('paid')
const state = vi.hoisted(() => ({
v1PaymentRecovery: true,
Expand All @@ -19,15 +20,21 @@ const state = vi.hoisted(() => ({
updateDialog: vi.fn()
}))

vi.mock('@/composables/billing/useBillingContext', () => ({
useBillingContext: () => ({
canRunWorkflows: mockCanRunWorkflows,
billingStatus: mockBillingStatus,
manageSubscription: state.manageSubscription,
fetchStatus: state.fetchStatus,
fetchBalance: state.fetchBalance
})
}))
vi.mock('@/composables/billing/useBillingContext', async () => {
const { computed } = await import('vue')
return {
useBillingContext: () => ({
canRunWorkflows: mockCanRunWorkflows,
showsSubscribeToRunPrompt: computed(
() => mockIsInitialized.value && !mockCanRunWorkflows.value
),
billingStatus: mockBillingStatus,
manageSubscription: state.manageSubscription,
fetchStatus: state.fetchStatus,
fetchBalance: state.fetchBalance
})
}
})

vi.mock('@/composables/useFeatureFlags', () => ({
useFeatureFlags: () => ({
Expand Down Expand Up @@ -89,6 +96,7 @@ function renderWrapper() {
describe('CloudRunButtonWrapper', () => {
beforeEach(() => {
mockCanRunWorkflows.value = true
mockIsInitialized.value = true
mockBillingStatus.value = 'paid'
state.v1PaymentRecovery = true
state.canManageSubscription = true
Expand All @@ -104,6 +112,18 @@ describe('CloudRunButtonWrapper', () => {
).not.toBeInTheDocument()
})

it('keeps the run button while billing status is still resolving', () => {
mockCanRunWorkflows.value = false
mockIsInitialized.value = false

render(CloudRunButtonWrapper)

expect(screen.getByTestId('queue-button')).toBeInTheDocument()
expect(
screen.queryByTestId('subscribe-to-run-button')
).not.toBeInTheDocument()
Comment on lines +121 to +124

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Prefer accessible queries for these controls.

getByTestId and queryByTestId couple the test to implementation-specific hooks. Use accessible button queries or visible labels when stable names are available.

Based on learnings, prefer accessible properties over data-testid selectors in component tests.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/actionbar/ComfyRunButton/CloudRunButtonWrapper.test.ts` around
lines 121 - 124, Replace the test-id assertions in the relevant test with
accessible button queries, using each control’s stable visible label or
accessible name. Preserve the existing expectations that the queue button is
present and the subscribe-to-run button is absent.

Source: Learnings

})

it('locks the run button when the subscription is inactive', () => {
mockCanRunWorkflows.value = false
renderWrapper()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<ComfyQueueButton
v-if="canRunWorkflows || paymentRecoveryLock"
v-if="!showsSubscribeToRunPrompt || paymentRecoveryLock"
:payment-recovery-lock="paymentRecoveryLock"
@payment-recovery-click="showPaymentRecoveryDialog"
/>
Expand All @@ -22,7 +22,7 @@ import { useDialogStore } from '@/stores/dialogStore'

const DIALOG_KEY = 'subscription-paused'
const {
canRunWorkflows,
showsSubscribeToRunPrompt,
billingStatus,
manageSubscription,
fetchStatus,
Expand Down
1 change: 1 addition & 0 deletions src/composables/billing/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export interface BillingContext extends BillingState, BillingActions {
isTeamPlan: ComputedRef<boolean>
getMaxSeats: (tierKey: TierKey) => number
canRunWorkflows: ComputedRef<boolean>
showsSubscribeToRunPrompt: ComputedRef<boolean>
/** @deprecated Use canAccessSubscriptionFeatures instead */
isActiveSubscription: ComputedRef<boolean>
}
5 changes: 5 additions & 0 deletions src/composables/billing/useBillingContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ function useBillingContextInternal(): BillingContext {
freeTierQuota.freeTierExecutionPermitted.value)
)

const showsSubscribeToRunPrompt = computed(
() => isInitialized.value && !canRunWorkflows.value
)

const isLegacyTeamPlan = computed(
() =>
type.value === 'workspace' &&
Expand Down Expand Up @@ -354,6 +358,7 @@ function useBillingContextInternal(): BillingContext {
error,
isActiveSubscription,
canRunWorkflows,
showsSubscribeToRunPrompt,
canAccessSubscriptionFeatures,
isFreeTier,
isLegacyTeamPlan,
Expand Down
12 changes: 9 additions & 3 deletions src/renderer/extensions/linearMode/LinearControls.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const { t } = useI18n()
const commandStore = useCommandStore()
const { batchCount } = storeToRefs(useQueueSettingsStore())
const settingStore = useSettingStore()
const { canRunWorkflows } = useBillingContext()
const { canRunWorkflows, showsSubscribeToRunPrompt } = useBillingContext()
const workflowStore = useWorkflowStore()
const { isBuilderMode } = useAppMode()
const appModeStore = useAppModeStore()
Expand Down Expand Up @@ -179,7 +179,10 @@ function replayAppModeTour() {
>
<LinearRunErrorWarning v-if="showRunErrorWarning" />
<div v-coachmark="COACH_IDS.appRunButton">
<SubscribeToRunButton v-if="!canRunWorkflows" class="mt-4 w-full" />
<SubscribeToRunButton
v-if="showsSubscribeToRunPrompt"
class="mt-4 w-full"
/>
<div v-else class="mt-4 flex">
<PartnerNodesList mobile />
<Popover side="top" @open-auto-focus.prevent>
Expand Down Expand Up @@ -243,7 +246,10 @@ function replayAppModeTour() {
:max="settingStore.get('Comfy.QueueButton.BatchCountLimit')"
class="h-7 min-w-40"
/>
<SubscribeToRunButton v-if="!canRunWorkflows" class="mt-4 w-full" />
<SubscribeToRunButton
v-if="showsSubscribeToRunPrompt"
class="mt-4 w-full"
/>
<Button
v-else
variant="primary"
Expand Down
3 changes: 3 additions & 0 deletions src/storybook/mocks/useBillingContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ export function useBillingContext(): BillingContext {
error: ref<string | null>(null),
isActiveSubscription: computed(() => state.value.isActiveSubscription),
canRunWorkflows: computed(() => state.value.isActiveSubscription),
showsSubscribeToRunPrompt: computed(
() => !state.value.isActiveSubscription
),
canAccessSubscriptionFeatures: computed(
() => state.value.isActiveSubscription
),
Expand Down
Loading