@nova-ui/bits
Version:
SolarWinds Nova Framework
122 lines • 4.58 kB
JavaScript
// © 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.
import { SelectV2OptionAtom } from "./select-v2-option.atom";
import { Atom } from "../../atom";
import { expect, Helpers } from "../../setup";
import { OverlayAtom } from "../overlay/overlay.atom";
export class BaseSelectV2Atom extends Atom {
static findIn(atomClass, parentLocator, root = true) {
return Atom.findIn(atomClass, parentLocator, root);
}
get popup() {
return Atom.findIn(OverlayAtom);
}
async options() {
let parentLocator;
if (await this.popup.isOpened()) {
parentLocator = Helpers.page.locator("body > .cdk-overlay-container .cdk-overlay-pane");
}
else {
parentLocator = this.getLocator();
}
return Atom.findIn(SelectV2OptionAtom, parentLocator);
}
get input() {
return this.getLocator().locator(".nui-select-v2__value");
}
get getPopupElement() {
return this.popup.getLocator();
}
/**
* Note: Despite its name, this method will only OPEN the dropdown. To toggle it closed, use this
* Atom's "click" method.
*/
async toggle() {
await this.click();
await this.waitForPopup();
}
async getOption(index) {
if (!(await this.popup.isOpened())) {
await this.toggle();
}
return (await this.options()).nth(SelectV2OptionAtom, index);
}
async getFirstOption() {
return this.getOption(0);
}
async getLastOption() {
const count = await (await this.options()).getLocator().count();
return this.getOption(count - 1);
}
async countOptions() {
if (!(await this.popup.isOpened())) {
await this.toggle();
}
return await (await this.options()).getLocator().count();
}
/**
* Note: This method checks whether ANY 'cdk-overlay-pane' on the document body is present
* (not just this dropdown instance). Close any other cdk-overlay-pane instances before invoking this
* method to ensure an accurate return value.
*
* Important: this is a pure state check (no auto-waits). Prefer toBeOpened/toBeClosed in tests.
*/
async isOpened() {
return this.popup.isOpened();
}
async toBeOpened() {
await this.popup.toBeOpened();
}
async toBeClosed() {
await this.popup.toNotBeOpened();
}
async toBeHidden() {
await this.popup.toBeHidden();
}
async getActiveItemsCount() {
return await this.popup.getLocator().locator(".active").count();
}
async type(text) {
await this.click();
return await this.input.fill(text);
}
async isSelectDisabled() {
return await this.toContainClass("disabled");
}
async select(title) {
if (!(await this.popup.isOpened())) {
await this.toggle();
}
// Use Playwright's getByText for exact text match
const optionsLocator = (await this.options()).getLocator();
const exactOption = optionsLocator.getByText(title, { exact: true });
await exactOption.first().click();
}
async waitForPopup() {
await this.popup.toBeVisible();
}
async toBeDisabled() {
await expect(this.getLocator()).toContainClass("disabled");
}
async toBeEnabled() {
await expect(this.getLocator()).not.toContainClass("disabled");
}
}
//# sourceMappingURL=base-select-v2.atom.js.map