Attempt to fix Failed to execute 'removeChild' on 'Node'
(#9196)
* Switch tooltips to use React Portals * Remove redundant React key to simplify reconciliation * Fix cleanup and it.each test * Update snapshots due to style order difference
This commit is contained in:
parent
3461573df9
commit
27a7263965
4 changed files with 66 additions and 65 deletions
|
@ -35,6 +35,14 @@ describe('<TooltipTarget />', () => {
|
|||
'data-test-id': 'test',
|
||||
};
|
||||
|
||||
afterEach(() => {
|
||||
// clean up renderer tooltips
|
||||
const wrapper = document.querySelector('.mx_Tooltip_wrapper');
|
||||
while (wrapper?.firstChild) {
|
||||
wrapper.removeChild(wrapper.lastChild);
|
||||
}
|
||||
});
|
||||
|
||||
const getComponent = (props = {}) => {
|
||||
const wrapper = renderIntoDocument<HTMLSpanElement>(
|
||||
// wrap in element so renderIntoDocument can render functional component
|
||||
|
@ -49,31 +57,20 @@ describe('<TooltipTarget />', () => {
|
|||
|
||||
const getVisibleTooltip = () => document.querySelector('.mx_Tooltip.mx_Tooltip_visible');
|
||||
|
||||
afterEach(() => {
|
||||
// clean up visible tooltips
|
||||
const tooltipWrapper = document.querySelector('.mx_Tooltip_wrapper');
|
||||
if (tooltipWrapper) {
|
||||
document.body.removeChild(tooltipWrapper);
|
||||
}
|
||||
});
|
||||
|
||||
it('renders container', () => {
|
||||
const component = getComponent();
|
||||
expect(component).toMatchSnapshot();
|
||||
expect(getVisibleTooltip()).toBeFalsy();
|
||||
});
|
||||
|
||||
for (const alignment in Alignment) {
|
||||
if (isNaN(Number(alignment))) {
|
||||
it(`displays ${alignment} aligned tooltip on mouseover`, () => {
|
||||
const wrapper = getComponent({ alignment: Alignment[alignment] });
|
||||
act(() => {
|
||||
Simulate.mouseOver(wrapper);
|
||||
});
|
||||
expect(getVisibleTooltip()).toMatchSnapshot();
|
||||
});
|
||||
}
|
||||
}
|
||||
const alignmentKeys = Object.keys(Alignment).filter((o: any) => isNaN(o));
|
||||
it.each(alignmentKeys)("displays %s aligned tooltip on mouseover", async (alignment) => {
|
||||
const wrapper = getComponent({ alignment: Alignment[alignment] });
|
||||
act(() => {
|
||||
Simulate.mouseOver(wrapper);
|
||||
});
|
||||
expect(getVisibleTooltip()).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('hides tooltip on mouseleave', () => {
|
||||
const wrapper = getComponent();
|
||||
|
@ -101,8 +98,8 @@ describe('<TooltipTarget />', () => {
|
|||
Simulate.focus(wrapper);
|
||||
});
|
||||
expect(getVisibleTooltip()).toBeTruthy();
|
||||
await act(async () => {
|
||||
await Simulate.blur(wrapper);
|
||||
act(() => {
|
||||
Simulate.blur(wrapper);
|
||||
});
|
||||
expect(getVisibleTooltip()).toBeFalsy();
|
||||
});
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
exports[`<TooltipTarget /> displays Bottom aligned tooltip on mouseover 1`] = `
|
||||
<div
|
||||
class="mx_Tooltip test tooltipClassName mx_Tooltip_visible"
|
||||
style="top: 6px; left: 0px; transform: translate(-50%); display: block;"
|
||||
style="display: block; top: 6px; left: 0px; transform: translate(-50%);"
|
||||
>
|
||||
<div
|
||||
class="mx_Tooltip_chevron"
|
||||
|
@ -15,7 +15,7 @@ exports[`<TooltipTarget /> displays Bottom aligned tooltip on mouseover 1`] = `
|
|||
exports[`<TooltipTarget /> displays InnerBottom aligned tooltip on mouseover 1`] = `
|
||||
<div
|
||||
class="mx_Tooltip test tooltipClassName mx_Tooltip_visible"
|
||||
style="top: -50px; left: 0px; transform: translate(-50%); display: block;"
|
||||
style="display: block; top: -50px; left: 0px; transform: translate(-50%);"
|
||||
>
|
||||
<div
|
||||
class="mx_Tooltip_chevron"
|
||||
|
@ -27,7 +27,7 @@ exports[`<TooltipTarget /> displays InnerBottom aligned tooltip on mouseover 1`]
|
|||
exports[`<TooltipTarget /> displays Left aligned tooltip on mouseover 1`] = `
|
||||
<div
|
||||
class="mx_Tooltip test tooltipClassName mx_Tooltip_visible"
|
||||
style="right: 1030px; top: 0px; transform: translateY(-50%); display: block;"
|
||||
style="display: block; right: 1030px; top: 0px; transform: translateY(-50%);"
|
||||
>
|
||||
<div
|
||||
class="mx_Tooltip_chevron"
|
||||
|
@ -39,7 +39,7 @@ exports[`<TooltipTarget /> displays Left aligned tooltip on mouseover 1`] = `
|
|||
exports[`<TooltipTarget /> displays Natural aligned tooltip on mouseover 1`] = `
|
||||
<div
|
||||
class="mx_Tooltip test tooltipClassName mx_Tooltip_visible"
|
||||
style="left: 6px; top: 0px; transform: translateY(-50%); display: block;"
|
||||
style="display: block; left: 6px; top: 0px; transform: translateY(-50%);"
|
||||
>
|
||||
<div
|
||||
class="mx_Tooltip_chevron"
|
||||
|
@ -51,7 +51,7 @@ exports[`<TooltipTarget /> displays Natural aligned tooltip on mouseover 1`] = `
|
|||
exports[`<TooltipTarget /> displays Right aligned tooltip on mouseover 1`] = `
|
||||
<div
|
||||
class="mx_Tooltip test tooltipClassName mx_Tooltip_visible"
|
||||
style="left: 6px; top: 0px; transform: translateY(-50%); display: block;"
|
||||
style="display: block; left: 6px; top: 0px; transform: translateY(-50%);"
|
||||
>
|
||||
<div
|
||||
class="mx_Tooltip_chevron"
|
||||
|
@ -63,7 +63,7 @@ exports[`<TooltipTarget /> displays Right aligned tooltip on mouseover 1`] = `
|
|||
exports[`<TooltipTarget /> displays Top aligned tooltip on mouseover 1`] = `
|
||||
<div
|
||||
class="mx_Tooltip test tooltipClassName mx_Tooltip_visible"
|
||||
style="top: -6px; left: 0px; transform: translate(-50%, -100%); display: block;"
|
||||
style="display: block; top: -6px; left: 0px; transform: translate(-50%, -100%);"
|
||||
>
|
||||
<div
|
||||
class="mx_Tooltip_chevron"
|
||||
|
@ -75,7 +75,7 @@ exports[`<TooltipTarget /> displays Top aligned tooltip on mouseover 1`] = `
|
|||
exports[`<TooltipTarget /> displays TopRight aligned tooltip on mouseover 1`] = `
|
||||
<div
|
||||
class="mx_Tooltip test tooltipClassName mx_Tooltip_visible"
|
||||
style="top: -6px; right: 1024px; transform: translateY(-100%); display: block;"
|
||||
style="display: block; top: -6px; right: 1024px; transform: translateY(-100%);"
|
||||
>
|
||||
<div
|
||||
class="mx_Tooltip_chevron"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue