-
Notifications
You must be signed in to change notification settings - Fork 532
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Cypress Test for User Creation (#9986)
- Loading branch information
Showing
16 changed files
with
371 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { UserCreation } from "../../pageObject/Users/UserCreation"; | ||
import { FacilityCreation } from "../../pageObject/facility/FacilityCreation"; | ||
import { | ||
generateName, | ||
generatePhoneNumber, | ||
generateUsername, | ||
} from "../../utils/commonUtils"; | ||
|
||
describe("User Creation", () => { | ||
const facilityCreation = new FacilityCreation(); | ||
const userCreation = new UserCreation(); | ||
const userRole = "Doctor"; | ||
|
||
beforeEach(() => { | ||
cy.visit("/login"); | ||
cy.loginByApi("admin"); | ||
}); | ||
|
||
it("should create a new user successfully", () => { | ||
// Generate fresh data at the start of each test attempt | ||
const fullName = generateName(); | ||
const [firstName, lastName] = fullName.split(" "); | ||
const defaultPassword = "Test@123"; | ||
|
||
const testUserData = { | ||
firstName, | ||
lastName, | ||
username: generateUsername(firstName), | ||
password: defaultPassword, | ||
confirmPassword: defaultPassword, | ||
email: `${generateUsername(firstName)}@test.com`, | ||
phoneNumber: generatePhoneNumber(), | ||
dateOfBirth: "1990-01-01", | ||
userType: "Doctor", | ||
state: "Kerala", | ||
district: "Ernakulam", | ||
localBody: "Aluva", | ||
ward: "4", | ||
}; | ||
|
||
facilityCreation.navigateToOrganization("Kerala"); | ||
|
||
userCreation | ||
.navigateToUsersTab() | ||
.clickAddUserButton() | ||
.submitUserForm() | ||
.verifyValidationErrors() | ||
.fillUserDetails(testUserData) | ||
.interceptUserCreationRequest() | ||
.submitUserForm() | ||
.verifyUserCreationApiCall() | ||
.selectUserRole(userRole) | ||
.interceptOrganizationUserLinking() | ||
.clickLinkToOrganization() | ||
.verifyOrganizationUserLinkingApiCall(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
export interface UserData { | ||
firstName?: string; | ||
lastName?: string; | ||
username?: string; | ||
password?: string; | ||
email?: string; | ||
phoneNumber?: string; | ||
dateOfBirth?: string; | ||
userType?: string; | ||
state?: string; | ||
district?: string; | ||
localBody?: string; | ||
ward?: string; | ||
} | ||
|
||
export class UserCreation { | ||
clickAddUserButton() { | ||
cy.verifyAndClickElement('[data-cy="add-user-button"]', "Add User"); | ||
return this; | ||
} | ||
|
||
navigateToUsersTab() { | ||
cy.verifyAndClickElement('[data-cy="org-nav-users"]', "Users"); | ||
return this; | ||
} | ||
|
||
fillFirstName(firstName: string) { | ||
cy.typeIntoField('[data-cy="first-name-input"]', firstName); | ||
return this; | ||
} | ||
|
||
fillLastName(lastName: string) { | ||
cy.typeIntoField('[data-cy="last-name-input"]', lastName); | ||
return this; | ||
} | ||
|
||
fillUsername(username: string) { | ||
cy.typeIntoField('[data-cy="username-input"]', username); | ||
return this; | ||
} | ||
|
||
fillPassword(password: string) { | ||
cy.typeIntoField('[data-cy="password-input"]', password); | ||
return this; | ||
} | ||
|
||
fillConfirmPassword(confirmPassword: string) { | ||
cy.typeIntoField('[data-cy="confirm-password-input"]', confirmPassword); | ||
return this; | ||
} | ||
|
||
fillEmail(email: string) { | ||
cy.typeIntoField('[data-cy="email-input"]', email); | ||
return this; | ||
} | ||
|
||
fillPhoneNumber(phoneNumber: string) { | ||
cy.typeIntoField('[data-cy="phone-number-input"]', phoneNumber, { | ||
skipVerification: true, | ||
}); | ||
return this; | ||
} | ||
|
||
verifyValidationErrors() { | ||
cy.verifyErrorMessages([ | ||
{ label: "First Name", message: "Required" }, | ||
{ label: "Last Name", message: "Required" }, | ||
{ label: "Username", message: "Required" }, | ||
{ label: "Password", message: "Required" }, | ||
{ label: "Confirm Password", message: "Required" }, | ||
{ label: "Email", message: "Required" }, | ||
{ | ||
label: "Phone Number", | ||
message: "Phone number must start with +91 followed by 10 digits", | ||
}, | ||
{ | ||
label: "Alternate Phone Number", | ||
message: "Phone number must start with +91 followed by 10 digits", | ||
}, | ||
{ label: "Date of Birth", message: "Required" }, | ||
{ label: "State", message: "Required" }, | ||
]); | ||
return this; | ||
} | ||
|
||
fillDateOfBirth(dateOfBirth: string) { | ||
cy.typeIntoField('[data-cy="dob-input"]', dateOfBirth); | ||
return this; | ||
} | ||
|
||
selectUserType(userType: string) { | ||
cy.clickAndSelectOption('[data-cy="user-type-select"]', userType); | ||
return this; | ||
} | ||
|
||
selectState(state: string) { | ||
cy.clickAndSelectOption('[data-cy="select-state"]', state); | ||
return this; | ||
} | ||
|
||
selectDistrict(district: string) { | ||
cy.clickAndSelectOption('[data-cy="select-district"]', district); | ||
return this; | ||
} | ||
|
||
selectLocalBody(localBody: string) { | ||
cy.clickAndSelectOption('[data-cy="select-local_body"]', localBody); | ||
return this; | ||
} | ||
|
||
selectWard(ward: string) { | ||
cy.clickAndSelectOption('[data-cy="select-ward"]', ward); | ||
return this; | ||
} | ||
|
||
fillUserDetails(userData: UserData & { confirmPassword?: string }) { | ||
if (userData.userType) this.selectUserType(userData.userType); | ||
if (userData.firstName) this.fillFirstName(userData.firstName); | ||
if (userData.lastName) this.fillLastName(userData.lastName); | ||
if (userData.username) this.fillUsername(userData.username); | ||
if (userData.password) { | ||
this.fillPassword(userData.password); | ||
this.fillConfirmPassword(userData.confirmPassword || userData.password); | ||
} | ||
if (userData.email) this.fillEmail(userData.email); | ||
if (userData.phoneNumber) this.fillPhoneNumber(userData.phoneNumber); | ||
if (userData.dateOfBirth) this.fillDateOfBirth(userData.dateOfBirth); | ||
if (userData.state) this.selectState(userData.state); | ||
if (userData.district) this.selectDistrict(userData.district); | ||
if (userData.localBody) this.selectLocalBody(userData.localBody); | ||
if (userData.ward) this.selectWard(userData.ward); | ||
return this; | ||
} | ||
|
||
submitUserForm() { | ||
cy.clickSubmitButton("Create User"); | ||
return this; | ||
} | ||
|
||
selectUserRole(role: string) { | ||
cy.clickAndSelectOption('[data-cy="select-role-dropdown"]', role); | ||
return this; | ||
} | ||
|
||
clickLinkToOrganization() { | ||
cy.verifyAndClickElement( | ||
'[data-cy="link-user-button"]', | ||
"Link to Organization", | ||
); | ||
return this; | ||
} | ||
|
||
interceptUserCreationRequest() { | ||
cy.intercept("POST", "**/api/v1/users/").as("createUser"); | ||
return this; | ||
} | ||
|
||
verifyUserCreationApiCall() { | ||
cy.wait("@createUser").then((interception) => { | ||
expect(interception.response?.statusCode).to.equal(200); | ||
}); | ||
return this; | ||
} | ||
|
||
interceptOrganizationUserLinking() { | ||
cy.intercept("POST", "**/api/v1/organization/*/users/").as("linkUserToOrg"); | ||
return this; | ||
} | ||
|
||
verifyOrganizationUserLinkingApiCall() { | ||
cy.wait("@linkUserToOrg").then((interception) => { | ||
expect(interception.response?.statusCode).to.equal(200); | ||
}); | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.