Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions packages/ripple-ui-core/src/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export { default as RplPrimaryCampaign } from './components/campaign-banner/RplP
export { default as RplPrimaryNav } from './components/primary-nav/RplPrimaryNav.vue'
export { default as RplProfile } from './components/profile/RplProfile.vue'
export { default as RplPromoCard } from './components/card/RplPromoCard.vue'
export { default as RplProgress } from './components/progress/RplProgress.vue'
export { default as RplRelatedLinks } from './components/related-links/RplRelatedLinks.vue'
export { default as RplResultListing } from './components/result-listing/RplResultListing.vue'
export { default as RplResultListingItem } from './components/result-listing/RplResultListingItem.vue'
Expand Down
101 changes: 101 additions & 0 deletions packages/ripple-ui-forms/src/components/RplForm/RplForm.cy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,60 @@
import RplForm from './RplForm.vue'
import { schema } from './fixtures/sample'

const multiStepSchema: any[] = [
{
$step: true,
id: 'step-one',
key: 'step-one',
name: 'step-one',
title: 'Step one',
nextButton: 'Next',
schema: [
{
$formkit: 'RplFormText',
id: 'first_name',
name: 'first_name',
label: 'First name',
validation: [['required']],
value: ''
}
]
},
{
$step: true,
id: 'step-two',
key: 'step-two',
name: 'step-two',
title: 'Step two',
nextButton: 'Review',
prevButton: 'Back',
schema: [
{
$formkit: 'RplFormText',
id: 'email',
name: 'email',
label: 'Email',
value: ''
}
]
},
{
$step: true,
id: 'review',
key: 'review',
name: 'review',
title: 'Review',
nextButton: 'Submit',
prevButton: 'Back',
schema: [
{
$formkit: 'RplFormReview',
key: 'review_component'
}
]
}
]

