Skip to content

Commit

Permalink
Merge branch 'develop' into issues/ohcnetwork#7309/weekly-hours-btn
Browse files Browse the repository at this point in the history
  • Loading branch information
kabirrajsingh authored Mar 28, 2024
2 parents 21f840d + b3263bd commit d679ca1
Show file tree
Hide file tree
Showing 129 changed files with 1,095 additions and 646 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",
"Please enter date in DD/MM/YYYY format",
"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",
"01/01/1998"
);
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("01/01/1999");
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
94 changes: 94 additions & 0 deletions plugins/treeShakeCareIcons.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { Plugin } from "vite";
import * as fs from "fs";
import * as path from "path";
import * as glob from "glob";

/**
* Interface defining options for the treeShakeUniconPathsPlugin.
*
* @interface TreeShakeUniconPathsPluginOptions
* @property {string[]} iconWhitelist - An array of icon names to always include, even if not found in code.
*/

export interface TreeShakeCareIconsOptions {
iconWhitelist: string[];
}

/**
* Creates a Webpack plugin that tree-shakes unused Unicon paths from UniconPaths.json in production builds.
*
* @param {TreeShakeCareIconsOptions} [options] - Optional configuration options. Defaults to an empty iconWhitelist.
* @returns {Plugin} Webpack plugin object.
*/

