/div>'));
const ctrl = new OverlayController({
...withGlobalTestConfig(),
elementToFocusAfterHide: input,
contentNode,
});
await ctrl.show();
// an outside element has taken over focus
outsideButton.focus();
expect(isActiveElement(outsideButton)).to.be.true;
await ctrl.hide();
expect(isActiveElement(outsideButton)).to.be.true;
});
it('allows to set elementToFocusAfterHide on show', async () => {
const input = /** @type {HTMLElement} */ (await fixture('
'));
const contentNode = /** @type {HTMLElement} */ (
await fixture('
')
);
const ctrl = new OverlayController({
...withGlobalTestConfig(),
viewportConfig: {
placement: 'top-left',
},
contentNode,
});
await ctrl.show(input);
const textarea = /** @type {HTMLTextAreaElement} */ (contentNode.querySelector('textarea'));
textarea.focus();
expect(isActiveElement(textarea)).to.be.true;
await ctrl.hide();
expect(isActiveElement(input)).to.be.true;
});
});
describe('preventsScroll', () => {
it('prevent scrolling the background', async () => {
const ctrl = new OverlayController({
...withGlobalTestConfig(),
preventsScroll: true,
});
await ctrl.show();
expect(Array.from(document.body.classList)).to.contain('overlays-scroll-lock');
await ctrl.hide();
expect(Array.from(document.body.classList)).to.not.contain('overlays-scroll-lock');
});
it('keeps preventing of scrolling when multiple overlays are opened and closed', async () => {
const ctrl0 = new OverlayController({
...withGlobalTestConfig(),
preventsScroll: true,
});
const ctrl1 = new OverlayController({
...withGlobalTestConfig(),
preventsScroll: true,
});
await ctrl0.show();
await ctrl1.show();
await ctrl1.hide();
expect(Array.from(document.body.classList)).to.contain('overlays-scroll-lock');
});
});
describe('hasBackdrop', () => {
it('has no backdrop by default', async () => {
const ctrl = new OverlayController({
...withGlobalTestConfig(),
});
await ctrl.show();
expect(ctrl.backdropNode).to.be.undefined;
});
it('supports a backdrop option', async () => {
const ctrl = new OverlayController({
...withGlobalTestConfig(),
hasBackdrop: false,
});
await ctrl.show();
expect(ctrl.backdropNode).to.be.undefined;
await ctrl.hide();
const controllerWithBackdrop = new OverlayController({
...withGlobalTestConfig(),
hasBackdrop: true,
});
await controllerWithBackdrop.show();
expect(controllerWithBackdrop.backdropNode).to.have.class('overlays__backdrop');
});
it('reenables the backdrop when shown/hidden/shown', async () => {
const ctrl = new OverlayController({
...withGlobalTestConfig(),
hasBackdrop: true,
});
await ctrl.show();
expect(ctrl.backdropNode).to.have.class('overlays__backdrop');
await ctrl.hide();
await ctrl.show();
expect(ctrl.backdropNode).to.have.class('overlays__backdrop');
});
it('adds and stacks backdrops if .hasBackdrop is enabled', async () => {
const ctrl0 = new OverlayController({
...withGlobalTestConfig(),
hasBackdrop: true,
});
await ctrl0.show();
expect(ctrl0.backdropNode).to.have.class('overlays__backdrop');
const ctrl1 = new OverlayController({
...withGlobalTestConfig(),
hasBackdrop: false,
});
await ctrl1.show();
expect(ctrl0.backdropNode).to.have.class('overlays__backdrop');
expect(ctrl1.backdropNode).to.be.undefined;
const ctrl2 = new OverlayController({
...withGlobalTestConfig(),
hasBackdrop: true,
});
await ctrl2.show();
expect(ctrl0.backdropNode).to.have.class('overlays__backdrop');
expect(ctrl1.backdropNode).to.be.undefined;
expect(ctrl2.backdropNode).to.have.class('overlays__backdrop');
});
});
describe('locally placed overlay with hasBackdrop', () => {
it('has no backdrop by default', async () => {
const ctrl = new OverlayController({
...withLocalTestConfig(),
});
await ctrl.show();
expect(ctrl.backdropNode).to.be.undefined;
});
it('supports a backdrop option', async () => {
const ctrl = new OverlayController({
...withLocalTestConfig(),
hasBackdrop: false,
});
await ctrl.show();
expect(ctrl.backdropNode).to.be.undefined;
await ctrl.hide();
const backdropNode = document.createElement('div');
backdropNode.classList.add('custom-backdrop');
const controllerWithBackdrop = new OverlayController({
...withLocalTestConfig(),
hasBackdrop: true,
backdropNode,
});
await controllerWithBackdrop.show();
expect(controllerWithBackdrop.backdropNode).to.have.class('custom-backdrop');
});
it('reenables the backdrop when shown/hidden/shown', async () => {
const backdropNode = document.createElement('div');
backdropNode.classList.add('custom-backdrop');
const ctrl = new OverlayController({
...withLocalTestConfig(),
hasBackdrop: true,
backdropNode,
});
await ctrl.show();
expect(ctrl.backdropNode).to.have.class('custom-backdrop');
await ctrl.hide();
await ctrl.show();
expect(ctrl.backdropNode).to.have.class('custom-backdrop');
});
it('adds and stacks backdrops if .hasBackdrop is enabled', async () => {
const backdropNode = document.createElement('div');
backdropNode.classList.add('custom-backdrop-zero');
const ctrl0 = new OverlayController({
...withLocalTestConfig(),
hasBackdrop: true,
backdropNode,
});
await ctrl0.show();
expect(ctrl0.backdropNode).to.have.class('custom-backdrop-zero');
const ctrl1 = new OverlayController({
...withLocalTestConfig(),
hasBackdrop: false,
});
await ctrl1.show();
expect(ctrl0.backdropNode).to.have.class('custom-backdrop-zero');
expect(ctrl1.backdropNode).to.be.undefined;
const anotherBackdropNode = document.createElement('div');
anotherBackdropNode.classList.add('custom-backdrop-two');
const ctrl2 = new OverlayController({
...withLocalTestConfig(),
hasBackdrop: true,
backdropNode: anotherBackdropNode,
});
await ctrl2.show();
expect(ctrl0.backdropNode).to.have.class('custom-backdrop-zero');
expect(ctrl1.backdropNode).to.be.undefined;
expect(ctrl2.backdropNode).to.have.class('custom-backdrop-two');
});
});
describe('isBlocking', () => {
it('prevents showing of other overlays', async () => {
const ctrl0 = new OverlayController({
...withGlobalTestConfig(),
isBlocking: false,
});
const ctrl1 = new OverlayController({
...withGlobalTestConfig(),
isBlocking: false,
});
const ctrl2 = new OverlayController({
...withGlobalTestConfig(),
isBlocking: true,
});
const ctrl3 = new OverlayController({
...withGlobalTestConfig(),
isBlocking: false,
});
await ctrl0.show();
await ctrl1.show();
await ctrl2.show(); // blocking
expect(ctrl0.__wrappingDialogNode).to.not.be.displayed;
expect(ctrl1.__wrappingDialogNode).to.not.be.displayed;
expect(ctrl2.__wrappingDialogNode).to.be.displayed;
await ctrl3.show();
await ctrl3._showComplete;
expect(ctrl3.__wrappingDialogNode).to.be.displayed;
await ctrl2.hide();
await ctrl2._hideComplete;
expect(ctrl0.__wrappingDialogNode).to.be.displayed;
expect(ctrl1.__wrappingDialogNode).to.be.displayed;
await ctrl2.show(); // blocking
expect(ctrl0.__wrappingDialogNode).to.not.be.displayed;
expect(ctrl1.__wrappingDialogNode).to.not.be.displayed;
expect(ctrl2.__wrappingDialogNode).to.be.displayed;
expect(ctrl3.__wrappingDialogNode).to.not.be.displayed;
});
it('keeps backdrop status when used in combination with blocking', async () => {
const ctrl0 = new OverlayController({
...withGlobalTestConfig(),
isBlocking: false,
hasBackdrop: true,
});
await ctrl0.show();
const ctrl1 = new OverlayController({
...withGlobalTestConfig(),
isBlocking: false,
hasBackdrop: true,
});
await ctrl1.show();
await ctrl1.hide();
expect(ctrl0.hasActiveBackdrop).to.be.true;
expect(ctrl1.hasActiveBackdrop).to.be.false;
await ctrl1.show();
expect(ctrl0.hasActiveBackdrop).to.be.true;
expect(ctrl1.hasActiveBackdrop).to.be.true;
});
});
});
describe('Show / Hide / Toggle', () => {
it('has .isShown which defaults to false', async () => {
const ctrl = new OverlayController({
...withGlobalTestConfig(),
});
expect(ctrl.isShown).to.be.false;
});
it('has async show() which shows the overlay', async () => {
const ctrl = new OverlayController({
...withGlobalTestConfig(),
});
await ctrl.show();
expect(ctrl.isShown).to.be.true;
expect(ctrl.show()).to.be.instanceOf(Promise);
});
it('has async hide() which hides the overlay', async () => {
const ctrl = new OverlayController({
...withGlobalTestConfig(),
});
await ctrl.hide();
expect(ctrl.isShown).to.be.false;
expect(ctrl.hide()).to.be.instanceOf(Promise);
});
it('fires "show" event once overlay becomes shown', async () => {
const showSpy = sinon.spy();
const ctrl = new OverlayController({
...withGlobalTestConfig(),
});
ctrl.addEventListener('show', showSpy);
await ctrl.show();
expect(showSpy.callCount).to.equal(1);
await ctrl.show();
expect(showSpy.callCount).to.equal(1);
});
it('fires "before-show" event right before overlay becomes shown', async () => {
const ctrl = new OverlayController({
...withGlobalTestConfig(),
});
const eventSpy = sinon.spy();
ctrl.addEventListener('before-show', eventSpy);
ctrl.addEventListener('show', eventSpy);
await ctrl.show();
expect(eventSpy.getCall(0).args[0].type).to.equal('before-show');
expect(eventSpy.getCall(1).args[0].type).to.equal('show');
expect(eventSpy.callCount).to.equal(2);
await ctrl.show();
expect(eventSpy.callCount).to.equal(2);
});
it('fires "hide" event once overlay becomes hidden', async () => {
const hideSpy = sinon.spy();
const ctrl = new OverlayController({
...withGlobalTestConfig(),
});
ctrl.addEventListener('hide', hideSpy);
await ctrl.show();
await ctrl.hide();
expect(hideSpy.callCount).to.equal(1);
await ctrl.hide();
expect(hideSpy.callCount).to.equal(1);
});
it('fires "before-hide" event right before overlay becomes hidden', async () => {
const ctrl = new OverlayController({
...withGlobalTestConfig(),
});
const eventSpy = sinon.spy();
ctrl.addEventListener('before-hide', eventSpy);
ctrl.addEventListener('hide', eventSpy);
await ctrl.show();
await ctrl.hide();
expect(eventSpy.getCall(0).args[0].type).to.equal('before-hide');
expect(eventSpy.getCall(1).args[0].type).to.equal('hide');
expect(eventSpy.callCount).to.equal(2);
await ctrl.hide();
expect(eventSpy.callCount).to.equal(2);
});
it('can be toggled', async () => {
const ctrl = new OverlayController({
...withGlobalTestConfig(),
});
await ctrl.toggle();
expect(ctrl.isShown).to.be.true;
await ctrl.toggle();
expect(ctrl.isShown).to.be.false;
await ctrl.toggle();
expect(ctrl.isShown).to.be.true;
// check for hide
expect(ctrl.toggle()).to.be.instanceOf(Promise);
// check for show
expect(ctrl.toggle()).to.be.instanceOf(Promise);
});
it('makes sure the latest shown overlay is visible', async () => {
const ctrl0 = new OverlayController({
...withGlobalTestConfig(),
});
const ctrl1 = new OverlayController({
...withGlobalTestConfig(),
});
await ctrl0.show();
const rect = ctrl0.contentNode.getBoundingClientRect();
const getTopEl = () => document.elementFromPoint(Math.ceil(rect.left), Math.ceil(rect.top));
await ctrl0.show();
expect(getTopEl()).to.equal(ctrl0.contentNode);
await ctrl1.show();
expect(getTopEl()).to.equal(ctrl1.contentNode);
await ctrl0.show();
expect(getTopEl()).to.equal(ctrl0.contentNode);
});
it('awaits a "transitionHide" hook before hiding for real', done => {
const ctrl = new OverlayController({
...withGlobalTestConfig(),
});
ctrl.show();
/** @type {{ (): void; (value?: void | PromiseLike
| undefined): void; }} */
let hideTransitionFinished;
ctrl.transitionHide = () =>
new Promise(resolve => {
hideTransitionFinished = resolve;
});
ctrl.hide();
expect(getComputedStyle(ctrl.content).display).to.equal('block');
setTimeout(() => {
hideTransitionFinished();
setTimeout(() => {
expect(getComputedStyle(ctrl.content).display).to.equal('none');
done();
}, 0);
}, 0);
});
it('awaits a "transitionShow" hook before finishing the show method', done => {
const ctrl = new OverlayController({
...withGlobalTestConfig(),
});
/** @type {{ (): void; (value?: void | PromiseLike | undefined): void; }} */
let showTransitionFinished;
ctrl.transitionShow = () =>
new Promise(resolve => {
showTransitionFinished = resolve;
});
ctrl.show();
let showIsDone = false;
/** @type {Promise} */ (ctrl._showComplete).then(() => {
showIsDone = true;
});
expect(showIsDone).to.be.false;
setTimeout(() => {
showTransitionFinished();
setTimeout(() => {
expect(showIsDone).to.be.true;
done();
}, 0);
}, 0);
});
});
describe('Update Configuration', () => {
it('reinitializes content', async () => {
const ctrl = new OverlayController({
...withLocalTestConfig(),
contentNode: /** @type {HTMLElement} */ (await fixture(html`content1
`)),
});
await ctrl.show(); // Popper adds inline styles
expect(ctrl.content.style.transform).not.to.be.undefined;
expect(ctrl.contentNode.textContent).to.include('content1');
ctrl.updateConfig({
placementMode: 'local',
contentNode: /** @type {HTMLElement} */ (await fixture(html`content2
`)),
});
expect(ctrl.contentNode.textContent).to.include('content2');
});
it('respects the initial config provided to new OverlayController(initialConfig)', async () => {
const contentNode = /** @type {HTMLElement} */ (fixtureSync(html`my content
`));
const ctrl = new OverlayController({
// This is the shared config
placementMode: 'global',
handlesAccessibility: true,
contentNode,
});
ctrl.updateConfig({
// This is the added config
placementMode: 'local',
hidesOnEsc: true,
});
expect(ctrl.placementMode).to.equal('local');
expect(ctrl.handlesAccessibility).to.equal(true);
expect(ctrl.contentNode).to.equal(contentNode);
});
// Currently not working, enable again when we fix updateConfig
it.skip('allows for updating viewport config placement only, while keeping the content shown', async () => {
const contentNode = /** @type {HTMLElement} */ (fixtureSync(html`my content
`));
const ctrl = new OverlayController({
// This is the shared config
placementMode: 'global',
handlesAccessibility: true,
contentNode,
});
ctrl.show();
expect(ctrl.contentWrapperNode.classList.contains('overlays__overlay-container--center'));
expect(ctrl.isShown).to.be.true;
ctrl.updateConfig({ viewportConfig: { placement: 'top-right' } });
expect(ctrl.contentWrapperNode.classList.contains('overlays__overlay-container--top-right'));
expect(ctrl.isShown).to.be.true;
});
it('disables backdrop when switching to hasBackrop "false"', async () => {
const ctrl = new OverlayController({
...withLocalTestConfig(),
contentNode: /** @type {HTMLElement} */ (await fixture(html`content1
`)),
hasBackdrop: true,
});
await ctrl.show(); // Popper adds inline styles
expect(ctrl.backdropNode).not.to.be.undefined;
expect(Array.from(ctrl.backdropNode.classList)).to.include('overlays__backdrop--visible');
ctrl.updateConfig({
hasBackdrop: false,
});
expect(Array.from(ctrl.backdropNode.classList)).to.not.include('overlays__backdrop--visible');
});
});
describe('Accessibility', () => {
it('synchronizes [aria-expanded] on invoker', async () => {
const invokerNode = /** @type {HTMLElement} */ (
await fixture('invoker
')
);
const ctrl = new OverlayController({
...withLocalTestConfig(),
handlesAccessibility: true,
invokerNode,
});
expect(ctrl.invokerNode?.getAttribute('aria-expanded')).to.equal('false');
await ctrl.show();
expect(ctrl.invokerNode?.getAttribute('aria-expanded')).to.equal('true');
await ctrl.hide();
expect(ctrl.invokerNode?.getAttribute('aria-expanded')).to.equal('false');
});
it('does not synchronize [aria-expanded] on invoker when the overlay is modal', async () => {
const invokerNode = /** @type {HTMLElement} */ (
await fixture('invoker
')
);
const ctrl = new OverlayController({
...withLocalTestConfig(),
trapsKeyboardFocus: true,
handlesAccessibility: true,
invokerNode,
});
expect(ctrl.invokerNode?.getAttribute('aria-expanded')).to.equal(null);
await ctrl.show();
expect(ctrl.invokerNode?.getAttribute('aria-expanded')).to.equal(null);
await ctrl.hide();
expect(ctrl.invokerNode?.getAttribute('aria-expanded')).to.equal(null);
});
it('creates unique id for content', async () => {
const ctrl = new OverlayController({
...withLocalTestConfig(),
handlesAccessibility: true,
});
const { contentId } = getProtectedMembers(ctrl);
expect(ctrl.contentNode.id).to.contain(contentId);
});
it('preserves content id when present', async () => {
const contentNode = /** @type {HTMLElement} */ (
await fixture('content
')
);
const ctrl = new OverlayController({
...withLocalTestConfig(),
handlesAccessibility: true,
contentNode,
});
expect(ctrl.contentNode.id).to.contain('preserved');
});
it('adds [role=dialog] on content', async () => {
const invokerNode = /** @type {HTMLElement} */ (
await fixture('invoker
')
);
const ctrl = new OverlayController({
...withLocalTestConfig(),
handlesAccessibility: true,
invokerNode,
});
expect(ctrl.contentNode.getAttribute('role')).to.equal('dialog');
});
it('preserves [role] on content when present', async () => {
const invokerNode = /** @type {HTMLElement} */ (
await fixture('invoker
')
);
const contentNode = /** @type {HTMLElement} */ (
await fixture('invoker
')
);
const ctrl = new OverlayController({
...withLocalTestConfig(),
handlesAccessibility: true,
invokerNode,
contentNode,
});
expect(ctrl.contentNode.getAttribute('role')).to.equal('menu');
});
it('allows to not provide an invokerNode', async () => {
let properlyInstantiated = false;
try {
new OverlayController({
...withLocalTestConfig(),
handlesAccessibility: true,
invokerNode: undefined,
});
properlyInstantiated = true;
} catch (e) {
throw new Error(/** @type {Error} */ (e).message);
}
expect(properlyInstantiated).to.be.true;
});
// TODO: check if we covered all functionality. "Inertness" should be handled by the platform with a modal overlay...
it.skip('adds attributes inert and aria-hidden="true" on all siblings of rootNode if an overlay is shown', async () => {});
it.skip('disables pointer events and selection on inert elements', async () => {});
describe('Alert dialog', () => {
it('sets role="alertdialog" when isAlertDialog is set', async () => {
const invokerNode = /** @type {HTMLElement} */ (
await fixture('invoker
')
);
const ctrl = new OverlayController({
...withLocalTestConfig(),
handlesAccessibility: true,
isAlertDialog: true,
invokerNode,
});
expect(ctrl.contentNode?.getAttribute('role')).to.equal('alertdialog');
});
});
describe('Tooltip', () => {
it('adds [aria-describedby] on invoker', async () => {
const invokerNode = /** @type {HTMLElement} */ (
await fixture('invoker
')
);
const ctrl = new OverlayController({
...withLocalTestConfig(),
handlesAccessibility: true,
isTooltip: true,
invokerNode,
});
const { contentId } = getProtectedMembers(ctrl);
expect(ctrl.invokerNode?.getAttribute('aria-describedby')).to.equal(contentId);
});
it('adds [aria-labelledby] on invoker when invokerRelation is label', async () => {
const invokerNode = /** @type {HTMLElement} */ (
await fixture('invoker
')
);
const ctrl = new OverlayController({
...withLocalTestConfig(),
handlesAccessibility: true,
isTooltip: true,
invokerRelation: 'label',
invokerNode,
});
const { contentId } = getProtectedMembers(ctrl);
expect(ctrl.invokerNode?.getAttribute('aria-describedby')).to.equal(null);
expect(ctrl.invokerNode?.getAttribute('aria-labelledby')).to.equal(contentId);
});
it('adds [role=tooltip] on content', async () => {
const invokerNode = /** @type {HTMLElement} */ (
await fixture('invoker
')
);
const ctrl = new OverlayController({
...withLocalTestConfig(),
handlesAccessibility: true,
isTooltip: true,
invokerNode,
});
expect(ctrl.contentNode.getAttribute('role')).to.equal('tooltip');
});
it('adds tabindex="-1" to the wrappingDialog element', async () => {
const invokerNode = /** @type {HTMLElement} */ (
await fixture('invoker
')
);
const ctrl = new OverlayController({
...withLocalTestConfig(),
handlesAccessibility: true,
isTooltip: true,
invokerNode,
});
expect(ctrl.__wrappingDialogNode?.getAttribute('tabindex')).to.equal('-1');
});
describe('Teardown', () => {
it('restores [role] on dialog content', async () => {
const invokerNode = /** @type {HTMLElement} */ (
await fixture('invoker
')
);
const ctrl = new OverlayController({
...withLocalTestConfig(),
handlesAccessibility: true,
invokerNode,
});
expect(ctrl.contentNode.getAttribute('role')).to.equal('dialog');
ctrl.teardown();
expect(ctrl.contentNode.getAttribute('role')).to.equal(null);
});
it('restores [role] on tooltip content', async () => {
const invokerNode = /** @type {HTMLElement} */ (
await fixture('invoker
')
);
const contentNode = /** @type {HTMLElement} */ (
await fixture('content
')
);
const ctrl = new OverlayController({
...withLocalTestConfig(),
handlesAccessibility: true,
isTooltip: true,
invokerNode,
contentNode,
});
expect(contentNode.getAttribute('role')).to.equal('tooltip');
ctrl.teardown();
expect(contentNode.getAttribute('role')).to.equal('presentation');
});
it('restores [aria-describedby] on content', async () => {
const invokerNode = /** @type {HTMLElement} */ (
await fixture('invoker
')
);
const contentNode = /** @type {HTMLElement} */ (
await fixture('content
')
);
const ctrl = new OverlayController({
...withLocalTestConfig(),
handlesAccessibility: true,
isTooltip: true,
invokerNode,
contentNode,
});
expect(invokerNode.getAttribute('aria-describedby')).to.equal(contentNode.id);
ctrl.teardown();
expect(invokerNode.getAttribute('aria-describedby')).to.equal(null);
});
it('restores [aria-labelledby] on content', async () => {
const invokerNode = /** @type {HTMLElement} */ (
await fixture('invoker
')
);
const contentNode = /** @type {HTMLElement} */ (
await fixture('content
')
);
const ctrl = new OverlayController({
...withLocalTestConfig(),
handlesAccessibility: true,
isTooltip: true,
invokerNode,
contentNode,
invokerRelation: 'label',
});
expect(invokerNode.getAttribute('aria-labelledby')).to.equal(contentNode.id);
ctrl.teardown();
expect(invokerNode.getAttribute('aria-labelledby')).to.equal(null);
});
});
});
});
describe('Exception handling', () => {
it('throws if no .placementMode gets passed on', async () => {
const contentNode = document.createElement('div');
// Ensure the contentNode is connected to DOM
document.body.appendChild(contentNode);
expect(() => {
new OverlayController({
contentNode,
});
}).to.throw('[OverlayController] You need to provide a .placementMode ("global"|"local")');
});
it('throws if invalid .placementMode gets passed on', async () => {
expect(() => {
new OverlayController({
// @ts-ignore
placementMode: 'invalid',
});
}).to.throw(
'[OverlayController] "invalid" is not a valid .placementMode, use ("global"|"local")',
);
});
it('throws if no .contentNode gets passed on', async () => {
expect(() => {
new OverlayController({
placementMode: 'global',
});
}).to.throw('[OverlayController] You need to provide a .contentNode');
});
it('throws if handlesAccessibility is false for a tooltip', async () => {
const contentNode = document.createElement('div');
document.body.appendChild(contentNode);
expect(() => {
new OverlayController({
placementMode: 'local',
contentNode,
isTooltip: true,
handlesAccessibility: false,
});
}).to.throw(
'[OverlayController] .isTooltip only takes effect when .handlesAccessibility is enabled',
);
});
});
describe('run _keepBodySize only with scroll prevention', () => {
/**
* @type {OverlayController}
*/
const overlayControllerNoPrevent = new OverlayController({
...withLocalTestConfig(),
preventsScroll: false,
});
const overlayControllerPreventsScroll = new OverlayController({
...withLocalTestConfig(),
preventsScroll: true,
});
it('should not run with scroll prevention', async () => {
await overlayControllerNoPrevent.show();
expect(overlayControllerNoPrevent.__bodyMarginRightInline).to.equal(undefined);
expect(overlayControllerNoPrevent.__bodyMarginRight).to.equal(undefined);
});
it('should run with scroll prevention', async () => {
await overlayControllerPreventsScroll.show();
expect(overlayControllerPreventsScroll.__bodyMarginRightInline).to.not.equal(undefined);
expect(overlayControllerPreventsScroll.__bodyMarginRight).to.not.equal(undefined);
});
});
});