From 39cd53069623180a0c3f0ed15f4961af60797c34 Mon Sep 17 00:00:00 2001 From: jenny-s51 Date: Thu, 4 Mar 2021 09:26:21 -0500 Subject: [PATCH] add cypress test to create user --- cypress/integration/users_test.spec.ts | 27 +++++++++++- .../manage/users/CreateUserPage.ts | 41 +++++++++++++++++++ src/user/UserForm.tsx | 1 + 3 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 cypress/support/pages/admin_console/manage/users/CreateUserPage.ts diff --git a/cypress/integration/users_test.spec.ts b/cypress/integration/users_test.spec.ts index 623a004927..4a3bc7079f 100644 --- a/cypress/integration/users_test.spec.ts +++ b/cypress/integration/users_test.spec.ts @@ -1,9 +1,17 @@ import SidebarPage from "../support/pages/admin_console/SidebarPage"; import LoginPage from "../support/pages/LoginPage"; +import CreateUserPage from "../support/pages/admin_console/manage/users/CreateUserPage"; +import Masthead from "../support/pages/admin_console/Masthead"; +import ListingPage from "../support/pages/admin_console/ListingPage"; describe("Users test", () => { const loginPage = new LoginPage(); const sidebarPage = new SidebarPage(); + const createUserPage = new CreateUserPage(); + const masthead = new Masthead(); + const listingPage = new ListingPage(); + + let itemId = "user_crud"; describe("User creation", () => { beforeEach(function () { @@ -13,10 +21,25 @@ describe("Users test", () => { }); it("Go to create User page", () => { - cy.get("[data-testid=add-user").click(); + createUserPage.goToCreateUser(); cy.url().should("include", "users/add-user"); - cy.get("[data-testid=cancel-create-user").click(); + + // Verify Cancel button works + createUserPage.cancel(); cy.url().should("not.include", "/add-user"); }); + + it("Create user test", function () { + itemId += "_" + (Math.random() + 1).toString(36).substring(7); + + // Create + createUserPage.goToCreateUser(); + createUserPage.fillRealmRoleData(itemId).save(); + + masthead.checkNotificationMessage("The user has been created"); + + sidebarPage.goToUsers(); + listingPage.searchItem(itemId).itemExist(itemId); + }); }); }); diff --git a/cypress/support/pages/admin_console/manage/users/CreateUserPage.ts b/cypress/support/pages/admin_console/manage/users/CreateUserPage.ts new file mode 100644 index 0000000000..e5e477af52 --- /dev/null +++ b/cypress/support/pages/admin_console/manage/users/CreateUserPage.ts @@ -0,0 +1,41 @@ +export default class CreateUserPage { + usernameInput: string; + saveBtn: string; + cancelBtn: string; + + constructor() { + this.usernameInput = "#kc-username"; + + this.saveBtn = "[data-testid=create-user]"; + this.cancelBtn = "[data-testid=cancel-create-user]"; + } + + //#region General Settings + fillRealmRoleData(username: string) { + cy.get(this.usernameInput).clear(); + + if (username) { + cy.get(this.usernameInput).type(username); + } + + return this; + } + + goToCreateUser() { + cy.get("[data-testid=add-user").click(); + + return this; + } + + save() { + cy.get(this.saveBtn).click(); + + return this; + } + + cancel() { + cy.get(this.cancelBtn).click(); + + return this; + } +} diff --git a/src/user/UserForm.tsx b/src/user/UserForm.tsx index 55327626a3..1c02c2d4df 100644 --- a/src/user/UserForm.tsx +++ b/src/user/UserForm.tsx @@ -224,6 +224,7 @@ export const UserForm = ({