Skip to content

Commit

Permalink
add user-profile admin-ui test to realm_settings_user_profile_enabled…
Browse files Browse the repository at this point in the history
….spec.ts: "Checks that attribute with select-annotation is displayed and editable when user is created/edited"

- refactor existing tests to use page objects, add new helper methods to page objects and use it in existing tests
- rename CreateUserPage#save() to #create(), and add a new method #update()
- add new test mentioned above
- re-enable test "Checks that required attribute with permissions to view/edit is present and required when user is created"
- stabilize realm_settings_user_profile_enabled.spec.ts by resetting the user-profile to default and resetting the realm attributes to default before each test

Signed-off-by: Daniel Fesenmeyer <[email protected]>
  • Loading branch information
danielFesenmeyer committed Jan 15, 2024
1 parent 94b0e22 commit 37efa89
Show file tree
Hide file tree
Showing 9 changed files with 554 additions and 293 deletions.
484 changes: 252 additions & 232 deletions js/apps/admin-ui/cypress/e2e/realm_settings_user_profile_enabled.spec.ts

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions js/apps/admin-ui/cypress/e2e/users_test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe("User creation", () => {

createUserPage.createUser(itemId);

createUserPage.save();
createUserPage.create();

masthead.checkNotificationMessage("The user has been created");
});
Expand All @@ -95,7 +95,7 @@ describe("User creation", () => {

createUserPage.joinGroups();

createUserPage.save();
createUserPage.create();

masthead.checkNotificationMessage("The user has been created");
});
Expand All @@ -109,7 +109,7 @@ describe("User creation", () => {
createUserPage.createUser(itemIdWithCred);

userDetailsPage.fillUserData();
createUserPage.save();
createUserPage.create();
masthead.checkNotificationMessage("The user has been created");
sidebarPage.waitForPageLoad();

Expand Down Expand Up @@ -493,7 +493,7 @@ describe("User creation", () => {
createUserPage.goToCreateUser();
createUserPage.createUser(a11yUser);
userDetailsPage.fillUserData();
createUserPage.save();
createUserPage.create();
cy.checkA11y();
});

Expand Down
19 changes: 10 additions & 9 deletions js/apps/admin-ui/cypress/support/forms/FormValidation.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
export default class FormValidation {
static assertRequired(chain: Cypress.Chainable<JQuery<HTMLElement>>) {
return this.#getHelperText(chain).should("have.text", "Required field");
return this.assertMessage(chain, "Required field");
}

static assertMessage(
chain: Cypress.Chainable<JQuery<HTMLElement>>,
expectedMessage: string,
) {
return this.#getHelperText(chain).should("have.text", expectedMessage);
}

static assertMinValue(
chain: Cypress.Chainable<JQuery<HTMLElement>>,
minValue: number,
) {
this.#getHelperText(chain).should(
"have.text",
`Must be greater than ${minValue}`,
);
this.assertMessage(chain, `Must be greater than ${minValue}`);
}

static assertMaxValue(
chain: Cypress.Chainable<JQuery<HTMLElement>>,
maxValue: number,
) {
this.#getHelperText(chain).should(
"have.text",
`Must be less than ${maxValue}`,
);
this.assertMessage(chain, `Must be less than ${maxValue}`);
}

static #getHelperText(chain: Cypress.Chainable<JQuery<HTMLElement>>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export default class RealmSettingsPage extends CommonPage {
forgotPwdSwitch = "forgot-pw-switch";
rememberMeSwitch = "remember-me-switch";
emailAsUsernameSwitch = "email-as-username-switch";
editUsernameSwitch = "edit-username-switch";
loginWithEmailSwitch = "login-with-email-switch";
duplicateEmailsSwitch = "duplicate-emails-switch";
verifyEmailSwitch = "verify-email-switch";
Expand Down Expand Up @@ -448,6 +449,22 @@ export default class RealmSettingsPage extends CommonPage {
return this;
}

assertSwitch(switchName: string, on: boolean) {
cy.findByTestId(switchName).should("have.value", on ? "on" : "off");

return this;
}

setSwitch(switchName: string, on: boolean) {
if (on) {
cy.findByTestId(switchName).check({ force: true });
} else {
cy.findByTestId(switchName).uncheck({ force: true });
}

return this;
}

toggleCheck(switchName: string) {
cy.findByTestId(switchName).click();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import Select from "../../../../forms/Select";
import Masthead from "../../Masthead";
import ValidatorConfigDialogue from "./ValidatorConfigDialogue";

export default class UserProfile {
readonly masthead = new Masthead();
readonly validatorConfigDialogue = new ValidatorConfigDialogue(this);

#userProfileTab = "rs-user-profile-tab";
#attributesTab = "attributesTab";
#attributesGroupTab = "attributesGroupTab";
Expand All @@ -13,25 +17,22 @@ export default class UserProfile {
#newAttributeNameInput = "attribute-name";
#newAttributeDisplayNameInput = "attribute-display-name";
#newAttributeEnabledWhen = 'input[name="enabledWhen"]';
#newAttributeRequiredWhen = 'input[name="requiredWhen"]';
#newAttributeEmptyValidators = ".kc-emptyValidators";
#newAttributeAnnotationBtn = "annotations-add-row";
#newAttributeAnnotationKey = "annotations.0.key";
#newAttributeAnnotationValue = "annotations.0.value";
#validatorRolesList = "#validator";
#validatorsList = 'tbody [data-label="name"]';
#saveNewAttributeBtn = "attribute-create";
#addValidatorBtn = "addValidator";
#saveValidatorBtn = "save-validator-role-button";
#removeValidatorBtn = "deleteValidator";
#deleteValidatorBtn = "confirm";
#cancelAddingValidatorBtn = "cancel-validator-role-button";
#cancelRemovingValidatorBtn = "cancel";
#newAttributeRequiredField = "input#kc-required.pf-c-switch__input";
#newAttributeUserEdit = "user-edit";
#newAttributeAdminEdit = "admin-edit";
#newAttributeUserView = "user-view";
#newAttributeAdminView = "admin-view";
#createAttributesGroupButton = "create-attributes-groups-action";
#newAttributesGroupNameInput = "input#kc-name";
#newAttributesGroupDisplayNameInput = 'input[name="displayHeader"]';
#saveNewAttributesGroupBtn = "saveGroupBtn";
Expand All @@ -56,7 +57,7 @@ export default class UserProfile {
return this;
}

createAttributeButtonClick() {
clickOnCreateAttributeButton() {
cy.findByTestId(this.#createAttributeButton).click();
return this;
}
Expand All @@ -81,7 +82,7 @@ export default class UserProfile {
return this;
}

createAttribute(name: string, displayName: string) {
setAttributeNames(name: string, displayName: string) {
cy.findByTestId(this.#newAttributeNameInput).type(name);
cy.findByTestId(this.#newAttributeDisplayNameInput).type(displayName);
return this;
Expand All @@ -97,39 +98,30 @@ export default class UserProfile {
return this;
}

createAttributeNotRequiredWithPermissions(name: string, displayName: string) {
cy.findByTestId(this.#newAttributeNameInput).type(name);
cy.findByTestId(this.#newAttributeDisplayNameInput).type(displayName);
cy.get(this.#newAttributeEnabledWhen).first().check();
setAttributeRequired() {
cy.get(this.#newAttributeRequiredField).first().check({ force: true });

return this;
}

setAllAttributePermissions() {
cy.findByTestId(this.#newAttributeUserEdit).first().check({ force: true });
cy.findByTestId(this.#newAttributeUserView).first().check({ force: true });
cy.findByTestId(this.#newAttributeAdminView).first().check({ force: true });

return this;
}

createAttributeNotRequiredWithoutPermissions(
name: string,
displayName: string,
) {
cy.findByTestId(this.#newAttributeNameInput).type(name);
cy.findByTestId(this.#newAttributeDisplayNameInput).type(displayName);
cy.get(this.#newAttributeEnabledWhen).first().check();
setNoAttributePermissions() {
cy.findByTestId(this.#newAttributeAdminEdit)
.first()
.uncheck({ force: true });

return this;
}

createAttributeRequiredWithPermissions(name: string, displayName: string) {
cy.findByTestId(this.#newAttributeNameInput).type(name);
cy.findByTestId(this.#newAttributeDisplayNameInput).type(displayName);
cy.get(this.#newAttributeEnabledWhen).first().check();
cy.get(this.#newAttributeRequiredField).first().check({ force: true });
cy.get(this.#newAttributeRequiredWhen).first().check({ force: true });
cy.findByTestId(this.#newAttributeUserEdit).first().check({ force: true });
cy.findByTestId(this.#newAttributeUserView).first().check({ force: true });
cy.findByTestId(this.#newAttributeAdminView).first().check({ force: true });
clickOnCreatesAttributesGroupButton() {
cy.findByTestId(this.#createAttributesGroupButton).click();
return this;
}

Expand All @@ -149,6 +141,17 @@ export default class UserProfile {
return this;
}

setAttributeGroup(group: string) {
cy.get("#kc-attributeGroup").click();
cy.get("button.pf-c-select__menu-item").contains(group).click();

return this;
}

resetAttributeGroup() {
return this.setAttributeGroup("None");
}

editAttribute(displayName: string) {
cy.findByTestId(this.#newAttributeDisplayNameInput)
.click()
Expand All @@ -162,10 +165,9 @@ export default class UserProfile {
return this;
}

addValidator() {
cy.findByTestId(this.#addValidatorBtn).click();
Select.selectItem(cy.get(this.#validatorRolesList), "email");
cy.findByTestId(this.#saveValidatorBtn).click();
addValidator(type: string) {
this.clickAddValidator().selectValidatorType(type).clickSave();

return this;
}

Expand All @@ -175,13 +177,18 @@ export default class UserProfile {
return this;
}

cancelAddingValidator() {
cy.findByTestId(this.#addValidatorBtn).click();
Select.selectItem(cy.get(this.#validatorRolesList), "email");
cy.findByTestId(this.#cancelAddingValidatorBtn).click();
cancelAddingValidator(type: string) {
this.clickAddValidator().selectValidatorType(type).clickCancel();

return this;
}

clickAddValidator() {
cy.findByTestId(this.#addValidatorBtn).click();

return this.validatorConfigDialogue;
}

cancelRemovingValidator() {
cy.findByTestId(this.#removeValidatorBtn).click();
cy.findByTestId(this.#cancelRemovingValidatorBtn).click();
Expand All @@ -201,6 +208,14 @@ export default class UserProfile {
return this;
}

assertNotificationSaved() {
this.masthead.checkNotificationMessage(
"Success! User Profile configuration has been saved.",
);

return this;
}

shouldHaveText(text: string) {
this.#getText().should("have.text", text);
return this;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import UserProfile from "./UserProfile";
import Select from "../../../../forms/Select";

export default class ValidatorConfigDialogue {
readonly #validatorSelector = "#validator";
readonly #saveValidatorButton = "save-validator-role-button";
readonly #cancelValidatorButton: "cancel-validator-role-button";
readonly #addValue = "addValue";

readonly userProfile: UserProfile;

constructor(userProfile: UserProfile) {
this.userProfile = userProfile;
}

clickSave() {
cy.findByTestId(this.#saveValidatorButton).click();

return this.userProfile;
}

selectValidatorType(type: string) {
Select.selectItem(cy.get(this.#validatorSelector), type);

return this;
}

setListFieldValues(fieldName: string, values: string[]) {
for (let i = 0; i < values.length; i++) {
if (i != 0) {
cy.findByTestId(this.#addValue).click();
}

const testId = `config.options${i}`;
cy.findByTestId(testId).clear().type(values[i]);
}

return this;
}

clickCancel() {
cy.findByTestId(this.#cancelValidatorButton).click();

return this.userProfile;
}
}
Loading

0 comments on commit 37efa89

Please sign in to comment.