Skip to content

Commit

Permalink
Add test for PricingOptions markup order (#855)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielguillan authored Dec 10, 2024
1 parent 85a82b1 commit 5a28ff4
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions packages/react/src/PricingOptions/PricingOptions.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,37 @@ describe('PricingOptions.Item', () => {
expect(getByText(mockFeatureListItem)).toBeInTheDocument()
expect(getByText(mockFootnote)).toBeInTheDocument()
})

it('renders markup in the expected order', () => {
const {getByTestId} = render(
<PricingOptions.Item data-testid={testId}>
<PricingOptions.Footnote>{mockFootnote}</PricingOptions.Footnote>
<PricingOptions.Label>{mockLabel}</PricingOptions.Label>
<PricingOptions.Description>{mockDescription}</PricingOptions.Description>
<PricingOptions.Heading>{mockHeading}</PricingOptions.Heading>
<PricingOptions.FeatureList>
<PricingOptions.FeatureListHeading>{mockFeaturedListHeading}</PricingOptions.FeatureListHeading>
<PricingOptions.FeatureListItem>{mockFeatureListItem}</PricingOptions.FeatureListItem>
</PricingOptions.FeatureList>
</PricingOptions.Item>,
)

const PricingOptionsItemEl = getByTestId(testId)

const expectedOrder = [
'PricingOptions__heading',
'PricingOptions__label',
'PricingOptions__description',
'PricingOptions__featureList',
'PricingOptions__footnote',
]

const elementsWithTestId = PricingOptionsItemEl.querySelectorAll('[data-testid]')

const testIdsInOrder = Array.from(elementsWithTestId)
.map(el => el.getAttribute('data-testid'))
.filter(id => id && expectedOrder.includes(id))

expect(testIdsInOrder).toEqual(expectedOrder)
})
})

0 comments on commit 5a28ff4

Please sign in to comment.