describe('<RplForm />', () => {
it('renders', () => {
// see: https://test-utils.vuejs.org/guide/
Expand Down Expand Up @@ -37,4 +91,51 @@ describe('<RplForm />', () => {
cy.get('button[type="submit"]').should('be.disabled')
cy.get('button[type="reset"]').should('be.disabled')
})

it('validates and navigates between multi-step form steps', () => {
cy.mount(RplForm, {
props: {
id: 'test-multi-step-form',
schema: multiStepSchema
}
})

cy.contains('Step 1 of 3').should('be.visible')
cy.contains('h3', 'Step one').should('be.visible')

cy.contains('button', 'Next').click()
cy.contains('There is a problem').should('be.visible')
cy.contains('Step 1 of 3').should('be.visible')

cy.get('[name="first_name"]').type('Taylor')
cy.contains('button', 'Next').click()

cy.contains('Step 2 of 3').should('be.visible')
cy.contains('h3', 'Step two').should('be.visible')

cy.contains('button', 'Back').click()
cy.contains('Step 1 of 3').should('be.visible')
cy.contains('h3', 'Step one').should('be.visible')
})

it('renders review step content in multi-step form', () => {
cy.viewport('macbook-13')
cy.mount(RplForm, {
props: {
id: 'test-multi-step-review-form',
schema: multiStepSchema
}
})

cy.get('[name="first_name"]').type('Taylor')
cy.contains('button', 'Next').click()
cy.get('[name="email"]').type('taylor@example.com')
cy.contains('button', 'Review').click()

cy.contains('Step 3 of 3').should('be.visible')
cy.contains('h3', 'Review').should('be.visible')
cy.contains('Step one').should('be.visible')
cy.contains('Step two').should('be.visible')
cy.contains('Change').should('be.visible')
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ const handleStepChange = async ({

// Get the current steps errors when it's invalid, and we're trying to proceed
if (!currentStep.isValid && forwards) {
cachedErrors.value = getErrorMessages(getNode(currentStep.id))
cachedErrors.value = getErrorMessages(currentStep.node)
Comment thread
dylankelly marked this conversation as resolved.
}

if (isStepValid) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
import type { Meta, StoryObj } from '@storybook/vue3'
import RplForm from './RplForm.vue'
import { handleEligibilityStepChange } from './fixtures/before-step-change'
import '@dpc-sdp/ripple-ui-core/style/components'

export default {
title: 'Forms/Multi step form',
component: RplForm
} satisfies Meta<typeof RplForm>

type Story = StoryObj<typeof RplForm>

export const DefaultStory: Story = {
name: 'Default',
render: (args) => ({
components: { RplForm },
setup() {
return { args }
},
template: `
<RplForm
v-bind="args"
:style="{
'--local-max-width': '695px'
}"
>
<template #belowForm="{ value }">
<div class="rpl-storybook-form-values rpl-u-margin-t-6">
<h2 class="rpl-type-h4">Internal form values</h2>
<pre wrap>{{ value }}</pre>
</div>
</template>
</RplForm>
`
}),
args: {
id: 'multi-step-form',
schema: [
{
$step: true,
id: 'eligibility',
key: 'eligibility',
name: 'eligibility',
title: 'Eligibility',
nextButton: 'Next',
beforeStepChange: handleEligibilityStepChange,
schema: [
{
$formkit: 'RplFormFieldset',
legend: 'Address',
name: 'address',
children: [
{
$formkit: 'RplFormText',
id: 'forms_address_organization',
name: 'organization',
label: 'Organization',
validation: [['required']],
validationMessages: {
required: 'The message field is required',
matches: 'Please enter between 10 and 50 characters'
},
value: ''
},
{
$formkit: 'RplFormText',
id: 'forms_address_given_name',
name: 'given_name',
label: 'Given name',
validation: [],
value: ''
},
{
$formkit: 'RplFormText',
id: 'forms_address_family_name',
name: 'family_name',
label: 'Family name',
validation: [],
value: ''
},
{
$formkit: 'RplFormText',
id: 'forms_address_address_line1',
name: 'address_line1',
label: 'Street address',
validation: [],
value: ''
},
{
$formkit: 'RplFormText',
id: 'forms_address_address_line2',
name: 'address_line2',
label: 'Street address line 2',
validation: [],
value: ''
},
{
$formkit: 'RplFormText',
id: 'forms_address_locality',
name: 'locality',
label: 'Suburb',
columnClasses: 'rpl-col-12 rpl-col-5-m',
validation: [],
value: ''
},
{
$formkit: 'RplFormDropdown',
id: 'forms_address_administrative_area',
name: 'administrative_area',
label: 'State',
columnClasses: 'rpl-col-12 rpl-col-5-m',
options: [
{
id: 'VIC',
value: 'VIC',
label: 'Victoria'
},
{
id: 'NSW',
value: 'NSW',
label: 'New South Wales'
},
{
id: 'WA',
value: 'WA',
label: 'Western Australia'
},
{
id: 'QLD',
value: 'QLD',
label: 'Queensland'
},
{
id: 'ACT',
value: 'ACT',
label: 'Australian Capital Territory'
},
{
id: 'NT',
value: 'NT',
label: 'Northern Territory'
},
{
id: 'SA',
value: 'SA',
label: 'South Australia'
},
{
id: 'TAS',
value: 'TAS',
label: 'Tasmania'
}
],
validation: [],
value: '',
pii: false
},
{
$formkit: 'RplFormText',
id: 'forms_address_postal_code',
name: 'postal_code',
label: 'Postcode',
columnClasses: 'rpl-col-6 rpl-col-3-m',
validation: [],
value: ''
},
{
$formkit: 'hidden',
id: 'forms_address_country_code',
name: 'country_code',
value: 'AU'
}
]
}
]
},
{
$step: true,
id: 'not-eligible',
key: 'not-eligible',
name: 'not-eligible',
title: 'Not eligible',
nextButton: 'Exit',
prevButton: 'Go backwards',
beforeStepChange: handleEligibilityStepChange,
parentStep: 'eligibility',
schema: [
{
$el: 'div',
attrs: {
class: 'rpl-content'
},
children: [
{
$el: 'p',
children:
'Unfortunately, based on the information you have provided, you are not eligible to apply for this grant.'
}
]
}
]
},
{
$step: true,
id: 'eligible',
key: 'eligible',
name: 'eligible',
title: 'You are eligible',
nextButton: 'Go forwards',
prevButton: 'Go backwards',
beforeStepChange: handleEligibilityStepChange,
parentStep: 'eligibility',
schema: [
{
$el: 'div',
attrs: {
class: ['rpl-content', 'rpl-u-padding-b-4']
},
children: [
{
$el: 'p',
children:
'Congratulations! Based on the information you have provided, you are eligible to apply for this grant.'
}
]
}
]
},
{
$step: true,
id: 'review',
key: 'review',
name: 'review',
title: 'Review',
nextButton: 'Submit',
prevButton: 'Go backwards',
schema: [
{
$formkit: 'RplFormReview',
key: 'review_component'
}
]
}
]
}
}
Loading
Loading