Skip to content

Commit

Permalink
fix(user): added optional value to localbody field
Browse files Browse the repository at this point in the history
  • Loading branch information
aeswibon committed Dec 25, 2022
1 parent b5eb5d2 commit 03fd901
Show file tree
Hide file tree
Showing 5 changed files with 200 additions and 191 deletions.
27 changes: 13 additions & 14 deletions cypress/e2e/users_spec/user_crud.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const makeid = (length: number) => {
};

const makePhoneNumber = () =>
"9199" + Math.floor(Math.random() * 99999999).toString();
"98" + Math.floor(Math.random() * 99999999).toString();

const username = makeid(25);
const phone_number = makePhoneNumber();
Expand Down Expand Up @@ -41,29 +41,28 @@ describe("User management", () => {
cy.intercept(/\/api\/v1\/facility/).as("facility");
cy.get("[name='facilities']").type("Mysore").wait("@facility");
cy.get("[name='facilities']").type("{downarrow}{enter}");
cy.get("input[type='checkbox']").click();
cy.get("[placeholder='Phone Number']").type(phone_number);
cy.get("[placeholder='WhatsApp Phone Number']").type(alt_phone_number, {
force: true,
});
cy.intercept(/users/).as("check_availability");
cy.get("[name='username']").type(username, { force: true });
cy.get("[id='date_of_birth']").click();
cy.get("div").contains("20").click();
cy.get("[id='year-0']").click();
cy.get("[id='date-1']").click();
cy.wait("@check_availability").its("response.statusCode").should("eq", 200);
cy.get("[name='password']").type("#@Cypress_test123");
cy.get("[name='c_password']").type("#@Cypress_test123");
cy.get("[name='first_name']").type("Cypress Test");
cy.get("[name='last_name']").type("Tester");
cy.get("[name='email']").type("cypress@tester.com");
cy.get("[id='gender'] > div > button").click();
cy.get("div").contains("Male").click();
cy.get("[id='date_of_birth']").click();
cy.get("div").contains("20").click();
cy.get("body").click(700, 450);
cy.get("body").click(720, 470);
cy.get("input[type='checkbox']").click();
cy.wait(1000);
cy.get("[placeholder='Phone Number']").type(phone_number);
cy.wait(1000);
cy.get("[placeholder='WhatsApp Phone Number']").type(alt_phone_number, {
cy.get("button[id='submit']").contains("Save User").click({
force: true,
});
cy.wait(1000);
cy.get("[name='email']").type("cypress@tester.com");
cy.get("button[id='submit']").contains("Save User").click();
cy.verifyNotification("User added successfully");
});

Expand All @@ -72,10 +71,10 @@ describe("User management", () => {
cy.get("[name='first_name']").type("Cypress Test");
cy.get("[name='last_name']").type("Tester");
cy.get("[placeholder='Phone Number']").type(phone_number);
cy.get("input[name='district']").type("Ernakulam");
cy.get("[placeholder='WhatsApp Phone Number']").type(alt_phone_number);
cy.contains("Apply").click();
cy.get("[name='username']").type(username, { force: true });
// TODO: some verify task
});

it("link facility for user", () => {
Expand Down
16 changes: 13 additions & 3 deletions src/Components/Common/DateInputV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,12 @@ const DateInputV2: React.FC<Props> = ({
{type === "date" && (
<>
<div className="flex flex-wrap mb-3">
{DAYS.map((day) => (
<div key={day} className="aspect-square w-[14.26%]">
{DAYS.map((day, i) => (
<div
key={day}
id={`day-${i}`}
className="aspect-square w-[14.26%]"
>
<div className="text-gray-800 font-medium text-center text-sm">
{day}
</div>
Expand All @@ -268,7 +272,11 @@ const DateInputV2: React.FC<Props> = ({
/>
))}
{dayCount.map((d, i) => (
<div key={i} className="aspect-square w-[14.26%]">
<div
key={i}
id={`date-${d}`}
className="aspect-square w-[14.26%]"
>
<div
onClick={setDateValue(d)}
className={classNames(
Expand All @@ -293,6 +301,7 @@ const DateInputV2: React.FC<Props> = ({
.map((_, i) => (
<div
key={i}
id={`month-${i}`}
className={classNames(
"cursor-pointer w-1/4 font-semibold py-4 px-2 text-center text-sm rounded-lg",
value && isSelectedMonth(i)
Expand Down Expand Up @@ -322,6 +331,7 @@ const DateInputV2: React.FC<Props> = ({
return (
<div
key={i}
id={`year-${i}`}
className={classNames(
"cursor-pointer w-1/4 font-semibold py-4 px-2 text-center text-sm rounded-lg",
value && isSelectedYear(y)
Expand Down
75 changes: 42 additions & 33 deletions src/Components/Form/SelectMenuV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Listbox } from "@headlessui/react";
import { DropdownTransition } from "../Common/components/HelperComponents";
import CareIcon from "../../CAREUI/icons/CareIcon";
import { dropdownOptionClassNames } from "./MultiSelectMenuV2";
import { classNames } from "../../Utils/utils";

type OptionCallback<T, R> = (option: T) => R;

Expand All @@ -12,6 +13,7 @@ type SelectMenuProps<T, V = T> = {
disabled?: boolean | undefined;
value: V | undefined;
placeholder?: React.ReactNode;
position?: "above" | "below";
optionLabel: OptionCallback<T, React.ReactNode>;
optionSelectedLabel?: OptionCallback<T, React.ReactNode>;
optionDescription?: OptionCallback<T, React.ReactNode>;
Expand Down Expand Up @@ -99,40 +101,47 @@ const SelectMenuV2 = <T, V>(props: SelectMenuProps<T, V>) => {
)}
</div>
</Listbox.Button>
<DropdownTransition show={open}>
<Listbox.Options className="cui-dropdown-base origin-top-right absolute mt-0.5">
{options.map((option, index) => (
<Listbox.Option
id={`${props.id}-option-${option.value}`}
key={index}
className={dropdownOptionClassNames}
value={option}
>
{({ active, selected }) => (
<div className="flex flex-col gap-2">
<div className="flex justify-between">
{option.label}
{props.optionIcon
? option.icon
: selected && (
<CareIcon className="care-l-check text-lg" />
)}
<div
className={classNames(
"absolute z-10 w-full",
props.position === "above" ? "bottom-0 mb-14" : "top-0 mt-14"
)}
>
<DropdownTransition show={open}>
<Listbox.Options className="cui-dropdown-base origin-top-right absolute mt-0.5">
{options.map((option, index) => (
<Listbox.Option
id={`${props.id}-option-${option.value}`}
key={index}
className={dropdownOptionClassNames}
value={option}
>
{({ active, selected }) => (
<div className="flex flex-col gap-2">
<div className="flex justify-between">
{option.label}
{props.optionIcon
? option.icon
: selected && (
<CareIcon className="care-l-check text-lg" />
)}
</div>
{option.description && (
<p
className={`font-normal ${
active ? "text-primary-200" : "text-gray-700"
}`}
>
{option.description}
</p>
)}
</div>
{option.description && (
<p
className={`font-normal ${
active ? "text-primary-200" : "text-gray-700"
}`}
>
{option.description}
</p>
)}
</div>
)}
</Listbox.Option>
))}
</Listbox.Options>
</DropdownTransition>
)}
</Listbox.Option>
))}
</Listbox.Options>
</DropdownTransition>
</div>
</div>
</>
)}
Expand Down
Loading

0 comments on commit 03fd901

Please sign in to comment.