-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
STCOM-1335 add
StripesOverlayContext
to Modal, MCL... implement in …
…Popper (#2351) * add StripesOverlayContext to Modal, MCL... implement in Popper * move useOverlayContainer to hooks dir * modify getHookExecutionResults, add tests for useOverlayContainer * don't replace getHookExecutionResults * include tests for null initial results and for refresh() on useOverlayContainer * remove only * just a little more coverage... * STCOM-1335 * fix falsy initial result test * log changes * use isEqual for default HookExecResult comparator * close MCL wrapping div for shortcut keys * rollback, re-wrap in overlayContext, have non-findDOMNode cake and eat it.
- Loading branch information
Showing
10 changed files
with
316 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
import { | ||
describe, | ||
beforeEach, | ||
it, | ||
} from 'mocha'; | ||
import { converge } from '@folio/stripes-testing'; | ||
import { getHookExecutionHarness } from '../../tests/helpers/getHookExecutionResult'; | ||
import useOverlayContainer from '../useOverlayContainer'; | ||
|
||
import { OVERLAY_CONTAINER_ID } from '../../util/consts'; | ||
|
||
const Harness = ({ children }) => ( | ||
<div id="rootChild"> | ||
<div id="OverlayContainer" /> | ||
{children} | ||
</div> | ||
); | ||
|
||
const HarnessWithout = ({ children }) => ( | ||
<div id="rootChild"> | ||
{children} | ||
</div> | ||
); | ||
|
||
// We need to compare the `element` field of the result to discern difference on the re-render. | ||
const areDomNodesEqual = (current, candidate) => { | ||
return current?.element === candidate?.element; | ||
} | ||
|
||
describe('useOverlayContainer', () => { | ||
const overlayElement = () => document.getElementById(OVERLAY_CONTAINER_ID); | ||
let res; | ||
beforeEach(() => { | ||
res = null; | ||
}); | ||
|
||
describe('withoutOverlay fallback to a child of root.', () => { | ||
beforeEach(async () => { | ||
await getHookExecutionHarness( | ||
useOverlayContainer, | ||
[overlayElement()], | ||
HarnessWithout, | ||
(result) => { res = result.element }, | ||
areDomNodesEqual | ||
); | ||
}); | ||
|
||
it('should fallback to child of root element', | ||
() => converge(() => { | ||
if (res.parentNode?.id !== 'root') throw new Error(`expected child of root: ${res.id}`); | ||
})); | ||
}); | ||
|
||
describe('successfully resolving overlay container if it exists...', () => { | ||
beforeEach(async () => { | ||
await getHookExecutionHarness( | ||
useOverlayContainer, | ||
[overlayElement()], | ||
Harness, | ||
(result) => { res = result.element }, | ||
areDomNodesEqual | ||
); | ||
}); | ||
|
||
it('div#OverlayContainer in place, it should return it', | ||
() => converge(() => { | ||
if (res.id !== OVERLAY_CONTAINER_ID) throw new Error(`expected element to fallback to body: ${res.id}`); | ||
})); | ||
}); | ||
|
||
describe('successfully initial null result...', () => { | ||
beforeEach(async () => { | ||
await getHookExecutionHarness( | ||
useOverlayContainer, | ||
[null], | ||
Harness, | ||
(result) => { res = result.element }, | ||
areDomNodesEqual | ||
); | ||
}); | ||
|
||
it('div#OverlayContainer in place, it should return it', | ||
() => converge(() => { | ||
if (res.id !== OVERLAY_CONTAINER_ID) throw new Error(`expected element to fallback to body: ${res.id}`); | ||
})); | ||
}); | ||
|
||
describe('successfully initial result...', () => { | ||
beforeEach(async () => { | ||
await getHookExecutionHarness( | ||
useOverlayContainer, | ||
['true'], | ||
Harness, | ||
(result) => { res = result.element }, | ||
areDomNodesEqual | ||
); | ||
}); | ||
|
||
it('div#OverlayContainer in place, it should return it', | ||
() => converge(() => { | ||
if (res !== 'true') throw new Error('should just return truthy value'); | ||
})); | ||
}); | ||
|
||
describe('falsy initial result...', () => { | ||
beforeEach(async () => { | ||
res = await getHookExecutionHarness( | ||
useOverlayContainer, | ||
[false], | ||
Harness, | ||
(result) => { res = result.element }, | ||
areDomNodesEqual | ||
); | ||
res.refresh(); | ||
}); | ||
|
||
it('div#OverlayContainer in place, it should return it', | ||
() => converge(() => { | ||
if (res.element !== false) throw new Error('should just return false value'); | ||
})); | ||
}); | ||
|
||
describe('refresh', () => { | ||
beforeEach(async () => { | ||
res = await getHookExecutionHarness( | ||
useOverlayContainer, | ||
[null], | ||
Harness, | ||
(result) => { res = result }, | ||
areDomNodesEqual | ||
); | ||
res.refresh(); | ||
}); | ||
|
||
it('div#OverlayContainer in place, it should return it', | ||
() => converge(() => { | ||
if (res.element.id !== OVERLAY_CONTAINER_ID) throw new Error(`expected element to fallback to body: ${res.id}`); | ||
})); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './useOverlayContainer'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.