Skip to content

Commit

Permalink
Add tests to Cypress (keycloak#25958)
Browse files Browse the repository at this point in the history
Signed-off-by: Alfredo Moises Boullosa <aboullos@redhat.com>
  • Loading branch information
Aboullos committed Jan 10, 2024
1 parent 4be4212 commit 583d31b
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 24 deletions.
6 changes: 6 additions & 0 deletions js/apps/admin-ui/cypress/e2e/client_scopes_test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ describe("Client Scopes test", () => {
it("should filter item by name", () => {
const itemName = clientScopeName + 0;
listingPage
.searchItem("", false)
.itemsEqualTo(10)
.searchItem(itemName, false)
.itemsEqualTo(1)
.itemExist(itemName, true);
Expand Down Expand Up @@ -269,11 +271,15 @@ describe("Client Scopes test", () => {
sidebarPage.waitForPageLoad();
listingPage.goToCreateItem();

createClientScopePage.save_is_disabled(true);
createClientScopePage.fillClientScopeData("address").save();

masthead.checkNotificationMessage(
"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", () => {
Expand Down
34 changes: 17 additions & 17 deletions js/apps/admin-ui/cypress/e2e/clients_test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,34 +275,34 @@ describe("Clients test", () => {
.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.tableUtils().clickRowItemLink(clientName);

clientDetailsPage.goToClientScopesEvaluateTab();
clientDetailsPage.goToClientScopesEvaluateGeneratedAccessTokenTab();

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();

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();

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"');
});
});

Expand Down
6 changes: 1 addition & 5 deletions js/apps/admin-ui/cypress/e2e/masthead_test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ describe("Masthead tests", () => {
it("Go to account console and back to admin console", () => {
sidebarPage.waitForPageLoad();
masthead.accountManagement();
sidebarPage.waitForPageLoad();
cy.get("h1").contains("Welcome to Keycloak account management");
masthead.goToAdminConsole();
sidebarPage.waitForPageLoad();
masthead.checkIsAdminUI();
cy.url().should("contain", "/realms/master/account/");
});

it("Sign out reachs to log in screen", () => {
Expand Down
15 changes: 13 additions & 2 deletions js/apps/admin-ui/cypress/e2e/users_test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,21 @@ describe("User creation", () => {
it("User attributes test", () => {
listingPage.goToItemDetails(itemId);

attributesTab.goToAttributesTab().addAttribute("key", "value").save();
attributesTab
.goToAttributesTab()
.addAttribute("key_test", "value_test")
.save();

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", () => {
Expand All @@ -168,7 +180,6 @@ describe("User creation", () => {
cy.wait("@save-user").should(({ request, response }) => {
expect(response?.statusCode).to.equal(204);
expect(request.body.attributes, "response body").deep.equal({
key: ["value"],
"key-multiple": ["other value"],
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ export default class AttributesTab {
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() {
cy.findByTestId(this.#saveAttributeBtn).click();
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ export default class CreateClientScopePage extends CommonPage {
return this;
}

save_is_disabled(value: boolean) {
cy.get(this.saveBtn)
.invoke("attr", "aria-disabled")
.should("eq", value ? "true" : "false");

return this;
}

cancel() {
cy.get(this.cancelBtn).click();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default class UserDetailsPage extends PageObject {
lastNameValue: string;
requiredUserActions: RequiredActionAlias[];
identityProviderLinksTab: string;
detailsTab: string;
consentsTab: string;
sessionsTab: string;

Expand All @@ -28,6 +29,7 @@ export default class UserDetailsPage extends PageObject {
this.lastNameValue = "lastname";
this.requiredUserActions = [RequiredActionAlias.UPDATE_PASSWORD];
this.identityProviderLinksTab = "identity-provider-links-tab";
this.detailsTab = "user-details-tab";
this.consentsTab = "user-consents-tab";
this.sessionsTab = "user-sessions-tab";
}
Expand Down Expand Up @@ -65,6 +67,11 @@ export default class UserDetailsPage extends PageObject {
return this;
}

goToDetailsTab() {
cy.findByTestId(this.detailsTab).click();
return this;
}

goToConsentsTab() {
cy.findByTestId(this.consentsTab).click();
return this;
Expand Down

0 comments on commit 583d31b

Please sign in to comment.