Fix realm_test in cypress (#26400)

Signed-off-by: Alfredo Moises Boullosa <aboullos@redhat.com>
This commit is contained in:
Alfredo Moises Boullosa 2024-02-15 12:18:22 +01:00 committed by Hynek Mlnařík
parent f496e46dbb
commit 74e3b97d54
4 changed files with 42 additions and 24 deletions

View file

@ -34,23 +34,20 @@ describe("Realm tests", () => {
),
);
it("should fail creating Master realm", () => {
it("should fail creating duplicated or empty name realm", () => {
sidebarPage.goToCreateRealm();
createRealmPage.createRealm().verifyRealmNameFieldInvalid();
createRealmPage.fillRealmName("master").createRealm();
masthead.checkNotificationMessage(
"Could not create realm Conflict detected. See logs for details",
);
createRealmPage.cancelRealmCreation();
});
it("should fail creating realm with empty name", () => {
sidebarPage.goToCreateRealm();
createRealmPage.createRealm();
createRealmPage.verifyRealmNameFieldInvalid();
});
it("should create Test realm", () => {
sidebarPage.goToCreateRealm();
@ -63,24 +60,27 @@ describe("Realm tests", () => {
masthead.checkNotificationMessage("Realm created successfully");
});
it("should create Test Disabled realm", () => {
it("CRUD test of Disabled realm", () => {
sidebarPage.goToCreateRealm();
sidebarPage.waitForPageLoad();
createRealmPage.fillRealmName(testDisabledName).createRealm();
createRealmPage.disableRealm();
masthead.checkNotificationMessage("Realm created successfully");
});
it("Should cancel deleting Test Disabled realm", () => {
cy.reload();
sidebarPage.goToRealm(testDisabledName).goToRealmSettings();
createRealmPage.disableRealm();
modalUtils.confirmModal();
masthead.checkNotificationMessage("Realm successfully updated");
sidebarPage.goToRealm(testDisabledName).goToRealmSettings();
realmSettings.clickActionMenu();
cy.findByText("Delete").click();
modalUtils.cancelModal();
});
it("Should delete Test Disabled realm", () => {
cy.reload();
sidebarPage.waitForPageLoad();
sidebarPage.goToRealm(testDisabledName).goToRealmSettings();
@ -90,7 +90,7 @@ describe("Realm tests", () => {
masthead.checkNotificationMessage("The realm has been deleted");
// Show current realms
sidebarPage.showCurrentRealms(2);
sidebarPage.realmExists("Test-Disabled", false);
});
it("should create realm from new a realm", () => {

View file

@ -2,7 +2,7 @@ export default class CreateRealmPage {
#clearBtn = ".pf-c-file-upload__file-select button:last-child";
#modalClearBtn = "clear-button";
#realmNameInput = "#kc-realm-name";
#enabledSwitch = '[for="kc-realm-enabled-switch"] span.pf-c-switch__toggle';
#enabledSwitch = ".pf-c-toolbar .pf-c-switch__toggle";
#createBtn = '.pf-c-form__group:last-child button[type="submit"]';
#cancelBtn = '.pf-c-form__group:last-child button[type="button"]';
#codeEditor = ".pf-c-code-editor__code";

View file

@ -72,8 +72,12 @@ export default class ListingPage extends CommonElements {
}
showNextPageTableItems() {
cy.get(this.#nextPageBtn).scrollIntoView();
cy.get(this.#nextPageBtn).click();
cy.get("body").then(($body) => {
if (!$body.find('[data-testid="' + this.#nextPageBtn + '"]').length) {
cy.get(this.#nextPageBtn).scrollIntoView();
cy.get(this.#nextPageBtn).click();
}
});
return this;
}

View file

@ -17,13 +17,29 @@ export default class SidebarPage extends CommonElements {
#identityProvidersBtn = "#nav-item-identity-providers";
#userFederationBtn = "#nav-item-user-federation";
realmsElements = '[data-testid="realmSelector"] li';
showCurrentRealms(length: number) {
cy.findByTestId(this.#realmsDrpDwn).click();
cy.get('[data-testid="realmSelector"] li').should(
cy.get(this.realmsElements).contains("Loading realms…").should("not.exist");
cy.get(this.realmsElements).should(
"have.length",
length + 1, // account for button
);
cy.findByTestId(this.#realmsDrpDwn).click({ force: true });
return this;
}
realmExists(realmName: string, exists = true) {
cy.findByTestId(this.#realmsDrpDwn).click();
cy.get(this.realmsElements).contains("Loading realms…").should("not.exist");
cy.get(this.realmsElements)
.contains(realmName)
.should((exists ? "" : "not.") + "exist");
cy.findByTestId(this.#realmsDrpDwn).click();
return this;
}
getCurrentRealm() {
@ -32,11 +48,9 @@ export default class SidebarPage extends CommonElements {
goToRealm(realmName: string) {
this.waitForPageLoad();
cy.findByTestId(this.#realmsDrpDwn)
.click()
.parent()
.contains(realmName)
.click();
cy.findByTestId(this.#realmsDrpDwn).click();
cy.get(this.realmsElements).contains("Loading realms…").should("not.exist");
cy.get(this.realmsElements).contains(realmName).click();
this.waitForPageLoad();
return this;