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 @@ -398,17 +398,25 @@ describe('SubscriptionAddPaymentPreviewWorkspace', () => {
expect(screen.getByText('op-reconcile-123')).toBeTruthy()
})

it('does not render a back action on the payment confirmation', () => {
render(SubscriptionAddPaymentPreviewWorkspace, {
props: { tierKey: 'creator', isLoading: true },
global: globalOptions
it('owns a back action whether or not the payment element is embedded', async () => {
const { emitted } = render(SubscriptionAddPaymentPreviewWorkspace, {
props: { tierKey: 'creator' },
global: {
...globalOptions,
stubs: {
...globalOptions.stubs,
Button: {
props: ['ariaLabel'],
template:
'<button :aria-label="ariaLabel" @click="$emit(\'click\')"><slot /></button>'
}
}
}
})

expect(
screen.queryByRole('button', {
name: 'subscription.preview.backToAllPlans'
})
).toBeNull()
await userEvent.click(screen.getByRole('button', { name: 'g.back' }))

expect(emitted().back).toBeTruthy()
})

it('prices a legacy preview from the server costs instead of rendering a blank total', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
:class="cn('mb-8 flex items-center gap-3', captureMode && 'xl:mb-10')"
>
<Button
v-if="usePaymentElement"
size="icon"
variant="muted-textonly"
class="shrink-0 rounded-full"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { createI18n } from 'vue-i18n'
import SubscriptionRequiredDialogContentUnified from './SubscriptionRequiredDialogContentUnified.vue'

const mockHandleSubscribeTeamClick = vi.fn()
const mockHandleBackToPricing = vi.fn()
const mockHandleSubscribeClick = vi.fn()
const mockInvalidateQuote = vi.fn()
const mockIsInPersonalWorkspace = ref(false)
Expand Down Expand Up @@ -42,7 +43,7 @@ vi.mock('@/platform/workspace/composables/useSubscriptionCheckout', () => ({
previewVariant: computed(() => mockPreviewVariant.value),
handleSubscribeClick: mockHandleSubscribeClick,
handleSubscribeTeamClick: mockHandleSubscribeTeamClick,
handleBackToPricing: vi.fn(),
handleBackToPricing: mockHandleBackToPricing,
handleSuccessClose: vi.fn(),
handleAddCreditCard: vi.fn(),
handleConfirmTransition: vi.fn(),
Expand Down Expand Up @@ -112,6 +113,7 @@ function renderComponent(props: Record<string, unknown> = {}) {
<span data-testid="payment-element-enabled">{{ usePaymentElement }}</span>
<button data-testid="saved-method-btn" @click="$emit('update:selectedSavedMethodId', 'pm_other')">Saved method</button>
<button data-testid="new-method-btn" @click="$emit('changePaymentMethod')">New method</button>
<button aria-label="Back" @click="$emit('back')">Back</button>
</div>`
},
SubscriptionTransitionPreviewWorkspace: { template: '<div />' },
Expand Down Expand Up @@ -248,4 +250,22 @@ describe('SubscriptionRequiredDialogContentUnified team-plan subscribe', () => {
})
expect(mockHandleSubscribeClick).not.toHaveBeenCalled()
})

it.for([true, false])(
'leaves the confirm step its own header and back action (embedded: %s)',
async (embeddedCheckoutEnabled) => {
mockCheckoutStep.value = 'preview'
mockPreviewVariant.value = 'team-new'
mockSelectedTeamStop.value = TEAM_PAYLOAD.stop

renderComponent({ embeddedCheckoutEnabled })

expect(screen.queryByText('Choose your plan')).toBeNull()
expect(screen.getAllByRole('button', { name: 'Back' })).toHaveLength(1)

await userEvent.click(screen.getByRole('button', { name: 'Back' }))

expect(mockHandleBackToPricing).toHaveBeenCalled()
}
)
})
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,6 @@
)
"
>
<Button
v-if="
checkoutStep === 'preview' &&
!isEmbeddedPaymentStep &&
!isEmbeddedConfirmStep
"
size="icon"
variant="muted-textonly"
class="absolute top-2.5 left-2.5 shrink-0 rounded-full text-text-secondary hover:bg-white/10"
:aria-label="$t('g.back')"
:disabled="isPolling"
@click="handleBackToPricing"
>
<i class="pi pi-arrow-left text-xl" />
</Button>

<Button
size="icon"
variant="muted-textonly"
Expand All @@ -54,15 +38,9 @@
<i class="pi pi-times text-xl" />
</Button>

<!-- The embedded payment step titles itself ("Confirm your payment");
stacking "Choose a Plan" above it doubled the header and made this
step taller than the pricing table. -->
<!-- The confirm and success steps title themselves. -->
<div
v-if="
!isEmbeddedPaymentStep &&
!isEmbeddedSuccessStep &&
!isEmbeddedConfirmStep
"
v-if="checkoutStep === 'pricing'"
class="flex flex-col items-center gap-3"
>
<h2 class="m-0 font-inter text-2xl font-semibold text-base-foreground">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const AddPaymentPreviewStub = {
<button data-testid="add-card-btn" @click="$emit('addCreditCard')">Add Card</button>
<button data-testid="apply-promo-btn" @click="$emit('applyPromotionCode', 'SAVE20')">Apply promo</button>
<button data-testid="invalidate-quote-btn" @click="$emit('invalidateQuote')">Invalidate quote</button>
<button @click="$emit('back')">Back</button>
</div>`
}

Expand Down Expand Up @@ -209,11 +210,11 @@ describe('SubscriptionRequiredDialogContentWorkspace', () => {
expect(onClose).toHaveBeenCalledOnce()
})

it('shows back button on preview step', () => {
it('leaves the back action to the preview step that renders its own', () => {
mockCheckoutStep.value = 'preview'
mockPreviewData.value = { transition_type: 'new_subscription' }
renderComponent()
expect(screen.getByLabelText('Back')).toBeInTheDocument()
expect(screen.getAllByRole('button', { name: 'Back' })).toHaveLength(1)
})

it('shows insufficient credits message when reason is out_of_credits', () => {
Expand Down Expand Up @@ -283,7 +284,7 @@ describe('SubscriptionRequiredDialogContentWorkspace', () => {
mockPreviewData.value = { transition_type: 'new_subscription' }
renderComponent()

await user.click(screen.getByLabelText('Back'))
await user.click(screen.getByRole('button', { name: 'Back' }))

expect(mockHandleBackToPricing).toHaveBeenCalled()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,6 @@
<div
class="relative flex h-full flex-col gap-6 overflow-y-auto p-4 pt-8 md:px-16 md:py-8"
>
<Button
v-if="checkoutStep === 'preview'"
size="icon"
variant="muted-textonly"
class="absolute top-2.5 left-2.5 shrink-0 rounded-full text-text-secondary hover:bg-white/10"
:aria-label="$t('g.back')"
:disabled="isPolling"
@click="handleBackToPricing"
>
<i class="pi pi-arrow-left text-xl" />
</Button>

<Button
size="icon"
variant="muted-textonly"
Expand Down
Loading