-
Notifications
You must be signed in to change notification settings - Fork 14
/
Accordion.spec.tsx
119 lines (106 loc) · 2.51 KB
/
Accordion.spec.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import React, { useState } from 'react'
import {
Accordion,
Typography,
Button,
Container,
Check16,
} from '@toptal/picasso'
const Summary = ({
onClick,
expanded,
}: {
onClick: () => void
expanded: boolean
}) => (
<Container
flex
alignItems='center'
justifyContent='space-between'
bottom='small'
top='small'
>
<Typography variant='heading' size='medium'>
Upcoming interviews
</Typography>
<Container>
<Button variant='secondary' onClick={onClick} data-testid='trigger'>
{expanded ? 'Hide' : 'Show'}
</Button>
</Container>
</Container>
)
const Content = () => (
<Container
bordered
flex
justifyContent='space-around'
padded='medium'
data-testid='content'
>
<Button
data-testid='start-onboarding'
size='small'
onClick={() => window.alert('Onboarding started')}
>
Start Interview Onboarding
</Button>
</Container>
)
const AccordionCustomSummary = () => {
const [expanded, setExpanded] = useState(true)
const handleClick = () => {
setExpanded(prevExpanded => !prevExpanded)
}
return (
<>
<Summary onClick={handleClick} expanded={expanded} />
<Accordion
data-testid='accordion-custom-summary'
content={<Content />}
expanded={expanded}
borders='none'
/>
</>
)
}
const component = 'Accordion'
describe('Accordion', () => {
it('renders custom summary and content', () => {
cy.mount(<AccordionCustomSummary />)
cy.getByTestId('trigger').click()
cy.getByTestId('content').should('not.be.visible')
cy.get('body').happoScreenshot({
component,
variant: 'custom-summary-content/before-expanded',
})
cy.getByTestId('trigger').click()
cy.getByTestId('content').should('be.visible')
cy.get('body').happoScreenshot({
component,
variant: 'custom-summary-content/after-expanded',
})
// check if content is interactive
cy.getByTestId('start-onboarding').click()
cy.on('window:alert', text => {
expect(text).equal('Onboarding started')
})
})
it('renders custom expand icon', () => {
cy.mount(
<Accordion
data-testid='accordion'
content='Aliqua ut aliquip dolor velit.'
expandIcon={<Check16 />}
>
<Accordion.Summary>
Est amet duis deserunt proident Lorem.
</Accordion.Summary>
</Accordion>
)
cy.get('body').happoScreenshot({
component,
variant: 'custom-expand-icon',
})
})
})