Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Cypress Test | Existing User Profile Updation | User Tab #6527

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 83 additions & 62 deletions cypress/e2e/users_spec/user_creation.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { AssetSearchPage } from "../../pageobject/Asset/AssetSearch";
import FacilityPage from "../../pageobject/Facility/FacilityCreation";
import { UserPage } from "../../pageobject/Users/UserSearch";
import { UserCreationPage } from "../../pageobject/Users/UserCreation";
import {
emergency_phone_number,
phone_number,
} from "../../pageobject/constants";

describe("User Creation", () => {
const userPage = new UserPage();
Expand Down Expand Up @@ -43,6 +47,15 @@ describe("User Creation", () => {
"Please select the local body",
];

const EXPECTED_PROFILE_ERROR_MESSAGES = [
"Field is required",
"Field is required",
"This field is required",
"Please enter valid phone number",
"This field is required",
"This field is required",
];

before(() => {
loginPage.loginAsDisctrictAdmin();
cy.saveLocalStorage();
Expand All @@ -53,13 +66,82 @@ describe("User Creation", () => {
cy.awaitUrl("/users");
});

it("Update the existing user profile and verify its reflection", () => {
userCreationPage.clickElementById("profilenamelink");
userCreationPage.verifyElementContainsText(
"username-profile-details",
"devdistrictadmin"
);
userCreationPage.clickElementById("edit-cancel-profile-button");
userCreationPage.typeIntoElementByIdPostClear(
"firstName",
"District Editted"
);
userCreationPage.typeIntoElementByIdPostClear("lastName", "Cypress");
userCreationPage.typeIntoElementByIdPostClear("age", "22");
userCreationPage.selectDropdownOption("gender", "Male");
userCreationPage.typeIntoElementByIdPostClear(
"phoneNumber",
"+91" + phone_number
);
userCreationPage.typeIntoElementByIdPostClear(
"altPhoneNumber",
"+91" + emergency_phone_number
);
userCreationPage.typeIntoElementByIdPostClear("email", "[email protected]");
userCreationPage.typeIntoElementByIdPostClear("weekly_working_hours", "14");
userCreationPage.clickElementById("submit");
userCreationPage.verifyElementContainsText(
"contactno-profile-details",
"+91" + phone_number
);
userCreationPage.verifyElementContainsText(
"whatsapp-profile-details",
"+91" + emergency_phone_number
);
userCreationPage.verifyElementContainsText(
"firstname-profile-details",
"District Editted"
);
userCreationPage.verifyElementContainsText(
"lastname-profile-details",
"Cypress"
);
userCreationPage.verifyElementContainsText("age-profile-details", "22");
userCreationPage.verifyElementContainsText(
"emailid-profile-details",
"[email protected]"
);
userCreationPage.verifyElementContainsText(
"gender-profile-details",
"Male"
);
userCreationPage.verifyElementContainsText(
"averageworkinghour-profile-details",
"14"
);
});

it("Update the existing user profile Form Mandatory File Error", () => {
userCreationPage.clickElementById("profilenamelink");
userCreationPage.clickElementById("edit-cancel-profile-button");
userCreationPage.clearIntoElementById("firstName");
userCreationPage.clearIntoElementById("lastName");
userCreationPage.clearIntoElementById("age");
userCreationPage.clearIntoElementById("phoneNumber");
userCreationPage.clearIntoElementById("altPhoneNumber");
userCreationPage.clearIntoElementById("weekly_working_hours");
userCreationPage.clickElementById("submit");
userCreationPage.verifyErrorMessages(EXPECTED_PROFILE_ERROR_MESSAGES);
});

it("create new user and verify reflection", () => {
userCreationPage.clickElementById("addUserButton");
userCreationPage.selectFacility("Dummy Shifting Center");
userCreationPage.typeIntoElementById("username", username);
userCreationPage.typeIntoElementById("password", "Test@123");
userCreationPage.selectHomeFacility("Dummy Shifting Center");
userCreationPage.typeIntoElementById("phone_number", "9999999999");
userCreationPage.typeIntoElementById("phone_number", phone_number);
userCreationPage.setInputDate("date_of_birth", "date-input", "25081999");
userCreationPage.selectDropdownOption("user_type", "Doctor");
userCreationPage.typeIntoElementById("c_password", "Test@123");
Expand Down Expand Up @@ -130,67 +212,6 @@ describe("User Creation", () => {
// .contains("Facility - User Already has permission to this facility");
// });

// describe("Edit User Profile & Error Validation", () => {
// before(() => {
// cy.loginByApi(username, "#@Cypress_test123");
// cy.saveLocalStorage();
// });

// beforeEach(() => {
// cy.restoreLocalStorage();
// cy.awaitUrl("/user/profile");
// cy.contains("button", "Edit User Profile").click();
// });

// it("First name Field Updation " + username, () => {
// cy.get("input[name=firstName]").clear();
// cy.contains("button[type='submit']", "Update").click();
// cy.get("span.error-text").should("contain", "Field is required");
// cy.get("input[name=firstName]").type("firstName updated");
// cy.contains("button[type='submit']", "Update").click();
// });

// it("Last name Field Updation " + username, () => {
// cy.get("input[name=lastName]").clear();
// cy.contains("button[type='submit']", "Update").click();
// cy.get("span.error-text").should("contain", "Field is required");
// cy.get("input[name=lastName]").type("lastName updated");
// cy.contains("button[type='submit']", "Update").click();
// });

// it("Age Field Updation " + username, () => {
// cy.get("input[name=age]").clear();
// cy.contains("button[type='submit']", "Update").click();
// cy.get("span.error-text").should("contain", "This field is required");
// cy.get("input[name=age]").type("11");
// cy.contains("button[type='submit']", "Update").click();
// });

// it("Phone number Field Updation " + username, () => {
// cy.get("input[name=phoneNumber]").clear();
// cy.contains("button[type='submit']", "Update").click();
// cy.get("span.error-text").should(
// "contain",
// "Please enter valid phone number"
// );
// cy.get("input[name=phoneNumber]").type("+919999999999");
// cy.contains("button[type='submit']", "Update").click();
// });

// it("Whatsapp number Field Updation " + username, () => {
// cy.get("input[name=altPhoneNumber]").clear();
// cy.get("input[name=altPhoneNumber]").type("+919999999999");
// cy.contains("button[type='submit']", "Update").click();
// });

// it("Email Field Updation " + username, () => {
// cy.get("input[name=email]").clear();
// cy.contains("button[type='submit']", "Update").click();
// cy.get("span.error-text").should("contain", "This field is required");
// cy.get("input[name=email]").type("[email protected]");
// cy.contains("button[type='submit']", "Update").click();
// });

afterEach(() => {
cy.saveLocalStorage();
});
Expand Down
14 changes: 14 additions & 0 deletions cypress/pageobject/Users/UserCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ export class UserCreationPage {
.type(value);
}

typeIntoElementByIdPostClear(elementId: string, value: string) {
cy.get("#" + elementId)
.click()
.clear()
.click()
.type(value);
}

clearIntoElementById(elementId: string) {
cy.get("#" + elementId)
.click()
.clear();
}

typeIntoInputByName(inputName: string, value: string) {
cy.get("input[name='" + inputName + "']")
.click()
Expand Down
1 change: 1 addition & 0 deletions src/Components/Common/Sidebar/SidebarUserCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const SidebarUserCard = ({ shrinked }: { shrinked: boolean }) => {
<Link
href="/user/profile"
className="flex-nowrap overflow-hidden break-words font-semibold text-white"
id="profilenamelink"
>
{profileName}
</Link>
Expand Down
48 changes: 38 additions & 10 deletions src/Components/Users/UserProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,11 @@ export default function UserProfile() {
Local Body, District and State are Non Editable Settings.
</p>
<div className="flex flex-col gap-2">
<ButtonV2 onClick={(_) => setShowEdit(!showEdit)} type="button">
<ButtonV2
onClick={(_) => setShowEdit(!showEdit)}
type="button"
id="edit-cancel-profile-button"
>
{showEdit ? "Cancel" : "Edit User Profile"}
</ButtonV2>
<ButtonV2 variant="danger" onClick={(_) => handleSignOut(true)}>
Expand All @@ -431,15 +435,21 @@ export default function UserProfile() {
{!showEdit && (
<div className="m-2 overflow-hidden rounded-lg bg-white px-4 py-5 shadow sm:rounded-lg sm:px-6">
<dl className="col-gap-4 row-gap-8 grid grid-cols-1 sm:grid-cols-2">
<div className="my-2 sm:col-span-1">
<div
className="my-2 sm:col-span-1"
id="username-profile-details"
>
<dt className="text-sm font-medium leading-5 text-black">
Username
</dt>
<dd className="mt-1 text-sm leading-5 text-gray-900">
{details.username || "-"}
</dd>
</div>
<div className="my-2 sm:col-span-1">
<div
className="my-2 sm:col-span-1"
id="contactno-profile-details"
>
<dt className="text-sm font-medium leading-5 text-black">
Contact No
</dt>
Expand All @@ -448,39 +458,51 @@ export default function UserProfile() {
</dd>
</div>

<div className="my-2 sm:col-span-1">
<div
className="my-2 sm:col-span-1"
id="whatsapp-profile-details"
>
<dt className="text-sm font-medium leading-5 text-black">
Whatsapp No
</dt>
<dd className="mt-1 text-sm leading-5 text-gray-900">
{details.alt_phone_number || "-"}
</dd>
</div>
<div className="my-2 sm:col-span-1">
<div
className="my-2 sm:col-span-1"
id="emailid-profile-details"
>
<dt className="text-sm font-medium leading-5 text-black">
Email address
</dt>
<dd className="mt-1 text-sm leading-5 text-gray-900">
{details.email || "-"}
</dd>
</div>
<div className="my-2 sm:col-span-1">
<div
className="my-2 sm:col-span-1"
id="firstname-profile-details"
>
<dt className="text-sm font-medium leading-5 text-black">
First Name
</dt>
<dd className="mt-1 text-sm leading-5 text-gray-900">
{details.first_name || "-"}
</dd>
</div>
<div className="my-2 sm:col-span-1">
<div
className="my-2 sm:col-span-1"
id="lastname-profile-details"
>
<dt className="text-sm font-medium leading-5 text-black">
Last Name
</dt>
<dd className="mt-1 text-sm leading-5 text-gray-900">
{details.last_name || "-"}
</dd>
</div>
<div className="my-2 sm:col-span-1">
<div className="my-2 sm:col-span-1" id="age-profile-details">
<dt className="text-sm font-medium leading-5 text-black">
Age
</dt>
Expand All @@ -497,7 +519,10 @@ export default function UserProfile() {
{details.user_type || "-"}
</dd>
</div>
<div className="my-2 sm:col-span-1">
<div
className="my-2 sm:col-span-1"
id="gender-profile-details"
>
<dt className="text-sm font-medium leading-5 text-black">
Gender
</dt>
Expand Down Expand Up @@ -547,7 +572,10 @@ export default function UserProfile() {
</div>
</dd>
</div>
<div className="my-2 sm:col-span-1">
<div
className="my-2 sm:col-span-1"
id="averageworkinghour-profile-details"
>
<dt className="text-sm font-medium leading-5 text-black">
Average weekly working hours
</dt>
Expand Down
Loading