Add tests to Cypress (#25958)

Signed-off-by: Alfredo Moises Boullosa <aboullos@redhat.com>
This commit is contained in:
Aboullos 2024-01-10 16:26:13 +01:00 committed by GitHub
parent 4be4212dca
commit 583d31bf3e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 62 additions and 24 deletions

View file

@ -77,6 +77,8 @@ describe("Client Scopes test", () => {
it("should filter item by name", () => { it("should filter item by name", () => {
const itemName = clientScopeName + 0; const itemName = clientScopeName + 0;
listingPage listingPage
.searchItem("", false)
.itemsEqualTo(10)
.searchItem(itemName, false) .searchItem(itemName, false)
.itemsEqualTo(1) .itemsEqualTo(1)
.itemExist(itemName, true); .itemExist(itemName, true);
@ -269,11 +271,15 @@ describe("Client Scopes test", () => {
sidebarPage.waitForPageLoad(); sidebarPage.waitForPageLoad();
listingPage.goToCreateItem(); listingPage.goToCreateItem();
createClientScopePage.save_is_disabled(true);
createClientScopePage.fillClientScopeData("address").save(); createClientScopePage.fillClientScopeData("address").save();
masthead.checkNotificationMessage( masthead.checkNotificationMessage(
"Could not create client scope: 'Client Scope address already exists'", "Could not create client scope: 'Client Scope address already exists'",
); );
createClientScopePage.fillClientScopeData("");
createClientScopePage.save_is_disabled(true);
}); });
it("hides 'consent text' field when 'display consent' switch is disabled", () => { it("hides 'consent text' field when 'display consent' switch is disabled", () => {

View file

@ -275,34 +275,34 @@ describe("Clients test", () => {
.should("have.length.gt", 0); .should("have.length.gt", 0);
}); });
it("check generated access token when user is not selected", () => { it("check generated id token and user info", () => {
commonPage.tableToolbarUtils().searchItem(clientName); commonPage.tableToolbarUtils().searchItem(clientName);
commonPage.tableUtils().clickRowItemLink(clientName); commonPage.tableUtils().clickRowItemLink(clientName);
clientDetailsPage.goToClientScopesEvaluateTab(); clientDetailsPage.goToClientScopesEvaluateTab();
clientDetailsPage.goToClientScopesEvaluateGeneratedAccessTokenTab();
cy.get("div#generatedAccessToken").contains("No generated access token"); cy.get("div#generatedAccessToken").contains("No generated access token");
});
it("check generated id token when user is not selected", () => {
commonPage.tableToolbarUtils().searchItem(clientName);
commonPage.tableUtils().clickRowItemLink(clientName);
clientDetailsPage.goToClientScopesEvaluateTab();
clientDetailsPage.goToClientScopesEvaluateGeneratedIdTokenTab(); clientDetailsPage.goToClientScopesEvaluateGeneratedIdTokenTab();
cy.get("div#generatedIdToken").contains("No generated id token"); cy.get("div#generatedIdToken").contains("No generated id token");
});
it("check generated user info when user is not selected", () => {
commonPage.tableToolbarUtils().searchItem(clientName);
commonPage.tableUtils().clickRowItemLink(clientName);
clientDetailsPage.goToClientScopesEvaluateTab();
clientDetailsPage.goToClientScopesEvaluateGeneratedUserInfoTab(); clientDetailsPage.goToClientScopesEvaluateGeneratedUserInfoTab();
cy.get("div#generatedUserInfo").contains("No generated user info"); cy.get("div#generatedUserInfo").contains("No generated user info");
cy.get("input#user-select-typeahead").type("admin");
cy.get("li[id*=select-option-] > button:first-child").click();
clientDetailsPage.goToClientScopesEvaluateGeneratedAccessTokenTab();
cy.get("div#generatedAccessToken").contains(
'"preferred_username": "admin"',
);
cy.get("div#generatedAccessToken").contains('"scope": "');
clientDetailsPage.goToClientScopesEvaluateGeneratedIdTokenTab();
cy.get("div#generatedIdToken").contains('"preferred_username": "admin"');
clientDetailsPage.goToClientScopesEvaluateGeneratedUserInfoTab();
cy.get("div#generatedIdToken").contains('"preferred_username": "admin"');
cy.get("div#generatedIdToken").contains('"session_state"');
}); });
}); });

View file

@ -18,11 +18,7 @@ describe("Masthead tests", () => {
it("Go to account console and back to admin console", () => { it("Go to account console and back to admin console", () => {
sidebarPage.waitForPageLoad(); sidebarPage.waitForPageLoad();
masthead.accountManagement(); masthead.accountManagement();
sidebarPage.waitForPageLoad(); cy.url().should("contain", "/realms/master/account/");
cy.get("h1").contains("Welcome to Keycloak account management");
masthead.goToAdminConsole();
sidebarPage.waitForPageLoad();
masthead.checkIsAdminUI();
}); });
it("Sign out reachs to log in screen", () => { it("Sign out reachs to log in screen", () => {

View file

@ -146,9 +146,21 @@ describe("User creation", () => {
it("User attributes test", () => { it("User attributes test", () => {
listingPage.goToItemDetails(itemId); listingPage.goToItemDetails(itemId);
attributesTab.goToAttributesTab().addAttribute("key", "value").save(); attributesTab
.goToAttributesTab()
.addAttribute("key_test", "value_test")
.save();
masthead.checkNotificationMessage("The user has been saved"); masthead.checkNotificationMessage("The user has been saved");
userDetailsPage.goToDetailsTab();
attributesTab
.goToAttributesTab()
.checkAttribute("key_test", true)
.deleteAttribute(0);
userDetailsPage.goToDetailsTab();
attributesTab.goToAttributesTab().checkAttribute("key_test", false);
}); });
it("User attributes with multiple values test", () => { it("User attributes with multiple values test", () => {
@ -168,7 +180,6 @@ describe("User creation", () => {
cy.wait("@save-user").should(({ request, response }) => { cy.wait("@save-user").should(({ request, response }) => {
expect(response?.statusCode).to.equal(204); expect(response?.statusCode).to.equal(204);
expect(request.body.attributes, "response body").deep.equal({ expect(request.body.attributes, "response body").deep.equal({
key: ["value"],
"key-multiple": ["other value"], "key-multiple": ["other value"],
}); });
}); });

View file

@ -26,6 +26,16 @@ export default class AttributesTab {
return this; return this;
} }
public checkAttribute(key: string, exist: boolean) {
cy.findByTestId(this.#keyInput).should((exist ? "" : "not.") + "exist");
if (exist) {
cy.findAllByTestId(this.#keyInput).invoke("val").should("eq", "key_test");
}
return this;
}
public save() { public save() {
cy.findByTestId(this.#saveAttributeBtn).click(); cy.findByTestId(this.#saveAttributeBtn).click();
return this; return this;

View file

@ -100,6 +100,14 @@ export default class CreateClientScopePage extends CommonPage {
return this; return this;
} }
save_is_disabled(value: boolean) {
cy.get(this.saveBtn)
.invoke("attr", "aria-disabled")
.should("eq", value ? "true" : "false");
return this;
}
cancel() { cancel() {
cy.get(this.cancelBtn).click(); cy.get(this.cancelBtn).click();

View file

@ -13,6 +13,7 @@ export default class UserDetailsPage extends PageObject {
lastNameValue: string; lastNameValue: string;
requiredUserActions: RequiredActionAlias[]; requiredUserActions: RequiredActionAlias[];
identityProviderLinksTab: string; identityProviderLinksTab: string;
detailsTab: string;
consentsTab: string; consentsTab: string;
sessionsTab: string; sessionsTab: string;
@ -28,6 +29,7 @@ export default class UserDetailsPage extends PageObject {
this.lastNameValue = "lastname"; this.lastNameValue = "lastname";
this.requiredUserActions = [RequiredActionAlias.UPDATE_PASSWORD]; this.requiredUserActions = [RequiredActionAlias.UPDATE_PASSWORD];
this.identityProviderLinksTab = "identity-provider-links-tab"; this.identityProviderLinksTab = "identity-provider-links-tab";
this.detailsTab = "user-details-tab";
this.consentsTab = "user-consents-tab"; this.consentsTab = "user-consents-tab";
this.sessionsTab = "user-sessions-tab"; this.sessionsTab = "user-sessions-tab";
} }
@ -65,6 +67,11 @@ export default class UserDetailsPage extends PageObject {
return this; return this;
} }
goToDetailsTab() {
cy.findByTestId(this.detailsTab).click();
return this;
}
goToConsentsTab() { goToConsentsTab() {
cy.findByTestId(this.consentsTab).click(); cy.findByTestId(this.consentsTab).click();
return this; return this;