@nova-ui/bits
Version:
SolarWinds Nova Framework
94 lines • 5.91 kB
JavaScript
"use strict";
// © 2022 SolarWinds Worldwide, LLC. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
Object.defineProperty(exports, "__esModule", { value: true });
exports.PopoverAtom = void 0;
const tslib_1 = require("tslib");
const protractor_1 = require("protractor");
const atom_1 = require("../../atom");
class PopoverAtom extends atom_1.Atom {
constructor(root) {
super(root);
this.root = root;
this.modalBackdrop = PopoverAtom.backdrop;
this.containerAnimationInProgress = (0, protractor_1.$)("div.nui-popover-container-animation.ng-animating");
this.togglePopover = () => tslib_1.__awaiter(this, void 0, void 0, function* () {
const wasDisplayed = yield this.isPopoverDisplayed();
const hasBackdrop = (yield this.modalBackdrop.isPresent()) &&
(yield this.modalBackdrop.isDisplayed());
hasBackdrop
? yield this.modalBackdrop.click()
: yield this.clickTarget();
return wasDisplayed ? this.waitForClosed() : this.waitForOpen();
});
this.open = () => tslib_1.__awaiter(this, void 0, void 0, function* () {
if (yield this.isPopoverDisplayed()) {
return;
}
yield this.clickTarget();
return this.waitForOpen();
});
this.openByHover = () => tslib_1.__awaiter(this, void 0, void 0, function* () {
if (yield this.isPopoverDisplayed()) {
return;
}
yield this.hover();
return this.waitForOpen();
});
this.closeModal = () => tslib_1.__awaiter(this, void 0, void 0, function* () {
yield this.modalBackdrop.click();
return this.waitForClosed();
});
this.waitForOpen = (timeout = 1000) => tslib_1.__awaiter(this, void 0, void 0, function* () {
const errorMessage = "Popover failed to open";
yield protractor_1.browser.wait(protractor_1.ExpectedConditions.visibilityOf(this.getPopoverBody()), timeout, errorMessage);
return protractor_1.browser.wait(protractor_1.ExpectedConditions.stalenessOf(this.containerAnimationInProgress), timeout, errorMessage);
});
this.waitForClosed = (timeout = 1000) => tslib_1.__awaiter(this, void 0, void 0, function* () {
return protractor_1.browser.wait(protractor_1.ExpectedConditions.stalenessOf(this.getPopoverBody()), timeout, "Popover failed to close");
});
this.isPopoverDisplayed = () => tslib_1.__awaiter(this, void 0, void 0, function* () { return this.getPopoverBody().isPresent(); });
this.getTitle = () => (0, protractor_1.$)(".nui-popover-container__title");
this.getTitleText = () => tslib_1.__awaiter(this, void 0, void 0, function* () { return (0, protractor_1.$)(".nui-popover-container__title").getText(); });
this.isDisplayedRight = () => tslib_1.__awaiter(this, void 0, void 0, function* () { return this.bodyHasClass("nui-popover-container--right"); });
this.isDisplayedLeft = () => tslib_1.__awaiter(this, void 0, void 0, function* () { return this.bodyHasClass("nui-popover-container--left"); });
this.isDisplayedTop = () => tslib_1.__awaiter(this, void 0, void 0, function* () { return this.bodyHasClass("nui-popover-container--top"); });
this.isDisplayedBottom = () => tslib_1.__awaiter(this, void 0, void 0, function* () { return this.bodyHasClass("nui-popover-container--bottom"); });
this.clickTarget = () => tslib_1.__awaiter(this, void 0, void 0, function* () { return this.root.click(); });
/*
!!! WARNING !!!
As popovers are attached to body by default we should use popoverModalId everywhere!
Another way is to introduce custom way to identify popover by trigger (like custom attribute),
so atom will be operating with popover it is responsible for.
Right now we are taking first available .nui-popover-container from the dom and asume that it is the thing we were looking for.
Or taking an element inside of content that is completely different from .nui-popover-container.
That is why we need to call this function every time.
*/
this.getPopoverBody = () => this.popoverModalId
? (0, protractor_1.$)(`#${this.popoverModalId}`)
: (0, protractor_1.$)(".nui-popover-container");
this.bodyHasClass = (className) => tslib_1.__awaiter(this, void 0, void 0, function* () { return atom_1.Atom.hasClass(this.getPopoverBody(), className); });
}
}
exports.PopoverAtom = PopoverAtom;
PopoverAtom.CSS_CLASS = "nui-popover";
PopoverAtom.animationDelay = 200;
PopoverAtom.backdrop = (0, protractor_1.$)(".cdk-overlay-backdrop");
//# sourceMappingURL=popover.atom.js.map