keycloak-scim/js/apps/admin-ui/cypress/support/pages/CommonElements.ts
Jon Koops d3c2475041
Upgrade admin and account console to PatternFly 5 (#28196)
Closes #21345
Closes #21344

Signed-off-by: Jon Koops <jonkoops@gmail.com>
Co-authored-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Co-authored-by: Mark Franceschelli <mfrances@redhat.com>
Co-authored-by: Hynek Mlnařík <hmlnarik@redhat.com>
Co-authored-by: Agnieszka Gancarczyk <agancarc@redhat.com>
2024-04-05 16:37:05 +02:00

63 lines
2 KiB
TypeScript

import { trim } from "lodash-es";
export default class CommonElements {
protected parentSelector;
protected primaryBtn;
protected secondaryBtn;
protected secondaryBtnLink;
protected dropdownMenuItem;
protected selectMenuItem;
protected dropdownToggleBtn;
protected dropdownSelectToggleBtn;
protected dropdownSelectToggleItem;
protected tableKebabBtn;
constructor(parentSelector = "") {
this.parentSelector = trim(parentSelector) + " ";
this.primaryBtn = this.parentSelector + ".pf-v5-c-button.pf-m-primary";
this.secondaryBtn = this.parentSelector + ".pf-v5-c-button.pf-m-secondary";
this.secondaryBtnLink = this.parentSelector + ".pf-v5-c-button.pf-m-link";
this.dropdownMenuItem =
this.parentSelector +
".pf-v5-c-dropdown__menu .pf-v5-c-dropdown__menu-item";
this.selectMenuItem =
this.parentSelector + ".pf-v5-c-select__menu .pf-v5-c-select__menu-item";
this.dropdownToggleBtn = this.parentSelector + ".pf-v5-c-select__toggle";
this.tableKebabBtn = this.parentSelector + ".pf-v5-c-dropdown__toggle";
this.dropdownSelectToggleBtn =
this.parentSelector + ".pf-v5-c-select__toggle";
this.dropdownSelectToggleItem =
this.parentSelector + ".pf-v5-c-select__menu > li";
}
clickPrimaryBtn() {
cy.get(this.primaryBtn).click();
return this;
}
clickSecondaryBtn(buttonName: string, force = false) {
cy.get(this.secondaryBtn).contains(buttonName).click({ force: force });
return this;
}
checkIfExists(exist: boolean) {
cy.get(this.parentSelector).should((!exist ? "not." : "") + "exist");
return this;
}
checkElementIsDisabled(
element: Cypress.Chainable<JQuery<HTMLElement>>,
disabled: boolean,
) {
element.then(($btn) => {
if ($btn.hasClass("pf-m-disabled")) {
element.should(
(!disabled ? "not." : "") + "have.class",
"pf-m-disabled",
);
} else {
element.should((!disabled ? "not." : "") + "have.attr", "disabled");
}
});
}
}