Skip to content

Commit

Permalink
Add tests for stepChange event
Browse files Browse the repository at this point in the history
  • Loading branch information
timomeh committed Mar 1, 2024
1 parent 059caed commit 29c554a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/PortingEmbed/PortingForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function PortingForm({ porting, onValidationChange, onSubmit }: Props) {
)
}

if (step === 'donorApproval') {
if (step === 'donorProviderApproval') {
return (
<StepDonorProviderApprovalForm
porting={porting}
Expand Down
19 changes: 19 additions & 0 deletions lib/PortingEmbed/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,14 @@ describe('updating a porting', () => {
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(
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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({
Expand Down
4 changes: 2 additions & 2 deletions lib/PortingEmbed/__tests__/wizardStep.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -185,7 +185,7 @@ describe('donor approval', () => {
donorProviderApproval: null,
})
.build()
expect(wizardStep(porting)).toBe('donorApproval')
expect(wizardStep(porting)).toBe('donorProviderApproval')
})
})

Expand Down
6 changes: 3 additions & 3 deletions lib/PortingEmbed/wizardStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
Expand Down

0 comments on commit 29c554a

Please sign in to comment.