Skip to content

Commit

Permalink
change cypress tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rash-27 committed Mar 10, 2024
1 parent 3fc908c commit 9b9f137
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 34 deletions.
16 changes: 9 additions & 7 deletions cypress/e2e/users_spec/user_creation.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe("User Creation", () => {
"Please select the User Type",
"Please enter valid phone number",
"Please enter the username",
"Please enter date in YYYY/MM/DD format",
"Field is required",
"Please enter the password",
"Confirm password is required",
"First Name is required",
Expand All @@ -52,10 +52,7 @@ describe("User Creation", () => {
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(() => {
Expand All @@ -81,7 +78,6 @@ describe("User Creation", () => {
"District Editted"
);
userCreationPage.typeIntoElementByIdPostClear("lastName", "Cypress");
userCreationPage.typeIntoElementByIdPostClear("age", "22");
userCreationPage.selectDropdownOption("gender", "Male");
userCreationPage.typeIntoElementByIdPostClear(
"phoneNumber",
Expand All @@ -93,6 +89,10 @@ describe("User Creation", () => {
);
userCreationPage.typeIntoElementByIdPostClear("email", "[email protected]");
userCreationPage.typeIntoElementByIdPostClear("weekly_working_hours", "14");
userCreationPage.typeIntoElementByIdPostClearDob(
"date_of_birth",
"01011998"
);
userCreationPage.clickElementById("submit");
userCreationPage.verifyElementContainsText(
"contactno-profile-details",
Expand All @@ -110,7 +110,10 @@ describe("User Creation", () => {
"lastname-profile-details",
"Cypress"
);
userCreationPage.verifyElementContainsText("age-profile-details", "22");
userCreationPage.verifyElementContainsText(
"date_of_birth-profile-details",
"1998-01-01"
);
userCreationPage.verifyElementContainsText(
"emailid-profile-details",
"[email protected]"
Expand All @@ -130,7 +133,6 @@ describe("User Creation", () => {
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");
Expand Down
8 changes: 4 additions & 4 deletions cypress/e2e/users_spec/user_profile.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe("Manage User Profile", () => {
const userProfilePage = new UserProfilePage();
const manageUserPage = new ManageUserPage();

const age = "30";
const date_of_birth = "01011999";
const gender = "Male";
const email = "[email protected]";
const phone = "+918899887788";
Expand All @@ -32,10 +32,10 @@ describe("Manage User Profile", () => {
cy.awaitUrl("/user/profile");
});

it("Set Age, Gender, Email, Phone and Working Hours for a user and verify its reflection in user profile", () => {
it("Set Dob, Gender, Email, Phone and Working Hours for a user and verify its reflection in user profile", () => {
userProfilePage.clickEditProfileButton();

userProfilePage.typeAge(age);
userProfilePage.typedate_of_birth(date_of_birth);
userProfilePage.selectGender(gender);
userProfilePage.typeEmail(email);
userProfilePage.typePhone(phone);
Expand All @@ -49,7 +49,7 @@ describe("Manage User Profile", () => {

cy.verifyNotification("Details updated successfully");

userProfilePage.assertAge(age);
userProfilePage.assertdate_of_birth("1999-01-01");
userProfilePage.assertGender(gender);
userProfilePage.assertEmail(email);
userProfilePage.assertPhone(phone);
Expand Down
5 changes: 4 additions & 1 deletion cypress/pageobject/Users/UserCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ export class UserCreationPage {
.click()
.type(value);
}

typeIntoElementByIdPostClearDob(elementId: string, value: string) {
cy.get("#" + elementId).click();
cy.get("#date-input").clear().type(value);
}
clearIntoElementById(elementId: string) {
cy.get("#" + elementId)
.click()
Expand Down
15 changes: 11 additions & 4 deletions cypress/pageobject/Users/UserProfilePage.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { cy } from "local-cypress";

export default class UserProfilePage {
assertVideoConnectLink(link: string) {
cy.get("#videoconnectlink-profile-details").should("contain.text", link);
Expand All @@ -15,8 +17,10 @@ export default class UserProfilePage {
cy.get("#submit").click();
}

typeAge(age: string) {
cy.get("#age").click().clear().type(age);
typedate_of_birth(date_of_birth: string) {
//check
cy.get("#date_of_birth").click();
cy.get("#date-input").clear().type(date_of_birth);
}

selectGender(gender: string) {
Expand Down Expand Up @@ -55,8 +59,11 @@ export default class UserProfilePage {
.type(medicalCouncilRegistration);
};

assertAge(age: string) {
cy.get("#age-profile-details").should("contain.text", age);
assertdate_of_birth(date_of_birth: string) {
cy.get("#date_of_birth-profile-details").should(
"contain.text",
date_of_birth
);
}

assertGender(gender: string) {
Expand Down
32 changes: 14 additions & 18 deletions src/Components/Users/UserProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import * as Notification from "../../Utils/Notifications.js";
import LanguageSelector from "../../Components/Common/LanguageSelector";
import TextFormField from "../Form/FormFields/TextFormField";
import ButtonV2, { Submit } from "../Common/components/ButtonV2";
import { classNames, isValidUrl, parsePhoneNumber } from "../../Utils/utils";
import {
classNames,
dateQueryString,
isValidUrl,
parsePhoneNumber,
} from "../../Utils/utils";
import CareIcon from "../../CAREUI/icons/CareIcon";
import PhoneNumberFormField from "../Form/FormFields/PhoneNumberFormField";
import { FieldChangeEvent } from "../Form/FormFields/Utils";
Expand Down Expand Up @@ -190,10 +195,11 @@ export default function UserProfile() {
return;
case "date_of_birth":
if (!states.form[field]) {
errors[field] = "Field is required";
errors[field] = "Enter a valid date of birth";
invalidForm = true;
} else if (
dayjs(states.form[field]).isAfter(dayjs().subtract(1, "year"))
!dayjs(states.form[field]).isValid() ||
dayjs(states.form[field]).isAfter(dayjs().subtract(17, "year"))
) {
errors[field] = "Enter a valid date of birth";
invalidForm = true;
Expand Down Expand Up @@ -294,17 +300,6 @@ export default function UserProfile() {
form: { ...states.form, [event.name]: event.value },
});
};
const handleDateChange = (e: FieldChangeEvent<Date>) => {
if (dayjs(e.value).isValid()) {
dispatch({
type: "set_form",
form: {
...states.form,
[e.name]: dayjs(e.value).format("YYYY-MM-DD"),
},
});
}
};

const getDate = (value: any) =>
value && dayjs(value).isValid() && dayjs(value).toDate();
Expand Down Expand Up @@ -332,7 +327,7 @@ export default function UserProfile() {
phone_number: parsePhoneNumber(states.form.phoneNumber) ?? "",
alt_phone_number: parsePhoneNumber(states.form.altPhoneNumber) ?? "",
gender: states.form.gender,
date_of_birth: states.form.date_of_birth,
date_of_birth: dateQueryString(states.form.date_of_birth),
doctor_qualification:
states.form.user_type === "Doctor"
? states.form.doctor_qualification
Expand Down Expand Up @@ -531,7 +526,10 @@ export default function UserProfile() {
{userData?.last_name || "-"}
</dd>
</div>
<div className="my-2 sm:col-span-1" id="age-profile-details">
<div
className="my-2 sm:col-span-1"
id="date_of_birth-profile-details"
>
<dt className="text-sm font-medium leading-5 text-black">
Date of Birth
</dt>
Expand Down Expand Up @@ -663,10 +661,8 @@ export default function UserProfile() {
<DateFormField
{...fieldProps("date_of_birth")}
label="Date of Birth"
required
className="col-span-6 sm:col-span-3"
value={getDate(states.form.date_of_birth)}
onChange={handleDateChange}
position="LEFT"
disableFuture={true}
/>
Expand Down

0 comments on commit 9b9f137

Please sign in to comment.