diff --git a/lib/PortingEmbed/PortingForm.tsx b/lib/PortingEmbed/PortingForm.tsx index 606bfb6..b8b30b7 100644 --- a/lib/PortingEmbed/PortingForm.tsx +++ b/lib/PortingEmbed/PortingForm.tsx @@ -59,7 +59,7 @@ export function PortingForm({ porting, onValidationChange, onSubmit }: Props) { ) } - if (step === 'donorApproval') { + if (step === 'donorProviderApproval') { return ( { it('goes through all required steps', async () => { const user = userEvent.setup() const completedEvent = vitest.fn() + const stepChangeEvent = vitest.fn() const csn = await createFixtures() const embed = await PortingEmbed(csn, { project }) embed.mount('#mount') embed.on('completed', completedEvent) + embed.on('stepChange', stepChangeEvent) + expect(embed.currentStep()).toBe('carrierDetails') const getCurrentPorting = () => { const sub = db.subscriptions.find( @@ -249,6 +252,10 @@ describe('updating a porting', () => { await user.click(screen.getByRole('button', { name: 'Submit' })) await screen.findByLabelText('First Name') + expect(stepChangeEvent).toHaveBeenLastCalledWith({ + nextStep: 'holderDetails', + prevStep: 'carrierDetails', + }) expect(getCurrentPorting()).toMatchObject({ accountPinExists: true, accountNumber: '11880', @@ -264,6 +271,10 @@ describe('updating a porting', () => { await user.click(screen.getByRole('button', { name: 'Submit' })) await screen.findByLabelText('Line 1') + expect(stepChangeEvent).toHaveBeenLastCalledWith({ + nextStep: 'address', + prevStep: 'holderDetails', + }) expect(getCurrentPorting()).toMatchObject({ accountPinExists: true, accountNumber: '11880', @@ -281,6 +292,10 @@ describe('updating a porting', () => { await user.click(screen.getByRole('button', { name: 'Submit' })) await screen.findByLabelText(/i have notified my current/i) + expect(stepChangeEvent).toHaveBeenLastCalledWith({ + nextStep: 'donorProviderApproval', + prevStep: 'address', + }) expect(getCurrentPorting()).toMatchObject({ accountPinExists: true, accountNumber: '11880', @@ -320,6 +335,10 @@ describe('updating a porting', () => { } await waitFor(() => expect(completedEvent).toHaveBeenCalled()) + expect(stepChangeEvent).toHaveBeenLastCalledWith({ + nextStep: null, + prevStep: 'donorProviderApproval', + }) expect(completedEvent).toHaveBeenCalledOnce() expect(completedEvent).toHaveBeenCalledWith({ diff --git a/lib/PortingEmbed/__tests__/wizardStep.test.ts b/lib/PortingEmbed/__tests__/wizardStep.test.ts index 4073d37..fb069ba 100644 --- a/lib/PortingEmbed/__tests__/wizardStep.test.ts +++ b/lib/PortingEmbed/__tests__/wizardStep.test.ts @@ -158,7 +158,7 @@ describe('donor approval', () => { donorProviderApproval: null, }) .build() - expect(wizardStep(porting)).toBe('donorApproval') + expect(wizardStep(porting)).toBe('donorProviderApproval') }) it('skips if donor approval was set', () => { @@ -185,7 +185,7 @@ describe('donor approval', () => { donorProviderApproval: null, }) .build() - expect(wizardStep(porting)).toBe('donorApproval') + expect(wizardStep(porting)).toBe('donorProviderApproval') }) }) diff --git a/lib/PortingEmbed/wizardStep.ts b/lib/PortingEmbed/wizardStep.ts index 241fcb0..fc0b55b 100644 --- a/lib/PortingEmbed/wizardStep.ts +++ b/lib/PortingEmbed/wizardStep.ts @@ -13,8 +13,8 @@ export function wizardStep(porting: Porting) { return 'address' as const } - if (requiresDonorApproval(porting)) { - return 'donorApproval' as const + if (requiresDonorProviderApproval(porting)) { + return 'donorProviderApproval' as const } return null @@ -52,7 +52,7 @@ function requiresAddress(porting: Porting) { return requires(porting, 'address') && !porting.address } -function requiresDonorApproval(porting: Porting) { +function requiresDonorProviderApproval(porting: Porting) { return ( requires(porting, 'donorProviderApproval') && !porting.donorProviderApproval )