From 92fde8b49445a32cea47d477637fea7fc580f94e Mon Sep 17 00:00:00 2001 From: AnveshNalimela Date: Tue, 26 Nov 2024 21:33:32 +0530 Subject: [PATCH] Made requested changes --- cypress/e2e/users_spec/UsersCreation.cy.ts | 72 ++++++++++++--------- cypress/e2e/users_spec/UsersProfile.cy.ts | 4 +- cypress/pageobject/Users/UserCreation.ts | 58 ----------------- cypress/pageobject/Users/UserProfilePage.ts | 17 ++++- 4 files changed, 57 insertions(+), 94 deletions(-) diff --git a/cypress/e2e/users_spec/UsersCreation.cy.ts b/cypress/e2e/users_spec/UsersCreation.cy.ts index d4fc2ff9e52..e17dcf6666a 100644 --- a/cypress/e2e/users_spec/UsersCreation.cy.ts +++ b/cypress/e2e/users_spec/UsersCreation.cy.ts @@ -1,3 +1,6 @@ +import ManageUserPage from "pageobject/Users/ManageUserPage"; +import UserProfilePage from "pageobject/Users/UserProfilePage"; + import { AssetSearchPage } from "../../pageobject/Asset/AssetSearch"; import FacilityPage from "../../pageobject/Facility/FacilityCreation"; import LoginPage from "../../pageobject/Login/LoginPage"; @@ -11,6 +14,8 @@ import { describe("User Creation", () => { const userPage = new UserPage(); const loginPage = new LoginPage(); + const userProfilePage = new UserProfilePage(); + const manageUserPage = new ManageUserPage(); const userCreationPage = new UserCreationPage(); const facilityPage = new FacilityPage(); const assetSearchPage = new AssetSearchPage(); @@ -87,25 +92,26 @@ describe("User Creation", () => { }); it("Update the existing user profile and verify its reflection", () => { - userCreationPage.clickProfileName(); - userCreationPage.clickProfileButton(); + manageUserPage.navigateToProfile(); cy.verifyContentPresence("#username-profile-details", [userName]); - userCreationPage.clickEditProfileButton(); + userProfilePage.clickEditProfileButton(); userCreationPage.clearFirstName(); userCreationPage.typeFirstName(firstName); userCreationPage.clearLastName(); userCreationPage.typeLastName(lastName); - userCreationPage.selectGender(gender); - userCreationPage.clearPhoneNumber(); - userCreationPage.typePhoneNumber(phone_number); - userCreationPage.clearAltPhoneNumber(); - userCreationPage.typeAltPhoneNumber(emergency_phone_number); - userCreationPage.clearEmail(); - userCreationPage.typeEmail(email); - userCreationPage.clearWeeklyWorkingHours(); - userCreationPage.typeWeeklyWorkingHours(weeklyWorkingHrs); - userCreationPage.typeDateOfBirth(dob); - cy.submitButton(updateBtn); + userProfilePage.selectGender(gender); + userProfilePage.clearPhoneNumber(); + userProfilePage.typePhoneNumber(phone_number); + userProfilePage.clearAltPhoneNumber(); + userProfilePage.typeAltPhoneNumber(emergency_phone_number); + userProfilePage.clearEmail(); + userProfilePage.typeEmail(email); + userProfilePage.clearWorkingHours(); + userProfilePage.typeWorkingHours(weeklyWorkingHrs); + userProfilePage.typedate_of_birth(dob); + cy.intercept("PATCH", "/api/v1/users/*").as("updateUser"); + cy.clickSubmitButton(updateBtn); + cy.wait("@updateUser").its("response.statusCode").should("eq", 200); cy.verifyContentPresence("#contactno-profile-details", [ "+91" + phone_number, ]); @@ -123,15 +129,14 @@ describe("User Creation", () => { }); it("Update the existing user profile Form Mandatory File Error", () => { - userCreationPage.clickProfileName(); - userCreationPage.clickProfileButton(); - userCreationPage.clickEditProfileButton(); + manageUserPage.navigateToProfile(); + userProfilePage.clickEditProfileButton(); userCreationPage.clearFirstName(); userCreationPage.clearLastName(); - userCreationPage.clearPhoneNumber(); - userCreationPage.clearAltPhoneNumber(); - userCreationPage.clearWeeklyWorkingHours(); - cy.submitButton(updateBtn); + userProfilePage.clearPhoneNumber(); + userProfilePage.clearAltPhoneNumber(); + userProfilePage.clearWorkingHours(); + cy.clickSubmitButton(updateBtn); userCreationPage.verifyErrorMessages(EXPECTED_PROFILE_ERROR_MESSAGES); }); @@ -140,22 +145,25 @@ describe("User Creation", () => { userCreationPage.selectFacility(homeFacility); userCreationPage.typeUserName(username); userCreationPage.typePassword(password); + userCreationPage.typeConfirmPassword(password); userCreationPage.selectHomeFacility(homeFacility); - userCreationPage.typeNewUserPhoneNumber(phone_number); - userCreationPage.typeDateOfBirth(newUserDob); + userPage.typeInPhoneNumber(phone_number); + userProfilePage.typedate_of_birth(newUserDob); userCreationPage.selectUserType(role); - userCreationPage.typeConfirmPassword(password); - userCreationPage.typeQualification(qualification); - userCreationPage.typeDoctorExperience(experince); - userCreationPage.typeDoctorMedicalCouncilRegNo(regNo); - userCreationPage.typeNewUserFirstName(newUserFirstName); - userCreationPage.typeNewUserLastName(newUserLastName); - userCreationPage.typeEmail(email); + userProfilePage.typeQualification(qualification); + userProfilePage.typeDoctorYoE(experince); + userProfilePage.typeMedicalCouncilRegistration(regNo); + userPage.typeInFirstName(newUserFirstName); + userPage.typeInLastName(newUserLastName); + userProfilePage.typeEmail(email); userCreationPage.selectGender(gender); userCreationPage.selectState(state); userCreationPage.selectDistrict(district); - cy.submitButton(saveBtn); + cy.intercept("POST", "/api/v1/users/add_user/").as("createUser"); + cy.clickSubmitButton(saveBtn); + cy.wait("@createUser").its("response.statusCode").should("eq", 201); cy.verifyNotification("User added successfully"); + userPage.typeInSearchInput(username); userPage.checkUsernameText(username); cy.verifyContentPresence("#name", [newUserFirstName]); @@ -169,7 +177,7 @@ describe("User Creation", () => { it("create new user form throwing mandatory field error", () => { userCreationPage.clickAddUserButton(); - cy.submitButton(saveBtn); + cy.clickSubmitButton(saveBtn); cy.get(".error-text", { timeout: 10000 }).should("be.visible"); userCreationPage.verifyErrorMessages(EXPECTED_ERROR_MESSAGES); }); diff --git a/cypress/e2e/users_spec/UsersProfile.cy.ts b/cypress/e2e/users_spec/UsersProfile.cy.ts index 35771024180..07e93607532 100644 --- a/cypress/e2e/users_spec/UsersProfile.cy.ts +++ b/cypress/e2e/users_spec/UsersProfile.cy.ts @@ -35,8 +35,8 @@ describe("Manage User Profile", () => { userProfilePage.typedate_of_birth(date_of_birth); userProfilePage.selectGender(gender); userProfilePage.typeEmail(email); - userProfilePage.typePhone(phone); - userProfilePage.typeWhatsApp(phone); + userProfilePage.typePhoneNumber(phone); + userProfilePage.typeAltPhoneNumber(phone); userProfilePage.typeWorkingHours(workinghours); userProfilePage.typeQualification(qualification); userProfilePage.typeDoctorYoE(doctorYoE); diff --git a/cypress/pageobject/Users/UserCreation.ts b/cypress/pageobject/Users/UserCreation.ts index f4d16784e6d..5b1515f4d0b 100644 --- a/cypress/pageobject/Users/UserCreation.ts +++ b/cypress/pageobject/Users/UserCreation.ts @@ -1,14 +1,5 @@ // UserCreation.ts export class UserCreationPage { - clickProfileName() { - cy.get("#user-profile-name").click(); - } - clickProfileButton() { - cy.verifyAndClickElement("#profile-button", "Profile"); - } - clickEditProfileButton() { - cy.verifyAndClickElement("#edit-cancel-profile-button", "Edit Profile"); - } clickAddUserButton() { cy.verifyAndClickElement("#addUserButton", "Add New User"); } @@ -21,64 +12,18 @@ export class UserCreationPage { typeLastName(lastName: string) { cy.get("#lastName").click().type(lastName); } - typeEmail(email: string) { - cy.get("#email").click().type(email); - } typePassword(password: string) { cy.get("#password").click().type(password); } - typePhoneNumber(phone_number: string) { - cy.get("#phoneNumber").click().type(phone_number); - } typeConfirmPassword(password: string) { cy.get("#c_password").click().type(password); } - typeQualification(qualification: string) { - cy.get("#qualification").click().type(qualification); - } - typeDoctorExperience(experience: string) { - cy.get("#doctor_experience_commenced_on").click().type(experience); - } - typeDoctorMedicalCouncilRegNo(regNo: string) { - cy.get("#doctor_medical_council_registration").click().type(regNo); - } - typeWeeklyWorkingHours(workingHrs: string) { - cy.get("#weekly_working_hours").click().type(workingHrs); - } - typeAltPhoneNumber(emergencyPhoneNumber: string) { - cy.get("#altPhoneNumber").click().type(emergencyPhoneNumber); - } - typeDateOfBirth(dob: string) { - cy.clickAndTypeDate("#date_of_birth", dob); - } - typeNewUserFirstName(firstName: string) { - cy.get("#first_name").click().type(firstName); - } - typeNewUserLastName(lastName: string) { - cy.get("#last_name").click().type(lastName); - } - typeNewUserPhoneNumber(phoneNumber: string) { - cy.get("#phone_number").click().type(phoneNumber); - } clearFirstName() { cy.get("#firstName").click().clear(); } clearLastName() { cy.get("#lastName").click().clear(); } - clearPhoneNumber() { - cy.get("#phoneNumber").click().clear(); - } - clearAltPhoneNumber() { - cy.get("#altPhoneNumber").click().clear(); - } - clearWeeklyWorkingHours() { - cy.get("#weekly_working_hours").click().clear(); - } - clearEmail() { - cy.get("#email").click().clear(); - } - selectUserType(role: string) { cy.clickAndSelectOption("#user_type", role); } @@ -98,9 +43,6 @@ export class UserCreationPage { selectFacility(name: string) { cy.typeAndSelectOption("input[name='facilities']", name); - cy.get("input[name='facilities'] + button") - .find("#dropdown-toggle") - .click(); } verifyElementContainsText(elementId: string, expectedText: string) { diff --git a/cypress/pageobject/Users/UserProfilePage.ts b/cypress/pageobject/Users/UserProfilePage.ts index 3744c5a5d82..de72fb51be0 100644 --- a/cypress/pageobject/Users/UserProfilePage.ts +++ b/cypress/pageobject/Users/UserProfilePage.ts @@ -19,6 +19,19 @@ export default class UserProfilePage { cy.clickAndTypeDate("#date_of_birth", date_of_birth); } + clearPhoneNumber() { + cy.get("#phoneNumber").click().clear(); + } + clearAltPhoneNumber() { + cy.get("#altPhoneNumber").click().clear(); + } + clearWorkingHours() { + cy.get("#weekly_working_hours").click().clear(); + } + clearEmail() { + cy.get("#email").click().clear(); + } + selectGender(gender: string) { cy.get("#gender").click(); cy.get("#gender-option-" + gender).click(); @@ -28,11 +41,11 @@ export default class UserProfilePage { cy.get("#email").click().clear().type(email); } - typePhone(phone: string) { + typePhoneNumber(phone: string) { cy.get("#phoneNumber").click().clear().type(phone); } - typeWhatsApp(phone: string) { + typeAltPhoneNumber(phone: string) { cy.get("#altPhoneNumber").click().clear().type(phone); }