|
22 | 22 | * SOFTWARE. |
23 | 23 | */ |
24 | 24 | import React, { useState } from 'react' |
25 | | -import { Modal, View } from '../../packages/ui' |
| 25 | +import { Modal, View, Button } from '@instructure/ui' |
| 26 | +import 'cypress-real-events' |
26 | 27 |
|
27 | 28 | import '../support/component' |
28 | 29 |
|
@@ -105,4 +106,69 @@ describe('<Modal/>', () => { |
105 | 106 | cy.get('body').click(0, 0) |
106 | 107 | cy.wrap(handleDismissSpy).should('have.been.calledOnceWith', 1) |
107 | 108 | }) |
| 109 | + |
| 110 | + it('should not close when button is clicked to rerender content', () => { |
| 111 | + const TestModal = () => { |
| 112 | + const [isOpen, setIsOpen] = useState(false) |
| 113 | + const [state, setState] = useState({ |
| 114 | + content: |
| 115 | + 'This content should change by clicking on the Change content button', |
| 116 | + isButtonVisible: true |
| 117 | + }) |
| 118 | + |
| 119 | + return ( |
| 120 | + <div> |
| 121 | + <Button onClick={() => setIsOpen(true)}>Open the Modal</Button> |
| 122 | + |
| 123 | + {isOpen && ( |
| 124 | + <Modal |
| 125 | + label="label" |
| 126 | + open |
| 127 | + onDismiss={() => setIsOpen(false)} |
| 128 | + shouldCloseOnDocumentClick |
| 129 | + > |
| 130 | + <Modal.Body> |
| 131 | + <div data-testid="modal-content">{state.content}</div> |
| 132 | + {state.isButtonVisible && ( |
| 133 | + <Button |
| 134 | + onClick={() => |
| 135 | + setState({ |
| 136 | + content: 'The content has changed!', |
| 137 | + isButtonVisible: false |
| 138 | + }) |
| 139 | + } |
| 140 | + data-testid="change-content-button" |
| 141 | + > |
| 142 | + Change content |
| 143 | + </Button> |
| 144 | + )} |
| 145 | + <Button |
| 146 | + data-testid="close-button" |
| 147 | + onClick={() => setIsOpen(false)} |
| 148 | + > |
| 149 | + Close |
| 150 | + </Button> |
| 151 | + </Modal.Body> |
| 152 | + </Modal> |
| 153 | + )} |
| 154 | + </div> |
| 155 | + ) |
| 156 | + } |
| 157 | + |
| 158 | + cy.mount(<TestModal />) |
| 159 | + |
| 160 | + cy.contains('Open the Modal').realClick() |
| 161 | + |
| 162 | + cy.get('[data-testid="modal-content"]').should('be.visible') |
| 163 | + |
| 164 | + cy.get('[data-testid="change-content-button"]') |
| 165 | + .realClick() |
| 166 | + .then(() => cy.get('[data-testid="modal-content"]').should('be.visible')) |
| 167 | + |
| 168 | + cy.get('[data-testid="close-button"]').should('be.visible') |
| 169 | + |
| 170 | + cy.get('[data-testid="close-button"]').realClick() |
| 171 | + |
| 172 | + cy.get('[data-testid="modal-content"]').should('not.exist') |
| 173 | + }) |
108 | 174 | }) |
0 commit comments