Skip to content

Commit

Permalink
Merge pull request #1442 from cozy/testing-steps
Browse files Browse the repository at this point in the history
  • Loading branch information
ptbrowne authored Apr 24, 2020
2 parents 04a8f91 + daa58e0 commit a2623e4
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions react/Stepper/testing.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React from 'react'
import { render } from '@testing-library/react'

import {
Stepper,
Step,
StepLabel,
StepButton
} from 'cozy-ui/transpiled/react/Stepper'

const renderSVGWarningIcon = () => {
const { getByRole } = render(
<Stepper>
<Step>
<StepButton>
<StepLabel error={true}>error</StepLabel>
</StepButton>
</Step>
</Stepper>
)
const button = getByRole('button')
const svg = button.querySelector('svg')
return svg
}

let warningSvg

const findStepButtonFromLabelNode = node => {
return node.parentNode.parentNode.parentNode
}

const haveSameClassList = (node1, node2) => {
const cs1 = node1.classList.toString()
const cs2 = node2.classList.toString()
return cs1 === cs2
}

const isWarningStep = stepLabelNode => {
const stepButtonNode = findStepButtonFromLabelNode(stepLabelNode)
const icon = stepButtonNode.querySelector('svg')
return haveSameClassList(warningSvg, icon)
}

beforeEach(() => {
warningSvg = renderSVGWarningIcon()
})

export { isWarningStep }

0 comments on commit a2623e4

Please sign in to comment.