@@ -2,7 +2,7 @@ import { createTestingPinia } from '@pinia/testing'
22import { render , screen } from '@testing-library/vue'
33import userEvent from '@testing-library/user-event'
44import { beforeEach , describe , expect , it , vi } from 'vitest'
5- import { computed , ref } from 'vue'
5+ import { computed , nextTick , ref } from 'vue'
66import { createI18n } from 'vue-i18n'
77
88import type { SubscriptionInfo } from '@/composables/billing/types'
@@ -53,7 +53,9 @@ const mockIsInPersonalWorkspace = ref(false)
5353const mockIsWorkspaceSubscribed = ref ( true )
5454const mockCanManageSubscription = ref ( true )
5555const mockBillingControlEnabled = ref ( false )
56- const mockBillingStatus = ref < 'paid' | 'paused' | 'payment_failed' > ( 'paid' )
56+ const mockBillingStatus = ref <
57+ 'paid' | 'paused' | 'payment_failed' | 'inactive'
58+ > ( 'paid' )
5759const mockBillingSubscriptionStatus = ref < 'active' | 'canceled' | 'ended' > (
5860 'active'
5961)
@@ -157,17 +159,6 @@ vi.mock('@/composables/useFeatureFlags', () => ({
157159 } )
158160} ) )
159161
160- vi . mock ( '@/platform/workspace/composables/useTeamPlan' , ( ) => ( {
161- useTeamPlan : ( ) => ( {
162- hasLapsedTeamPlan : computed (
163- ( ) =>
164- ! mockIsInPersonalWorkspace . value &&
165- ( mockBillingSubscriptionStatus . value === 'canceled' ||
166- mockBillingSubscriptionStatus . value === 'ended' )
167- )
168- } )
169- } ) )
170-
171162vi . mock ( '@/platform/workspace/stores/teamWorkspaceStore' , ( ) => ( {
172163 useTeamWorkspaceStore : ( ) => ( {
173164 isInPersonalWorkspace : mockIsInPersonalWorkspace ,
@@ -349,6 +340,30 @@ describe('SubscriptionPanelContentWorkspace', () => {
349340 )
350341 } )
351342
343+ it ( 'removes auto-reload when the billing control kill switch turns off' , async ( ) => {
344+ mockBillingControlEnabled . value = true
345+ renderComponent ( )
346+
347+ expect ( screen . getByTestId ( 'auto-reload-section' ) ) . toBeInTheDocument ( )
348+
349+ mockBillingControlEnabled . value = false
350+ await nextTick ( )
351+
352+ expect ( screen . queryByTestId ( 'auto-reload-section' ) ) . not . toBeInTheDocument ( )
353+ } )
354+
355+ it ( 'removes auto-reload when subscription management permission is revoked' , async ( ) => {
356+ mockBillingControlEnabled . value = true
357+ renderComponent ( )
358+
359+ expect ( screen . getByTestId ( 'auto-reload-section' ) ) . toBeInTheDocument ( )
360+
361+ mockCanManageSubscription . value = false
362+ await nextTick ( )
363+
364+ expect ( screen . queryByTestId ( 'auto-reload-section' ) ) . not . toBeInTheDocument ( )
365+ } )
366+
352367 it ( 'keeps auto-reload hidden from members' , ( ) => {
353368 mockBillingControlEnabled . value = true
354369 mockCanManageSubscription . value = false
@@ -368,19 +383,39 @@ describe('SubscriptionPanelContentWorkspace', () => {
368383 )
369384 } )
370385
371- it . for ( [ 'canceled' , 'ended' ] as const ) (
372- 'freezes auto-reload for a %s team subscription' ,
373- ( status ) => {
374- mockBillingControlEnabled . value = true
375- mockBillingSubscriptionStatus . value = status
376- renderComponent ( )
386+ it ( 'keeps auto-reload interactive while an active cancellation runs to term' , ( ) => {
387+ mockBillingControlEnabled . value = true
388+ mockBillingSubscriptionStatus . value = 'canceled'
389+ mockIsActiveSubscription . value = true
390+ renderComponent ( )
377391
378- expect ( screen . getByTestId ( 'auto-reload-section' ) ) . toHaveAttribute (
379- 'data-frozen' ,
380- 'true'
381- )
382- }
383- )
392+ expect ( screen . getByTestId ( 'auto-reload-section' ) ) . toHaveAttribute (
393+ 'data-frozen' ,
394+ 'false'
395+ )
396+ } )
397+
398+ it ( 'freezes auto-reload after the subscription has ended' , ( ) => {
399+ mockBillingControlEnabled . value = true
400+ mockBillingSubscriptionStatus . value = 'ended'
401+ renderComponent ( )
402+
403+ expect ( screen . getByTestId ( 'auto-reload-section' ) ) . toHaveAttribute (
404+ 'data-frozen' ,
405+ 'true'
406+ )
407+ } )
408+
409+ it ( 'freezes auto-reload while billing is inactive' , ( ) => {
410+ mockBillingControlEnabled . value = true
411+ mockBillingStatus . value = 'inactive'
412+ renderComponent ( )
413+
414+ expect ( screen . getByTestId ( 'auto-reload-section' ) ) . toHaveAttribute (
415+ 'data-frozen' ,
416+ 'true'
417+ )
418+ } )
384419
385420 it ( 'leaves auto-reload interactive when payment is at risk' , ( ) => {
386421 mockBillingControlEnabled . value = true
0 commit comments