forked from cypress-io/cypress-react-unit-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodal-spec.js
61 lines (54 loc) · 1.66 KB
/
modal-spec.js
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
import React from 'react'
import { Button, Modal } from 'react-bootstrap'
import { mount } from 'cypress-react-unit-test'
export class Example extends React.Component {
constructor(props, context) {
super(props, context)
this.handleShow = this.handleShow.bind(this)
this.handleClose = this.handleClose.bind(this)
this.state = {
show: true,
}
}
handleClose() {
this.setState({ show: false })
}
handleShow() {
this.setState({ show: true })
}
render() {
return (
<div>
This text is all that renders. And the modal is not rendered, regardless
of whether it is contained within this div.
<Modal show={this.state.show} onHide={this.handleClose}>
<Modal.Header closeButton>
<Modal.Title>Modal heading</Modal.Title>
</Modal.Header>
<Modal.Body>
<h4>Text in a modal</h4>
<p>
Cras mattis consectetur purus sit amet fermentum. Cras justo odio,
dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta
ac consectetur ac, vestibulum at eros.
</p>
</Modal.Body>
<Modal.Footer>
<Button onClick={this.handleClose}>Close</Button>
</Modal.Footer>
</Modal>
</div>
)
}
}
describe('react-bootstrap Modal', () => {
it('works', () => {
mount(<Example />, {
cssFile: 'node_modules/bootstrap/dist/css/bootstrap.min.css',
})
// confirm modal is visible
cy.contains('h4', 'Text in a modal').should('be.visible')
cy.contains('button', 'Close').click()
cy.contains('h4', 'Text in a modal').should('not.exist')
})
})