export function treeShakeCareIcons(
options: TreeShakeCareIconsOptions = { iconWhitelist: [] }
): Plugin {
const rootDir = path.resolve(__dirname, ".."); // update this if moving this code to a different file
const lineIconNameRegex = /"l-[a-z]+(?:-[a-z]+)*"/g;
const allUniconPaths = JSON.parse(
fs.readFileSync(
path.resolve(rootDir, "src/CAREUI/icons/UniconPaths.json"),
"utf8"
)
);

// Extracts icon names from a given file's content.
// Returns an array of icon names like ["l-eye", "l-sync", "l-hearbeat"]
function extractCareIconNames(file: string): string[] {
const fileContent = fs.readFileSync(file, "utf8");

const lineIconNameMatches = fileContent.match(lineIconNameRegex) || [];

const lineIconNames = lineIconNameMatches.map(
(lineIconName) => lineIconName.slice(1, -1) // remove quotes
);

return lineIconNames;
}
// Finds all used icon names within the project's source files (`.tsx` or `.res` extensions).
function getAllUsedIconNames() {
const files = glob.sync(path.resolve(rootDir, "src/**/*.{tsx,res}"));
const usedIconsArray: string[] = [];

files.forEach((file) => {
const iconNames = extractCareIconNames(file);
usedIconsArray.push(...iconNames);
});

return new Set(usedIconsArray);
}
// Generates a map of used icon names to their paths from UniconPaths.json, including any whitelisted icons.
function getTreeShakenUniconPaths() {
const usedIcons = [...getAllUsedIconNames(), ...options.iconWhitelist];
const treeshakenCareIconPaths = {};

for (const iconName of usedIcons) {
const path = allUniconPaths[iconName];
if (path === undefined) {
throw new Error(`Icon ${iconName} is not found in UniconPaths.json`);
} else {
treeshakenCareIconPaths[iconName] = path;
}
}

return treeshakenCareIconPaths;
}

return {
name: "tree-shake-care-icons",
transform(_src, id) {
if (process.env.NODE_ENV !== "production") {
return;
}

// Replace the UniconPaths with the tree-shaken version
if (id.endsWith("UniconPaths.json")) {
return {
code: `export default ${JSON.stringify(getTreeShakenUniconPaths())}`,
map: null,
};
}
},
};
}
4 changes: 2 additions & 2 deletions src/CAREUI/display/RecordMeta.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const RecordMeta = ({
{user && !inlineUser && (
<span className="flex items-center gap-1">
by
<CareIcon className="care-l-user" />
<CareIcon icon="l-user" />
{formatName(user)}
{isOnline && (
<div className="h-1.5 w-1.5 rounded-full bg-primary-400" />
Expand All @@ -61,7 +61,7 @@ const RecordMeta = ({
{prefix}
{child}
{user && inlineUser && <span>by</span>}
{user && !inlineUser && <CareIcon className="care-l-user" />}
{user && !inlineUser && <CareIcon icon="l-user" />}
{user && inlineUser && (
<span className="font-medium">{formatName(user)}</span>
)}
Expand Down
2 changes: 1 addition & 1 deletion src/CAREUI/display/SubHeading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function SubHeading(props: Props) {
</span>
{props.lastModified && (
<div className="ml-3 flex flex-row gap-2 text-xs font-medium text-gray-600">
<CareIcon className="care-l-history-alt text-sm" />
<CareIcon icon="l-history-alt" className="text-sm" />
<RecordMeta time={props.lastModified} prefix="Last modified" />
</div>
)}
Expand Down
4 changes: 2 additions & 2 deletions src/CAREUI/icons/CareIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import iconData from "./UniconPaths.json";
export type IconName = keyof typeof iconData;

export interface CareIconProps {
icon?: IconName;
icon: IconName;
className?: string | undefined;
onClick?: React.MouseEventHandler<HTMLSpanElement> | undefined;
id?: string;
Expand All @@ -16,7 +16,7 @@ export interface CareIconProps {
* ### CARE's Official Icon Library.
* @param className icon class name
* @returns icon component
* @example ```<CareIcon className="care-l-hospital" /> ```
* @example ```<CareIcon icon="l-hospital"/> ```
*
* @see [icon library](https://iconscout.com/unicons/)
*/
Expand Down
4 changes: 2 additions & 2 deletions src/CAREUI/interactive/FiltersSlideover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function FiltersSlideover({
onClick={onClear}
id="clear-filter"
>
<CareIcon className="care-l-filter-slash text-lg" />
<CareIcon icon="l-filter-slash" className="text-lg" />
<span>{t("clear")}</span>
</ButtonV2>
<ButtonV2 ghost onClick={onApply} id="apply-filter">
Expand All @@ -62,7 +62,7 @@ export const AdvancedFilterButton = ({ onClick }: { onClick: () => void }) => {
onClick={onClick}
id="advanced-filter"
>
<CareIcon className="care-l-filter" />
<CareIcon icon="l-filter" />
<span className="py-0.5">{t("advanced_filters")}</span>
</ButtonV2>
);
Expand Down
3 changes: 2 additions & 1 deletion src/CAREUI/interactive/LegendInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ export default function LegendInput(props: InputProps) {
onClick={() => setShowPassword(!showPassword)}
>
<CareIcon
className={`care-l-eye${showPassword ? "" : "-slash"} text-lg`}
icon={showPassword ? "l-eye" : "l-eye-slash"}
className="text-lg"
/>
</button>
)}
Expand Down
2 changes: 1 addition & 1 deletion src/CAREUI/interactive/SlideOver.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export default function SlideOver({
onCloseClick && onCloseClick();
}}
>
<CareIcon className="care-l-arrow-left" />
<CareIcon icon="l-arrow-left" />
</button>
<div className="flex w-full">
<h1 className="w-full text-xl font-black">{title}</h1>
Expand Down
2 changes: 1 addition & 1 deletion src/Common/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ export const GENDER: { [key: number]: string } = GENDER_TYPES.reduce(
);

export type CameraPTZ = {
icon?: string;
icon?: IconName;
label: string;
action: string;
loadingLabel?: string;
Expand Down
2 changes: 1 addition & 1 deletion src/Common/hooks/useRangePagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const useRangePagination = ({ bounds, perPage, ...props }: Props) => {

useEffect(() => {
setCurrentRange(getInitialBounds(bounds, perPage, props.defaultEnd));
}, [bounds, perPage, props.defaultEnd]);
}, [JSON.stringify(bounds), perPage, props.defaultEnd]);

const next = () => {
const { end } = currentRange;
Expand Down
6 changes: 4 additions & 2 deletions src/Components/ABDM/ABHAProfileModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@ const ABHAProfileModal = ({ patientId, show, onClose, abha }: IProps) => {
<div className="flex items-center gap-2">
<CareIcon
onClick={() => downloadAbhaCard("pdf")}
className="care-l-print cursor-pointer"
icon="l-print"
className="cursor-pointer"
/>
<CareIcon
onClick={() => downloadAbhaCard("png")}
className="care-l-import cursor-pointer"
icon="l-import"
className="cursor-pointer"
/>
</div>
</div>
Expand Down
6 changes: 3 additions & 3 deletions src/Components/ABDM/LinkABHANumberModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default function LinkABHANumberModal({

const title = (
<div className="flex items-center gap-3">
<CareIcon className="care-l-link text-xl" />
<CareIcon icon="l-link" className="text-xl" />
<h2 className="text-xl font-bold text-black">
{currentStep === "ScanExistingQR"
? "Link Existing ABHA Number"
Expand Down Expand Up @@ -752,7 +752,7 @@ const VerifyMobileSection = ({
/>
) : (
<p className="-mt-4 text-sm text-warning-600">
<CareIcon className="care-l-exclamation-triangle h-4 w-4" /> OTP is
<CareIcon icon="l-exclamation-triangle" className="h-4 w-4" /> OTP is
generated if the above phone number is not linked with given Aadhaar
number.
</p>
Expand Down Expand Up @@ -833,7 +833,7 @@ const CreateHealthIDSection = ({
/>

<p className="-mt-4 text-sm text-warning-600">
<CareIcon className="care-l-exclamation-triangle h-4 w-4" /> Existing
<CareIcon icon="l-exclamation-triangle" className="h-4 w-4" /> Existing
ABHA Address is used if ABHA Number already exists.
</p>

Expand Down
Loading

0 comments on commit d679ca1

Please sign in to comment.