|
23 | 23 | */ |
24 | 24 | import React from 'react' |
25 | 25 | import 'cypress-real-events' |
| 26 | +import { useState } from 'react' |
26 | 27 |
|
27 | | -import { Tooltip } from '../../packages/ui' |
| 28 | +import { Tooltip, Modal, Button, CloseButton } from '@instructure/ui' |
28 | 29 | import '../support/component' |
29 | 30 |
|
30 | 31 | describe('<Tooltip/>', () => { |
@@ -131,4 +132,64 @@ describe('<Tooltip/>', () => { |
131 | 132 | cy.contains('Hello').should('not.be.visible') |
132 | 133 | cy.wrap(onHideContent).should('have.been.calledOnce') |
133 | 134 | }) |
| 135 | + |
| 136 | + it('should not close parent Modal with shouldCloseOnDocumentClick when Tooltip is clicked on', async () => { |
| 137 | + const TestModal = () => { |
| 138 | + const [open, setOpen] = useState(false) |
| 139 | + |
| 140 | + return ( |
| 141 | + <div> |
| 142 | + <Button |
| 143 | + onClick={() => { |
| 144 | + setOpen(true) |
| 145 | + }} |
| 146 | + > |
| 147 | + Open the Modal |
| 148 | + </Button> |
| 149 | + <Modal |
| 150 | + label="modal" |
| 151 | + open={open} |
| 152 | + onDismiss={() => { |
| 153 | + setOpen(false) |
| 154 | + }} |
| 155 | + shouldCloseOnDocumentClick |
| 156 | + > |
| 157 | + <CloseButton |
| 158 | + screenReaderLabel="Close" |
| 159 | + onClick={() => { |
| 160 | + setOpen(false) |
| 161 | + }} |
| 162 | + /> |
| 163 | + <Tooltip renderTip="Tooltip!"> |
| 164 | + <Button data-testid="trigger">Hello</Button> |
| 165 | + </Tooltip> |
| 166 | + </Modal> |
| 167 | + </div> |
| 168 | + ) |
| 169 | + } |
| 170 | + cy.mount(<TestModal />) |
| 171 | + |
| 172 | + cy.contains('Open the Modal').click() |
| 173 | + |
| 174 | + cy.get('[data-testid="trigger"]').then(($trigger) => { |
| 175 | + const tooltipId = $trigger.attr('data-position-target') |
| 176 | + const tooltip = `span[data-position-content="${tooltipId}"]` |
| 177 | + |
| 178 | + cy.get(tooltip).should('not.be.visible') |
| 179 | + |
| 180 | + cy.get('[data-testid="trigger"]') |
| 181 | + .realHover() |
| 182 | + .then(() => { |
| 183 | + cy.get(tooltip).should('be.visible') |
| 184 | + }) |
| 185 | + |
| 186 | + cy.get(tooltip) |
| 187 | + .realClick() |
| 188 | + .wait(500) |
| 189 | + .then(() => { |
| 190 | + cy.get(tooltip).should('be.visible') |
| 191 | + cy.get('[role="dialog"]').should('be.visible') |
| 192 | + }) |
| 193 | + }) |
| 194 | + }) |
134 | 195 | }) |
0 commit comments