diff --git a/__tests__/ActionCell.test.tsx b/__tests__/ActionCell.test.tsx
index cbe4e451..471fd129 100644
--- a/__tests__/ActionCell.test.tsx
+++ b/__tests__/ActionCell.test.tsx
@@ -1,28 +1,31 @@
-import ActionCell from '@/components/ActionCell';
-import { Edit as EditIcon, MoreVert as MoreVertIcon } from '@mui/icons-material';
-import { fireEvent, render, screen } from '@testing-library/react';
+import ActionCell from "@/components/ActionCell";
+import {
+ Edit as EditIcon,
+ MoreVert as MoreVertIcon,
+} from "@mui/icons-material";
+import { fireEvent, render, screen } from "@testing-library/react";
// Mock the translation hook
-jest.mock('next-i18next', () => ({
+jest.mock("next-i18next", () => ({
useTranslation: () => ({
t: (key: string) => key,
}),
}));
-describe('ActionCell Component', () => {
- const mockRowData = { id: 1, name: 'Sample Row' };
+describe("ActionCell Component", () => {
+ const mockRowData = { id: 1, name: "Sample Row" };
const mockOnEdit = jest.fn();
const mockOnDelete = jest.fn();
const mockExtraAction = jest.fn();
const extraActions = [
{
- name: 'edit',
+ name: "edit",
onClick: mockExtraAction,
icon: EditIcon,
},
{
- name: 'delete',
+ name: "delete",
onClick: mockOnDelete,
icon: MoreVertIcon,
},
@@ -36,45 +39,45 @@ describe('ActionCell Component', () => {
showIcons: true,
};
- it('should render without crashing', () => {
+ it("should render without crashing", () => {
render();
- const iconButton = screen.getByRole('button');
+ const iconButton = screen.getByRole("button");
expect(iconButton).toBeInTheDocument();
});
- it('should display MoreVertIcon button', () => {
+ it("should display MoreVertIcon button", () => {
render();
- const moreVertIcon = screen.getByRole('button');
+ const moreVertIcon = screen.getByRole("button");
expect(moreVertIcon).toBeInTheDocument();
});
- it('should open the menu on MoreVertIcon click', () => {
+ it("should open the menu on MoreVertIcon click", () => {
render();
- const moreVertIcon = screen.getByRole('button');
+ const moreVertIcon = screen.getByRole("button");
// Open the menu
fireEvent.click(moreVertIcon);
- const menuItem = screen.getAllByRole('menuitem');
+ const menuItem = screen.getAllByRole("menuitem");
expect(menuItem.length).toBe(extraActions.length);
});
- it('should display the correct number of actions in the menu', () => {
+ it("should display the correct number of actions in the menu", () => {
render();
- const moreVertIcon = screen.getByRole('button');
+ const moreVertIcon = screen.getByRole("button");
// Open the menu
fireEvent.click(moreVertIcon);
- const menuItems = screen.getAllByRole('menuitem');
+ const menuItems = screen.getAllByRole("menuitem");
expect(menuItems).toHaveLength(extraActions.length);
});
- it('should call the correct action when a menu item is clicked', () => {
+ it("should call the correct action when a menu item is clicked", () => {
render();
- const moreVertIcon = screen.getByRole('button');
+ const moreVertIcon = screen.getByRole("button");
// Open the menu
fireEvent.click(moreVertIcon);
- const menuItems = screen.getAllByRole('menuitem');
+ const menuItems = screen.getAllByRole("menuitem");
// Click the first action
fireEvent.click(menuItems[0]);
@@ -88,85 +91,85 @@ describe('ActionCell Component', () => {
expect(mockOnDelete).toHaveBeenCalledWith(mockRowData);
});
- it('should close the menu after an action is clicked', () => {
+ it("should close the menu after an action is clicked", () => {
render();
- const moreVertIcon = screen.getByRole('button');
+ const moreVertIcon = screen.getByRole("button");
// Open the menu
fireEvent.click(moreVertIcon);
- const menuItems = screen.getAllByRole('menuitem');
+ const menuItems = screen.getAllByRole("menuitem");
// Click the first action
fireEvent.click(menuItems[0]);
expect(mockExtraAction).toHaveBeenCalledWith(mockRowData);
// Menu should be closed
- expect(screen.queryByRole('menuitem')).not.toBeInTheDocument();
+ expect(screen.queryByRole("menuitem")).not.toBeInTheDocument();
});
- xit('should not display menu items if extraActions are empty', () => {
+ xit("should not display menu items if extraActions are empty", () => {
render();
- const moreVertIcon = screen.getByRole('button');
+ const moreVertIcon = screen.getByRole("button");
// Try to open the menu
fireEvent.click(moreVertIcon);
- expect(screen.queryByRole('menuitem')).not.toBeInTheDocument();
+ expect(screen.queryByRole("menuitem")).not.toBeInTheDocument();
});
- it('should not show icons when showIcons is false', () => {
+ it("should not show icons when showIcons is false", () => {
render();
- const moreVertIcon = screen.getByRole('button');
+ const moreVertIcon = screen.getByRole("button");
// Open the menu
fireEvent.click(moreVertIcon);
- const listItemIcons = screen.queryAllByRole('icon');
+ const listItemIcons = screen.queryAllByRole("icon");
expect(listItemIcons).toHaveLength(0); // Icons should not be displayed
});
- it('should display translated action names using useTranslation hook', () => {
+ it("should display translated action names using useTranslation hook", () => {
render();
- const moreVertIcon = screen.getByRole('button');
+ const moreVertIcon = screen.getByRole("button");
// Open the menu
fireEvent.click(moreVertIcon);
- const menuItems = screen.getAllByRole('menuitem');
+ const menuItems = screen.getAllByRole("menuitem");
// Check the translated action names
- expect(menuItems[0]).toHaveTextContent('edit');
- expect(menuItems[1]).toHaveTextContent('delete');
+ expect(menuItems[0]).toHaveTextContent("edit");
+ expect(menuItems[1]).toHaveTextContent("delete");
});
- xit('should handle no actions gracefully', () => {
+ xit("should handle no actions gracefully", () => {
render();
- const moreVertIcon = screen.getByRole('button');
+ const moreVertIcon = screen.getByRole("button");
expect(moreVertIcon).toBeInTheDocument();
// Try to open the menu
fireEvent.click(moreVertIcon);
- expect(screen.queryByRole('menuitem')).not.toBeInTheDocument();
+ expect(screen.queryByRole("menuitem")).not.toBeInTheDocument();
});
- it('should display actions without icons when showIcons is false', () => {
+ it("should display actions without icons when showIcons is false", () => {
render();
- const moreVertIcon = screen.getByRole('button');
+ const moreVertIcon = screen.getByRole("button");
// Open the menu
fireEvent.click(moreVertIcon);
- const menuItems = screen.getAllByRole('menuitem');
+ const menuItems = screen.getAllByRole("menuitem");
expect(menuItems.length).toBe(extraActions.length);
- const icons = screen.queryAllByRole('icon');
+ const icons = screen.queryAllByRole("icon");
expect(icons).toHaveLength(0);
});
- it('should correctly handle onEdit and onDelete props', () => {
+ it("should correctly handle onEdit and onDelete props", () => {
render();
- const moreVertIcon = screen.getByRole('button');
+ const moreVertIcon = screen.getByRole("button");
// Open the menu
fireEvent.click(moreVertIcon);
- const menuItems = screen.getAllByRole('menuitem');
+ const menuItems = screen.getAllByRole("menuitem");
// Click the first action (edit)
fireEvent.click(menuItems[0]);
@@ -180,27 +183,27 @@ describe('ActionCell Component', () => {
expect(mockOnDelete).toHaveBeenCalledWith(mockRowData);
});
- it('should display all extra actions', () => {
+ it("should display all extra actions", () => {
render();
- const moreVertIcon = screen.getByRole('button');
+ const moreVertIcon = screen.getByRole("button");
// Open the menu
fireEvent.click(moreVertIcon);
- const menuItems = screen.getAllByRole('menuitem');
+ const menuItems = screen.getAllByRole("menuitem");
expect(menuItems).toHaveLength(extraActions.length);
});
- xit('should render the correct icon for each action', () => {
+ xit("should render the correct icon for each action", () => {
render();
- const moreVertIcon = screen.getByRole('button');
+ const moreVertIcon = screen.getByRole("button");
// Open the menu
fireEvent.click(moreVertIcon);
// Check for each action icon
extraActions.forEach((action) => {
- const iconElement = screen.getByTestId(action.name + '-icon');
+ const iconElement = screen.getByTestId(action.name + "-icon");
expect(iconElement).toBeInTheDocument();
});
});
diff --git a/__tests__/CardItem.test.tsx b/__tests__/CardItem.test.tsx
index 9208b838..4b9f9deb 100644
--- a/__tests__/CardItem.test.tsx
+++ b/__tests__/CardItem.test.tsx
@@ -54,7 +54,7 @@ describe("CardItem Component", () => {
it("should display the correct progress", () => {
render();
const progressText = screen.getByText(
- `${defaultProps.card.boardsUploaded} / ${defaultProps.card.totalBoards} COURSE_PLANNER.BOARDS_FULLY_UPLOADED`
+ `${defaultProps.card.boardsUploaded} / ${defaultProps.card.totalBoards} COURSE_PLANNER.BOARDS_FULLY_UPLOADED`,
);
expect(progressText).toBeInTheDocument();
});
@@ -62,7 +62,9 @@ describe("CardItem Component", () => {
it("should render CustomStepper with the correct completed steps", () => {
render();
const stepper = screen.getByTestId("custom-stepper");
- expect(stepper).toHaveTextContent(`Stepper: ${defaultProps.card.boardsUploaded}`);
+ expect(stepper).toHaveTextContent(
+ `Stepper: ${defaultProps.card.boardsUploaded}`,
+ );
});
xit("should call onClick handler when the card is clicked", () => {
diff --git a/__tests__/Helper.test.ts b/__tests__/Helper.test.ts
index de45edd1..01199baa 100644
--- a/__tests__/Helper.test.ts
+++ b/__tests__/Helper.test.ts
@@ -1,19 +1,26 @@
-import { capitalizeFirstLetterOfEachWordInArray, fieldTextValidation, firstLetterInUpperCase, generateUsernameAndPassword, transformArray, transformLabel } from '@/utils/Helper';
-import { State } from '@/utils/Interfaces';
-import { Role } from '@/utils/app.constant';
-import '@testing-library/jest-dom';
+import {
+ capitalizeFirstLetterOfEachWordInArray,
+ fieldTextValidation,
+ firstLetterInUpperCase,
+ generateUsernameAndPassword,
+ transformArray,
+ transformLabel,
+} from "@/utils/Helper";
+import { State } from "@/utils/Interfaces";
+import { Role } from "@/utils/app.constant";
+import "@testing-library/jest-dom";
-describe('generateUsernameAndPassword', () => {
+describe("generateUsernameAndPassword", () => {
// Mock Date to control current year
const mockDate = new Date(2024, 7, 3);
- jest.spyOn(global, 'Date').mockImplementation(() => mockDate);
+ jest.spyOn(global, "Date").mockImplementation(() => mockDate);
afterEach(() => {
jest.clearAllMocks();
});
- it('should generate username and password for a valid role and state code', () => {
- const stateCode = 'CA';
+ it("should generate username and password for a valid role and state code", () => {
+ const stateCode = "CA";
const role = Role.TEACHER;
const result = generateUsernameAndPassword(stateCode, role);
@@ -22,10 +29,10 @@ describe('generateUsernameAndPassword', () => {
expect(result?.password).toMatch(/^\d{5}$/); // Match 5 random digits
});
- it('should return null and log a warning for an invalid role', () => {
- const stateCode = 'NY';
- const role = 'INVALID_ROLE';
- const consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation();
+ it("should return null and log a warning for an invalid role", () => {
+ const stateCode = "NY";
+ const role = "INVALID_ROLE";
+ const consoleWarnSpy = jest.spyOn(console, "warn").mockImplementation();
const result = generateUsernameAndPassword(stateCode, role);
@@ -33,32 +40,32 @@ describe('generateUsernameAndPassword', () => {
expect(consoleWarnSpy).toHaveBeenCalledWith(`Unknown role: ${role}`);
});
- it('should generate a 5-digit random password', () => {
- const stateCode = 'TX';
+ it("should generate a 5-digit random password", () => {
+ const stateCode = "TX";
const role = Role.STUDENT;
const result = generateUsernameAndPassword(stateCode, role);
expect(result?.password).toMatch(/^\d{5}$/);
});
- it('should generate username with correct prefix for TEACHER role', () => {
- const stateCode = 'FL';
+ it("should generate username with correct prefix for TEACHER role", () => {
+ const stateCode = "FL";
const role = Role.TEACHER;
const result = generateUsernameAndPassword(stateCode, role);
expect(result?.username).toMatch(/^FSCFL24\d{5}$/); // Match FSC, FL, 24 (year), and 5 random digits
});
- it('should generate username with correct prefix for STUDENT role', () => {
- const stateCode = 'NV';
+ it("should generate username with correct prefix for STUDENT role", () => {
+ const stateCode = "NV";
const role = Role.STUDENT;
const result = generateUsernameAndPassword(stateCode, role);
expect(result?.username).toMatch(/^SCNV24\d{5}$/); // Match SC, NV, 24 (year), and 5 random digits
});
- it('should generate username with correct prefix for TEAM_LEADER role', () => {
- const stateCode = 'OH';
+ it("should generate username with correct prefix for TEAM_LEADER role", () => {
+ const stateCode = "OH";
const role = Role.TEAM_LEADER;
const result = generateUsernameAndPassword(stateCode, role);
@@ -66,356 +73,381 @@ describe('generateUsernameAndPassword', () => {
});
});
+describe("fieldTextValidation", () => {
+ it("should return true for a valid text containing only alphabets and spaces", () => {
+ expect(fieldTextValidation("Hello World")).toBe(true);
+ expect(fieldTextValidation("This is a Test")).toBe(true);
+ expect(fieldTextValidation("OpenAI ChatGPT")).toBe(true);
+ });
+
+ it("should return false for text containing numbers", () => {
+ expect(fieldTextValidation("Hello123")).toBe(false);
+ expect(fieldTextValidation("2024")).toBe(false);
+ expect(fieldTextValidation("Text with 123 numbers")).toBe(false);
+ });
+
+ it("should return false for text containing special characters", () => {
+ expect(fieldTextValidation("Hello@World")).toBe(false);
+ expect(fieldTextValidation("Test!")).toBe(false);
+ expect(fieldTextValidation("Hello#")).toBe(false);
+ });
+
+ it("should return true for text with mixed case alphabets", () => {
+ expect(fieldTextValidation("Hello")).toBe(true);
+ expect(fieldTextValidation("hello")).toBe(true);
+ expect(fieldTextValidation("HELLO")).toBe(true);
+ });
+
+ it("should return true for text with leading and trailing spaces", () => {
+ expect(fieldTextValidation(" Leading")).toBe(true);
+ expect(fieldTextValidation("Trailing ")).toBe(true);
+ expect(fieldTextValidation(" Both ")).toBe(true);
+ });
+
+ it("should return false for empty string", () => {
+ expect(fieldTextValidation("")).toBe(false);
+ });
+
+ it("should return true for single space", () => {
+ expect(fieldTextValidation(" ")).toBe(true);
+ });
+
+ it("should return true for multiple spaces", () => {
+ expect(fieldTextValidation(" ")).toBe(true);
+ });
+
+ it("should return true for strings with only alphabetic characters", () => {
+ expect(fieldTextValidation("abc")).toBe(true);
+ expect(fieldTextValidation("ABC")).toBe(true);
+ expect(fieldTextValidation("AbC")).toBe(true);
+ });
+
+ it("should return false for strings with underscores or hyphens", () => {
+ expect(fieldTextValidation("Hello_World")).toBe(false);
+ expect(fieldTextValidation("Hello-World")).toBe(false);
+ });
+});
+
+describe("capitalizeFirstLetterOfEachWordInArray", () => {
+ it("should capitalize the first letter of each word in every string of the array", () => {
+ const input = ["hello world", "this is a test", "openai chatgpt"];
+ const expectedOutput = ["Hello World", "This Is A Test", "Openai Chatgpt"];
+ expect(capitalizeFirstLetterOfEachWordInArray(input)).toEqual(
+ expectedOutput,
+ );
+ });
+
+ it("should handle single word strings", () => {
+ const input = ["hello", "world"];
+ const expectedOutput = ["Hello", "World"];
+ expect(capitalizeFirstLetterOfEachWordInArray(input)).toEqual(
+ expectedOutput,
+ );
+ });
+
+ it("should handle empty strings within the array", () => {
+ const input = ["", "hello world", ""];
+ const expectedOutput = ["", "Hello World", ""];
+ expect(capitalizeFirstLetterOfEachWordInArray(input)).toEqual(
+ expectedOutput,
+ );
+ });
+
+ it("should handle arrays with single character words", () => {
+ const input = ["a b c", "d e f"];
+ const expectedOutput = ["A B C", "D E F"];
+ expect(capitalizeFirstLetterOfEachWordInArray(input)).toEqual(
+ expectedOutput,
+ );
+ });
+
+ it("should handle strings with multiple spaces between words", () => {
+ const input = ["hello world", "this is a test"];
+ const expectedOutput = ["Hello World", "This Is A Test"];
+ expect(capitalizeFirstLetterOfEachWordInArray(input)).toEqual(
+ expectedOutput,
+ );
+ });
+
+ it("should not affect already capitalized words", () => {
+ const input = ["Hello World", "Already Capitalized"];
+ const expectedOutput = ["Hello World", "Already Capitalized"];
+ expect(capitalizeFirstLetterOfEachWordInArray(input)).toEqual(
+ expectedOutput,
+ );
+ });
+
+ it("should handle strings with special characters", () => {
+ const input = ["hello-world", "openai@chatgpt"];
+ const expectedOutput = ["Hello-World", "Openai@Chatgpt"];
+ expect(capitalizeFirstLetterOfEachWordInArray(input)).toEqual(
+ expectedOutput,
+ );
+ });
+
+ it("should handle mixed case words", () => {
+ const input = ["hElLo WoRlD", "OpEnAi ChAtGpT"];
+ const expectedOutput = ["HElLo WoRlD", "OpEnAi ChAtGpT"];
+ expect(capitalizeFirstLetterOfEachWordInArray(input)).toEqual(
+ expectedOutput,
+ );
+ });
+
+ it("should handle an empty array", () => {
+ const input: string[] = [];
+ const expectedOutput: string[] = [];
+ expect(capitalizeFirstLetterOfEachWordInArray(input)).toEqual(
+ expectedOutput,
+ );
+ });
+
+ it("should handle an array with empty strings only", () => {
+ const input = ["", "", ""];
+ const expectedOutput = ["", "", ""];
+ expect(capitalizeFirstLetterOfEachWordInArray(input)).toEqual(
+ expectedOutput,
+ );
+ });
+
+ it("should handle arrays with non-alphabetic characters", () => {
+ const input = ["123 abc", "$%^ abc", "123"];
+ const expectedOutput = ["123 Abc", "$%^ Abc", "123"];
+ expect(capitalizeFirstLetterOfEachWordInArray(input)).toEqual(
+ expectedOutput,
+ );
+ });
+});
+
+describe("firstLetterInUpperCase", () => {
+ it("should capitalize the first letter of each word in a single-word string", () => {
+ expect(firstLetterInUpperCase("hello")).toBe("Hello");
+ expect(firstLetterInUpperCase("world")).toBe("World");
+ });
+
+ it("should capitalize the first letter of each word in a multi-word string", () => {
+ expect(firstLetterInUpperCase("hello world")).toBe("Hello World");
+ expect(firstLetterInUpperCase("this is a test")).toBe("This Is A Test");
+ expect(firstLetterInUpperCase("openai chatgpt")).toBe("Openai Chatgpt");
+ });
+
+ it("should return null for an empty string", () => {
+ expect(firstLetterInUpperCase("")).toBeNull();
+ });
+
+ it("should handle strings with leading and trailing spaces", () => {
+ expect(firstLetterInUpperCase(" leading")).toBe(" Leading");
+ expect(firstLetterInUpperCase("trailing ")).toBe("Trailing ");
+ expect(firstLetterInUpperCase(" both ")).toBe(" Both ");
+ });
+
+ it("should handle strings with multiple spaces between words", () => {
+ expect(firstLetterInUpperCase("hello world")).toBe("Hello World");
+ expect(firstLetterInUpperCase("this is a test")).toBe(
+ "This Is A Test",
+ );
+ });
+
+ it("should not affect already capitalized words", () => {
+ expect(firstLetterInUpperCase("Hello World")).toBe("Hello World");
+ expect(firstLetterInUpperCase("Already Capitalized")).toBe(
+ "Already Capitalized",
+ );
+ });
+
+ it("should handle mixed case words", () => {
+ expect(firstLetterInUpperCase("hElLo WoRlD")).toBe("HElLo WoRlD");
+ expect(firstLetterInUpperCase("OpEnAi ChAtGpT")).toBe("OpEnAi ChAtGpT");
+ });
+
+ it("should handle single-character words", () => {
+ expect(firstLetterInUpperCase("a b c")).toBe("A B C");
+ expect(firstLetterInUpperCase("x y z")).toBe("X Y Z");
+ });
+
+ it("should return null for a null input", () => {
+ expect(firstLetterInUpperCase(null as unknown as string)).toBeNull();
+ });
-describe('fieldTextValidation', () => {
- it('should return true for a valid text containing only alphabets and spaces', () => {
- expect(fieldTextValidation('Hello World')).toBe(true);
- expect(fieldTextValidation('This is a Test')).toBe(true);
- expect(fieldTextValidation('OpenAI ChatGPT')).toBe(true);
- });
-
- it('should return false for text containing numbers', () => {
- expect(fieldTextValidation('Hello123')).toBe(false);
- expect(fieldTextValidation('2024')).toBe(false);
- expect(fieldTextValidation('Text with 123 numbers')).toBe(false);
- });
-
- it('should return false for text containing special characters', () => {
- expect(fieldTextValidation('Hello@World')).toBe(false);
- expect(fieldTextValidation('Test!')).toBe(false);
- expect(fieldTextValidation('Hello#')).toBe(false);
- });
-
- it('should return true for text with mixed case alphabets', () => {
- expect(fieldTextValidation('Hello')).toBe(true);
- expect(fieldTextValidation('hello')).toBe(true);
- expect(fieldTextValidation('HELLO')).toBe(true);
- });
-
- it('should return true for text with leading and trailing spaces', () => {
- expect(fieldTextValidation(' Leading')).toBe(true);
- expect(fieldTextValidation('Trailing ')).toBe(true);
- expect(fieldTextValidation(' Both ')).toBe(true);
- });
-
- it('should return false for empty string', () => {
- expect(fieldTextValidation('')).toBe(false);
- });
-
- it('should return true for single space', () => {
- expect(fieldTextValidation(' ')).toBe(true);
- });
-
- it('should return true for multiple spaces', () => {
- expect(fieldTextValidation(' ')).toBe(true);
- });
-
- it('should return true for strings with only alphabetic characters', () => {
- expect(fieldTextValidation('abc')).toBe(true);
- expect(fieldTextValidation('ABC')).toBe(true);
- expect(fieldTextValidation('AbC')).toBe(true);
- });
-
- it('should return false for strings with underscores or hyphens', () => {
- expect(fieldTextValidation('Hello_World')).toBe(false);
- expect(fieldTextValidation('Hello-World')).toBe(false);
- });
- });
-
- describe('capitalizeFirstLetterOfEachWordInArray', () => {
- it('should capitalize the first letter of each word in every string of the array', () => {
- const input = ['hello world', 'this is a test', 'openai chatgpt'];
- const expectedOutput = ['Hello World', 'This Is A Test', 'Openai Chatgpt'];
- expect(capitalizeFirstLetterOfEachWordInArray(input)).toEqual(expectedOutput);
- });
-
- it('should handle single word strings', () => {
- const input = ['hello', 'world'];
- const expectedOutput = ['Hello', 'World'];
- expect(capitalizeFirstLetterOfEachWordInArray(input)).toEqual(expectedOutput);
- });
-
- it('should handle empty strings within the array', () => {
- const input = ['', 'hello world', ''];
- const expectedOutput = ['', 'Hello World', ''];
- expect(capitalizeFirstLetterOfEachWordInArray(input)).toEqual(expectedOutput);
- });
-
- it('should handle arrays with single character words', () => {
- const input = ['a b c', 'd e f'];
- const expectedOutput = ['A B C', 'D E F'];
- expect(capitalizeFirstLetterOfEachWordInArray(input)).toEqual(expectedOutput);
- });
-
- it('should handle strings with multiple spaces between words', () => {
- const input = ['hello world', 'this is a test'];
- const expectedOutput = ['Hello World', 'This Is A Test'];
- expect(capitalizeFirstLetterOfEachWordInArray(input)).toEqual(expectedOutput);
- });
-
- it('should not affect already capitalized words', () => {
- const input = ['Hello World', 'Already Capitalized'];
- const expectedOutput = ['Hello World', 'Already Capitalized'];
- expect(capitalizeFirstLetterOfEachWordInArray(input)).toEqual(expectedOutput);
- });
-
- it('should handle strings with special characters', () => {
- const input = ['hello-world', 'openai@chatgpt'];
- const expectedOutput = ['Hello-World', 'Openai@Chatgpt'];
- expect(capitalizeFirstLetterOfEachWordInArray(input)).toEqual(expectedOutput);
- });
-
- it('should handle mixed case words', () => {
- const input = ['hElLo WoRlD', 'OpEnAi ChAtGpT'];
- const expectedOutput = ['HElLo WoRlD', 'OpEnAi ChAtGpT'];
- expect(capitalizeFirstLetterOfEachWordInArray(input)).toEqual(expectedOutput);
- });
-
- it('should handle an empty array', () => {
- const input: string[] = [];
- const expectedOutput: string[] = [];
- expect(capitalizeFirstLetterOfEachWordInArray(input)).toEqual(expectedOutput);
- });
-
- it('should handle an array with empty strings only', () => {
- const input = ['', '', ''];
- const expectedOutput = ['', '', ''];
- expect(capitalizeFirstLetterOfEachWordInArray(input)).toEqual(expectedOutput);
- });
-
- it('should handle arrays with non-alphabetic characters', () => {
- const input = ['123 abc', '$%^ abc', '123'];
- const expectedOutput = ['123 Abc', '$%^ Abc', '123'];
- expect(capitalizeFirstLetterOfEachWordInArray(input)).toEqual(expectedOutput);
- });
- });
-
- describe('firstLetterInUpperCase', () => {
- it('should capitalize the first letter of each word in a single-word string', () => {
- expect(firstLetterInUpperCase('hello')).toBe('Hello');
- expect(firstLetterInUpperCase('world')).toBe('World');
- });
-
- it('should capitalize the first letter of each word in a multi-word string', () => {
- expect(firstLetterInUpperCase('hello world')).toBe('Hello World');
- expect(firstLetterInUpperCase('this is a test')).toBe('This Is A Test');
- expect(firstLetterInUpperCase('openai chatgpt')).toBe('Openai Chatgpt');
- });
-
- it('should return null for an empty string', () => {
- expect(firstLetterInUpperCase('')).toBeNull();
- });
-
- it('should handle strings with leading and trailing spaces', () => {
- expect(firstLetterInUpperCase(' leading')).toBe(' Leading');
- expect(firstLetterInUpperCase('trailing ')).toBe('Trailing ');
- expect(firstLetterInUpperCase(' both ')).toBe(' Both ');
- });
-
- it('should handle strings with multiple spaces between words', () => {
- expect(firstLetterInUpperCase('hello world')).toBe('Hello World');
- expect(firstLetterInUpperCase('this is a test')).toBe('This Is A Test');
- });
-
- it('should not affect already capitalized words', () => {
- expect(firstLetterInUpperCase('Hello World')).toBe('Hello World');
- expect(firstLetterInUpperCase('Already Capitalized')).toBe('Already Capitalized');
- });
-
- it('should handle mixed case words', () => {
- expect(firstLetterInUpperCase('hElLo WoRlD')).toBe('HElLo WoRlD');
- expect(firstLetterInUpperCase('OpEnAi ChAtGpT')).toBe('OpEnAi ChAtGpT');
- });
-
- it('should handle single-character words', () => {
- expect(firstLetterInUpperCase('a b c')).toBe('A B C');
- expect(firstLetterInUpperCase('x y z')).toBe('X Y Z');
- });
-
- it('should return null for a null input', () => {
- expect(firstLetterInUpperCase(null as unknown as string)).toBeNull();
- });
-
- it('should handle strings with numbers', () => {
- expect(firstLetterInUpperCase('hello 123 world')).toBe('Hello 123 World');
- expect(firstLetterInUpperCase('2024 is a year')).toBe('2024 Is A Year');
- });
-
- it('should handle an empty word array', () => {
- expect(firstLetterInUpperCase(' ')).toBe(' ');
- });
-
- it('should handle strings with non-alphabetic characters', () => {
- expect(firstLetterInUpperCase('123 abc')).toBe('123 Abc');
- expect(firstLetterInUpperCase('$%^ abc')).toBe('$%^ Abc');
- expect(firstLetterInUpperCase('123')).toBe('123');
- });
- });
-
- describe('transformLabel', () => {
- it('should transform a label with underscores to capitalized words', () => {
- expect(transformLabel('hello_world')).toBe('Hello World');
- expect(transformLabel('this_is_a_test')).toBe('This Is A Test');
- expect(transformLabel('openai_chatgpt')).toBe('Openai Chatgpt');
- });
-
- it('should transform a label with mixed casing', () => {
- expect(transformLabel('hELLo_wOrLD')).toBe('Hello World');
- expect(transformLabel('tHiS_iS_A_tEsT')).toBe('This Is A Test');
- });
-
- it('should handle labels with spaces instead of underscores', () => {
- expect(transformLabel('hello world')).toBe('Hello World');
- expect(transformLabel('this is a test')).toBe('This Is A Test');
- });
-
- it('should transform a single word label', () => {
- expect(transformLabel('hello')).toBe('Hello');
- expect(transformLabel('WORLD')).toBe('World');
- });
-
- it('should return an empty string if the label is empty', () => {
- expect(transformLabel('')).toBe('');
- });
-
- it('should handle labels with numbers', () => {
- expect(transformLabel('hello_123_world')).toBe('Hello 123 World');
- expect(transformLabel('2024_is_a_year')).toBe('2024 Is A Year');
- });
-
- it('should handle labels with multiple underscores', () => {
- expect(transformLabel('hello___world')).toBe('Hello World');
- expect(transformLabel('this__is___a_test')).toBe('This Is A Test');
- });
-
- it('should handle labels with leading and trailing underscores', () => {
- expect(transformLabel('_hello_world_')).toBe(' Hello World ');
- expect(transformLabel('__this_is_a_test__')).toBe(' This Is A Test ');
- });
-
- it('should handle labels with leading and trailing spaces', () => {
- expect(transformLabel(' hello world ')).toBe(' Hello World ');
- });
- });
-
- describe('transformArray', () => {
- it('should transform an array of State objects', () => {
- const input: State[] = [
- { value: '1', label: 'hello_world' },
- { value: '2', label: 'this_is_a_test' },
- { value: '3', label: 'openai_chatgpt' },
- ];
-
- const expectedOutput: State[] = [
- { value: '1', label: 'Hello World' },
- { value: '2', label: 'This Is A Test' },
- { value: '3', label: 'Openai Chatgpt' },
- ];
-
- expect(transformArray(input)).toEqual(expectedOutput);
- });
-
- it('should handle an empty array', () => {
- const input: State[] = [];
- const expectedOutput: State[] = [];
-
- expect(transformArray(input)).toEqual(expectedOutput);
- });
-
- it('should handle an array with a single State object', () => {
- const input: State[] = [{ value: '1', label: 'single_word' }];
- const expectedOutput: State[] = [{ value: '1', label: 'Single Word' }];
-
- expect(transformArray(input)).toEqual(expectedOutput);
- });
-
- it('should handle an array with mixed casing in labels', () => {
- const input: State[] = [
- { value: '1', label: 'hELLo_wOrLD' },
- { value: '2', label: 'tHiS_iS_A_tEsT' },
- ];
-
- const expectedOutput: State[] = [
- { value: '1', label: 'Hello World' },
- { value: '2', label: 'This Is A Test' },
- ];
-
- expect(transformArray(input)).toEqual(expectedOutput);
- });
-
- it('should handle an array with numbers in labels', () => {
- const input: State[] = [
- { value: '1', label: 'hello_123_world' },
- { value: '2', label: '2024_is_a_year' },
- ];
-
- const expectedOutput: State[] = [
- { value: '1', label: 'Hello 123 World' },
- { value: '2', label: '2024 Is A Year' },
- ];
-
- expect(transformArray(input)).toEqual(expectedOutput);
- });
-
- it('should handle an array with leading and trailing underscores in labels', () => {
- const input: State[] = [
- { value: '1', label: '_hello_world_' },
- { value: '2', label: '__this_is_a_test__' },
- ];
-
- const expectedOutput: State[] = [
- { value: '1', label: ' Hello World ' },
- { value: '2', label: ' This Is A Test ' },
- ];
-
- expect(transformArray(input)).toEqual(expectedOutput);
- });
-
- it('should handle an array with leading and trailing spaces in labels', () => {
- const input: State[] = [
- { value: '1', label: ' hello world ' },
- { value: '2', label: ' this is a test ' },
- ];
-
- const expectedOutput: State[] = [
- { value: '1', label: ' Hello World ' },
- { value: '2', label: ' This Is A Test ' },
- ];
-
- expect(transformArray(input)).toEqual(expectedOutput);
- });
-
- it('should handle arrays with labels containing multiple underscores', () => {
- const input: State[] = [
- { value: '1', label: 'hello___world' },
- { value: '2', label: 'this__is___a_test' },
- ];
-
- const expectedOutput: State[] = [
- { value: '1', label: 'Hello World' },
- { value: '2', label: 'This Is A Test' },
- ];
-
- expect(transformArray(input)).toEqual(expectedOutput);
- });
-
- it('should return a new array without modifying the original array', () => {
- const input: State[] = [
- { value: '1', label: 'hello_world' },
- { value: '2', label: 'this_is_a_test' },
- ];
-
- const expectedOutput: State[] = [
- { value: '1', label: 'Hello World' },
- { value: '2', label: 'This Is A Test' },
- ];
-
- const result = transformArray(input);
-
- expect(result).toEqual(expectedOutput);
- expect(input).toEqual([
- { value: '1', label: 'hello_world' },
- { value: '2', label: 'this_is_a_test' },
- ]); // Ensure original array is unchanged
- });
- });
\ No newline at end of file
+ it("should handle strings with numbers", () => {
+ expect(firstLetterInUpperCase("hello 123 world")).toBe("Hello 123 World");
+ expect(firstLetterInUpperCase("2024 is a year")).toBe("2024 Is A Year");
+ });
+
+ it("should handle an empty word array", () => {
+ expect(firstLetterInUpperCase(" ")).toBe(" ");
+ });
+
+ it("should handle strings with non-alphabetic characters", () => {
+ expect(firstLetterInUpperCase("123 abc")).toBe("123 Abc");
+ expect(firstLetterInUpperCase("$%^ abc")).toBe("$%^ Abc");
+ expect(firstLetterInUpperCase("123")).toBe("123");
+ });
+});
+
+describe("transformLabel", () => {
+ it("should transform a label with underscores to capitalized words", () => {
+ expect(transformLabel("hello_world")).toBe("Hello World");
+ expect(transformLabel("this_is_a_test")).toBe("This Is A Test");
+ expect(transformLabel("openai_chatgpt")).toBe("Openai Chatgpt");
+ });
+
+ it("should transform a label with mixed casing", () => {
+ expect(transformLabel("hELLo_wOrLD")).toBe("Hello World");
+ expect(transformLabel("tHiS_iS_A_tEsT")).toBe("This Is A Test");
+ });
+
+ it("should handle labels with spaces instead of underscores", () => {
+ expect(transformLabel("hello world")).toBe("Hello World");
+ expect(transformLabel("this is a test")).toBe("This Is A Test");
+ });
+
+ it("should transform a single word label", () => {
+ expect(transformLabel("hello")).toBe("Hello");
+ expect(transformLabel("WORLD")).toBe("World");
+ });
+
+ it("should return an empty string if the label is empty", () => {
+ expect(transformLabel("")).toBe("");
+ });
+
+ it("should handle labels with numbers", () => {
+ expect(transformLabel("hello_123_world")).toBe("Hello 123 World");
+ expect(transformLabel("2024_is_a_year")).toBe("2024 Is A Year");
+ });
+
+ it("should handle labels with multiple underscores", () => {
+ expect(transformLabel("hello___world")).toBe("Hello World");
+ expect(transformLabel("this__is___a_test")).toBe("This Is A Test");
+ });
+
+ it("should handle labels with leading and trailing underscores", () => {
+ expect(transformLabel("_hello_world_")).toBe(" Hello World ");
+ expect(transformLabel("__this_is_a_test__")).toBe(" This Is A Test ");
+ });
+
+ it("should handle labels with leading and trailing spaces", () => {
+ expect(transformLabel(" hello world ")).toBe(" Hello World ");
+ });
+});
+
+describe("transformArray", () => {
+ it("should transform an array of State objects", () => {
+ const input: State[] = [
+ { value: "1", label: "hello_world" },
+ { value: "2", label: "this_is_a_test" },
+ { value: "3", label: "openai_chatgpt" },
+ ];
+
+ const expectedOutput: State[] = [
+ { value: "1", label: "Hello World" },
+ { value: "2", label: "This Is A Test" },
+ { value: "3", label: "Openai Chatgpt" },
+ ];
+
+ expect(transformArray(input)).toEqual(expectedOutput);
+ });
+
+ it("should handle an empty array", () => {
+ const input: State[] = [];
+ const expectedOutput: State[] = [];
+
+ expect(transformArray(input)).toEqual(expectedOutput);
+ });
+
+ it("should handle an array with a single State object", () => {
+ const input: State[] = [{ value: "1", label: "single_word" }];
+ const expectedOutput: State[] = [{ value: "1", label: "Single Word" }];
+
+ expect(transformArray(input)).toEqual(expectedOutput);
+ });
+
+ it("should handle an array with mixed casing in labels", () => {
+ const input: State[] = [
+ { value: "1", label: "hELLo_wOrLD" },
+ { value: "2", label: "tHiS_iS_A_tEsT" },
+ ];
+
+ const expectedOutput: State[] = [
+ { value: "1", label: "Hello World" },
+ { value: "2", label: "This Is A Test" },
+ ];
+
+ expect(transformArray(input)).toEqual(expectedOutput);
+ });
+
+ it("should handle an array with numbers in labels", () => {
+ const input: State[] = [
+ { value: "1", label: "hello_123_world" },
+ { value: "2", label: "2024_is_a_year" },
+ ];
+
+ const expectedOutput: State[] = [
+ { value: "1", label: "Hello 123 World" },
+ { value: "2", label: "2024 Is A Year" },
+ ];
+
+ expect(transformArray(input)).toEqual(expectedOutput);
+ });
+
+ it("should handle an array with leading and trailing underscores in labels", () => {
+ const input: State[] = [
+ { value: "1", label: "_hello_world_" },
+ { value: "2", label: "__this_is_a_test__" },
+ ];
+
+ const expectedOutput: State[] = [
+ { value: "1", label: " Hello World " },
+ { value: "2", label: " This Is A Test " },
+ ];
+
+ expect(transformArray(input)).toEqual(expectedOutput);
+ });
+
+ it("should handle an array with leading and trailing spaces in labels", () => {
+ const input: State[] = [
+ { value: "1", label: " hello world " },
+ { value: "2", label: " this is a test " },
+ ];
+
+ const expectedOutput: State[] = [
+ { value: "1", label: " Hello World " },
+ { value: "2", label: " This Is A Test " },
+ ];
+
+ expect(transformArray(input)).toEqual(expectedOutput);
+ });
+
+ it("should handle arrays with labels containing multiple underscores", () => {
+ const input: State[] = [
+ { value: "1", label: "hello___world" },
+ { value: "2", label: "this__is___a_test" },
+ ];
+
+ const expectedOutput: State[] = [
+ { value: "1", label: "Hello World" },
+ { value: "2", label: "This Is A Test" },
+ ];
+
+ expect(transformArray(input)).toEqual(expectedOutput);
+ });
+
+ it("should return a new array without modifying the original array", () => {
+ const input: State[] = [
+ { value: "1", label: "hello_world" },
+ { value: "2", label: "this_is_a_test" },
+ ];
+
+ const expectedOutput: State[] = [
+ { value: "1", label: "Hello World" },
+ { value: "2", label: "This Is A Test" },
+ ];
+
+ const result = transformArray(input);
+
+ expect(result).toEqual(expectedOutput);
+ expect(input).toEqual([
+ { value: "1", label: "hello_world" },
+ { value: "2", label: "this_is_a_test" },
+ ]); // Ensure original array is unchanged
+ });
+});
diff --git a/__tests__/UserNameCell.test.tsx b/__tests__/UserNameCell.test.tsx
index c6aef1cd..ad6ca821 100644
--- a/__tests__/UserNameCell.test.tsx
+++ b/__tests__/UserNameCell.test.tsx
@@ -48,7 +48,7 @@ describe("UserNameCell Component", () => {
name
.split(" ")
.map((word: string) => word.charAt(0).toUpperCase() + word.slice(1))
- .join(" ")
+ .join(" "),
);
render();
@@ -62,7 +62,7 @@ describe("UserNameCell Component", () => {
});
it("should display a dash if username is not available", async () => {
- mockGetUserName.mockResolvedValueOnce('');
+ mockGetUserName.mockResolvedValueOnce("");
render();
diff --git a/app.config.ts b/app.config.ts
index b48fe0ee..4ef8bb3f 100644
--- a/app.config.ts
+++ b/app.config.ts
@@ -1 +1 @@
-export const tenantId = "ef99949b-7f3a-4a5f-806a-e67e683e38f3"
\ No newline at end of file
+export const tenantId = "ef99949b-7f3a-4a5f-806a-e67e683e38f3";
diff --git a/jest.config.ts b/jest.config.ts
index 4b985bfc..2b0cc53c 100644
--- a/jest.config.ts
+++ b/jest.config.ts
@@ -3,12 +3,12 @@
* https://jestjs.io/docs/configuration
*/
-import type {Config} from 'jest';
-import nextJest from 'next/jest.js';
+import type { Config } from "jest";
+import nextJest from "next/jest.js";
const createJestConfig = nextJest({
// Provide the path to your Next.js app to load next.config.js and .env files in your test environment
- dir: './',
+ dir: "./",
});
const config: Config = {
@@ -97,7 +97,7 @@ const config: Config = {
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
moduleNameMapper: {
- '^@/(.*)$': '/src/$1',
+ "^@/(.*)$": "/src/$1",
},
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
@@ -145,7 +145,7 @@ const config: Config = {
// setupFiles: [],
// A list of paths to modules that run some code to configure or set up the testing framework before each test
- setupFilesAfterEnv: ['/jest.setup.ts'],
+ setupFilesAfterEnv: ["/jest.setup.ts"],
// The number of seconds after which a test is considered as slow and reported as such in the results.
// slowTestThreshold: 5,
diff --git a/jest.setup.ts b/jest.setup.ts
index 7b0828bf..d0de870d 100644
--- a/jest.setup.ts
+++ b/jest.setup.ts
@@ -1 +1 @@
-import '@testing-library/jest-dom';
+import "@testing-library/jest-dom";
diff --git a/src/components/ActionCell.tsx b/src/components/ActionCell.tsx
index 521686fd..7944318a 100644
--- a/src/components/ActionCell.tsx
+++ b/src/components/ActionCell.tsx
@@ -44,7 +44,7 @@ const ActionCell: React.FC = ({
{extraActions?.length > 0 ? (
-
+
diff --git a/src/components/AddBlockModal.tsx b/src/components/AddBlockModal.tsx
index 94c55caa..a52a0ea3 100644
--- a/src/components/AddBlockModal.tsx
+++ b/src/components/AddBlockModal.tsx
@@ -20,7 +20,7 @@ interface AddBlockModalProps {
value: string,
controllingField: string,
fieldId: string,
- districtId?: string
+ districtId?: string,
) => void;
fieldId: string;
initialValues?: {
diff --git a/src/components/AddDistrictBlockModal.tsx b/src/components/AddDistrictBlockModal.tsx
index f6547c48..941a7c2f 100644
--- a/src/components/AddDistrictBlockModal.tsx
+++ b/src/components/AddDistrictBlockModal.tsx
@@ -21,7 +21,7 @@ interface AddDistrictBlockModalProps {
value: string,
controllingField: string,
fieldId: string,
- districtId?: string
+ districtId?: string,
) => void;
fieldId: string;
initialValues?: {
@@ -116,7 +116,7 @@ export const AddDistrictBlockModal: React.FC = ({
};
const handleControllingFieldChange = (
- e: React.ChangeEvent
+ e: React.ChangeEvent,
) => {
const inputControllingField = e.target.value;
if (fieldTextValidation(inputControllingField)) {
diff --git a/src/components/AddNewCenters.tsx b/src/components/AddNewCenters.tsx
index 9423c363..d30df335 100644
--- a/src/components/AddNewCenters.tsx
+++ b/src/components/AddNewCenters.tsx
@@ -4,9 +4,7 @@ import {
customFields,
} from "@/components/GeneratedSchemas";
import SimpleModal from "@/components/SimpleModal";
-import {
- getFormRead,
-} from "@/services/CreateUserService";
+import { getFormRead } from "@/services/CreateUserService";
import { CustomField } from "@/utils/Interfaces";
import { CohortTypes } from "@/utils/app.constant";
import { useLocationState } from "@/utils/useLocationState";
@@ -49,7 +47,6 @@ const AddNewCenters: React.FC = ({
const [openAddNewCohort, setOpenAddNewCohort] =
React.useState(false);
-
const { t } = useTranslation();
const {
states,
@@ -92,7 +89,7 @@ const AddNewCenters: React.FC = ({
const handleSubmit = async (
data: IChangeEvent,
- event: React.FormEvent
+ event: React.FormEvent,
) => {
const formData = data?.formData;
@@ -144,53 +141,52 @@ const AddNewCenters: React.FC = ({
};
return (
-
-
+
-
-
-
+
+
- {dynamicFormForBlock && schema && uiSchema && (
-
- )}
-
+ {dynamicFormForBlock && schema && uiSchema && (
+
+ )}
+
);
};
diff --git a/src/components/AddStateModal.tsx b/src/components/AddStateModal.tsx
index f24b66f6..9f1cddbb 100644
--- a/src/components/AddStateModal.tsx
+++ b/src/components/AddStateModal.tsx
@@ -20,7 +20,7 @@ interface AddStateModalProps {
name: string,
value: string,
fieldId: string,
- stateId?: string
+ stateId?: string,
) => void;
fieldId: string;
initialValues?: {
diff --git a/src/components/AreaSelection.tsx b/src/components/AreaSelection.tsx
index bbf01d4c..f0163a10 100644
--- a/src/components/AreaSelection.tsx
+++ b/src/components/AreaSelection.tsx
@@ -32,19 +32,19 @@ interface DropdownBoxProps {
selectedCenter?: any;
handleStateChangeWrapper: (
selectedNames: string[],
- selectedCodes: string[]
+ selectedCodes: string[],
) => Promise;
handleDistrictChangeWrapper: (
selected: string[],
- selectedCodes: string[]
+ selectedCodes: string[],
) => Promise;
handleBlockChangeWrapper: (
selected: string[],
- selectedCodes: string[]
+ selectedCodes: string[],
) => void;
handleCenterChangeWrapper?: (
selected: string[],
- selectedCodes: string[]
+ selectedCodes: string[],
) => void;
isMobile: boolean;
@@ -89,7 +89,7 @@ const AreaSelection: React.FC = ({
names={states?.map(
(state) =>
state.label?.toLowerCase().charAt(0).toUpperCase() +
- state.label?.toLowerCase().slice(1)
+ state.label?.toLowerCase().slice(1),
)}
codes={states?.map((state) => state.value)}
tagName={t("FACILITATORS.STATE")}
diff --git a/src/components/CommonUserModal.tsx b/src/components/CommonUserModal.tsx
index 4764cc39..07f17597 100644
--- a/src/components/CommonUserModal.tsx
+++ b/src/components/CommonUserModal.tsx
@@ -2,7 +2,13 @@ import React, { useState, useEffect } from "react";
import { useTranslation } from "next-i18next";
import { IChangeEvent } from "@rjsf/core";
import { RJSFSchema } from "@rjsf/utils";
-import { Typography, useMediaQuery , Box, Button, useTheme} from "@mui/material";
+import {
+ Typography,
+ useMediaQuery,
+ Box,
+ Button,
+ useTheme,
+} from "@mui/material";
import {
GenerateSchemaAndUiSchema,
customFields,
@@ -18,17 +24,13 @@ import {
} from "@/services/CreateUserService";
import { generateUsernameAndPassword } from "@/utils/Helper";
import { FormData } from "@/utils/Interfaces";
-import { RoleId ,Role} from "@/utils/app.constant";
+import { RoleId, Role } from "@/utils/app.constant";
import AreaSelection from "./AreaSelection";
import { showToastMessage } from "./Toastify";
import { transformArray } from "../utils/Helper";
import { useLocationState } from "@/utils/useLocationState";
import { tenantId } from "../../app.config";
-
-
-
-
interface UserModalProps {
open: boolean;
onClose: () => void;
@@ -36,7 +38,7 @@ interface UserModalProps {
isEditModal?: boolean;
userId?: string;
onSubmit: (submitValue: boolean) => void;
- userType:string
+ userType: string;
}
const CommonUserModal: React.FC = ({
@@ -46,16 +48,26 @@ const CommonUserModal: React.FC = ({
isEditModal = false,
userId,
onSubmit,
- userType
+ userType,
}) => {
- console.log(userType)
+ console.log(userType);
const [schema, setSchema] = React.useState();
const [uiSchema, setUiSchema] = React.useState();
const { t } = useTranslation();
const [formValue, setFormValue] = useState();
- const modalTitle=!isEditModal? userType === FormContextType.STUDENT?t("LEARNERS.NEW_LEARNER"):userType === FormContextType.TEACHER?t("FACILITATORS.NEW_FACILITATOR"):t("TEAM_LEADERS.NEW_TEAM_LEADER"): userType === FormContextType.STUDENT?t("LEARNERS.EDIT_LEARNER"):userType === FormContextType.TEACHER?t("FACILITATORS.EDIT_FACILITATOR"):t("TEAM_LEADERS.EDIT_TEAM_LEADER")
+ const modalTitle = !isEditModal
+ ? userType === FormContextType.STUDENT
+ ? t("LEARNERS.NEW_LEARNER")
+ : userType === FormContextType.TEACHER
+ ? t("FACILITATORS.NEW_FACILITATOR")
+ : t("TEAM_LEADERS.NEW_TEAM_LEADER")
+ : userType === FormContextType.STUDENT
+ ? t("LEARNERS.EDIT_LEARNER")
+ : userType === FormContextType.TEACHER
+ ? t("FACILITATORS.EDIT_FACILITATOR")
+ : t("TEAM_LEADERS.EDIT_TEAM_LEADER");
const theme = useTheme();
- const {
+ const {
states,
districts,
blocks,
@@ -74,49 +86,56 @@ const CommonUserModal: React.FC = ({
handleDistrictChangeWrapper,
handleBlockChangeWrapper,
handleCenterChangeWrapper,
- selectedCenterCode, selectedBlockCohortId, blockFieldId, distrctFieldId, stateFieldId, dynamicFormForBlock
-
+ selectedCenterCode,
+ selectedBlockCohortId,
+ blockFieldId,
+ distrctFieldId,
+ stateFieldId,
+ dynamicFormForBlock,
} = useLocationState(open, onClose);
useEffect(() => {
const getAddUserFormData = async () => {
try {
-
const response: FormData = await getFormRead(
FormContext.USERS,
- userType );
-
+ userType,
+ );
+
console.log("sortedFields", response);
if (response) {
- if(userType=== FormContextType.TEACHER )
- {
- const newResponse={
+ if (userType === FormContextType.TEACHER) {
+ const newResponse = {
...response,
- fields: response.fields.filter(field => field.name !== 'no_of_clusters')
- }
- const { schema, uiSchema, formValues } = GenerateSchemaAndUiSchema(newResponse, t);
- setFormValue(formValues)
- setSchema(schema);
- setUiSchema(uiSchema);
- }
- else if(userType=== FormContextType.TEAM_LEADER)
- {
- const { schema, uiSchema, formValues } = GenerateSchemaAndUiSchema(response, t);
- setFormValue(formValues)
+ fields: response.fields.filter(
+ (field) => field.name !== "no_of_clusters",
+ ),
+ };
+ const { schema, uiSchema, formValues } = GenerateSchemaAndUiSchema(
+ newResponse,
+ t,
+ );
+ setFormValue(formValues);
+ setSchema(schema);
+ setUiSchema(uiSchema);
+ } else if (userType === FormContextType.TEAM_LEADER) {
+ const { schema, uiSchema, formValues } = GenerateSchemaAndUiSchema(
+ response,
+ t,
+ );
+ setFormValue(formValues);
+ setSchema(schema);
+ console.log(schema);
+ setUiSchema(uiSchema);
+ } else {
+ console.log("true");
+ const { schema, uiSchema } = GenerateSchemaAndUiSchema(response, t);
setSchema(schema);
console.log(schema);
setUiSchema(uiSchema);
- }
- else {
- console.log("true")
- const { schema, uiSchema } = GenerateSchemaAndUiSchema(response, t);
- setSchema(schema);
- console.log(schema);
- setUiSchema(uiSchema);
}
}
-
} catch (error) {
console.error("Error fetching form data:", error);
}
@@ -126,11 +145,11 @@ const CommonUserModal: React.FC = ({
const handleSubmit = async (
data: IChangeEvent,
- event: React.FormEvent
+ event: React.FormEvent,
) => {
// setOpenModal(true);
const target = event.target as HTMLFormElement;
- // const elementsArray = Array.from(target.elements);
+ // const elementsArray = Array.from(target.elements);
console.log("onsubmit", data);
// for (const element of elementsArray) {
@@ -150,10 +169,10 @@ const CommonUserModal: React.FC = ({
const formData = data.formData;
console.log("Form data submitted:", formData);
const schemaProperties = schema.properties;
-
+
const { username, password } = generateUsernameAndPassword(
selectedStateCode,
- userType
+ userType,
);
let apiBody: any = {
@@ -162,8 +181,16 @@ const CommonUserModal: React.FC = ({
tenantCohortRoleMapping: [
{
tenantId: tenantId,
- roleId:userType===FormContextType.STUDENT? RoleId.STUDENT: userType===FormContextType.TEACHER?RoleId.TEACHER:RoleId.TEAM_LEADER,
- cohortId:userType===FormContextType.TEAM_LEADER ?[selectedBlockCohortId] :[selectedCenterCode],
+ roleId:
+ userType === FormContextType.STUDENT
+ ? RoleId.STUDENT
+ : userType === FormContextType.TEACHER
+ ? RoleId.TEACHER
+ : RoleId.TEAM_LEADER,
+ cohortId:
+ userType === FormContextType.TEAM_LEADER
+ ? [selectedBlockCohortId]
+ : [selectedCenterCode],
},
],
customFields: [],
@@ -173,7 +200,7 @@ const CommonUserModal: React.FC = ({
const fieldSchema = schemaProperties[fieldKey];
const fieldId = fieldSchema?.fieldId;
console.log(
- `FieldID: ${fieldId}, FieldValue: ${fieldSchema}, type: ${typeof fieldValue}`
+ `FieldID: ${fieldId}, FieldValue: ${fieldSchema}, type: ${typeof fieldValue}`,
);
if (fieldId === null || fieldId === "null") {
@@ -181,7 +208,6 @@ const CommonUserModal: React.FC = ({
apiBody[fieldKey] = fieldValue;
}
} else {
-
if (
fieldSchema?.hasOwnProperty("isDropdown") ||
fieldSchema?.hasOwnProperty("isCheckbox")
@@ -191,21 +217,17 @@ const CommonUserModal: React.FC = ({
value: [String(fieldValue)],
});
} else {
- if(fieldSchema.checkbox &&fieldSchema.type==="array")
- {
+ if (fieldSchema.checkbox && fieldSchema.type === "array") {
apiBody.customFields.push({
fieldId: fieldId,
- value: String(fieldValue).split(',')
+ value: String(fieldValue).split(","),
});
- }
-
- else{ apiBody.customFields.push({
- fieldId: fieldId,
- value: String(fieldValue),
- });
- }
-
-
+ } else {
+ apiBody.customFields.push({
+ fieldId: fieldId,
+ value: String(fieldValue),
+ });
+ }
}
}
});
@@ -239,22 +261,24 @@ const CommonUserModal: React.FC = ({
customFields: customFields,
};
const response = await updateUser(userId, object);
- const messageKey = userType === FormContextType.STUDENT
- ? "LEARNERS.LEARNER_UPDATED_SUCCESSFULLY"
- : userType === FormContextType.TEACHER
- ? "FACILITATORS.FACILITATOR_UPDATED_SUCCESSFULLY"
- : "TEAM_LEADERS.TEAM_LEADER_UPDATED_SUCCESSFULLY";
-
- showToastMessage(t(messageKey), "success");
+ const messageKey =
+ userType === FormContextType.STUDENT
+ ? "LEARNERS.LEARNER_UPDATED_SUCCESSFULLY"
+ : userType === FormContextType.TEACHER
+ ? "FACILITATORS.FACILITATOR_UPDATED_SUCCESSFULLY"
+ : "TEAM_LEADERS.TEAM_LEADER_UPDATED_SUCCESSFULLY";
+
+ showToastMessage(t(messageKey), "success");
} else {
const response = await createUser(apiBody);
- const messageKey = userType === FormContextType.STUDENT
- ? "LEARNERS.LEARNER_CREATED_SUCCESSFULLY"
- : userType === FormContextType.TEACHER
- ? "FACILITATORS.FACILITATOR_CREATED_SUCCESSFULLY"
- : "TEAM_LEADERS.TEAM_LEADER_CREATED_SUCCESSFULLY";
+ const messageKey =
+ userType === FormContextType.STUDENT
+ ? "LEARNERS.LEARNER_CREATED_SUCCESSFULLY"
+ : userType === FormContextType.TEACHER
+ ? "FACILITATORS.FACILITATOR_CREATED_SUCCESSFULLY"
+ : "TEAM_LEADERS.TEAM_LEADER_CREATED_SUCCESSFULLY";
-showToastMessage(t(messageKey), "success");
+ showToastMessage(t(messageKey), "success");
}
onSubmit(true);
onClose();
@@ -376,7 +400,7 @@ showToastMessage(t(messageKey), "success");
handleBlockChangeWrapper={handleBlockChangeWrapper}
isMobile={isMobile}
isMediumScreen={isMediumScreen}
- isCenterSelection={userType!=="TEAM LEADER"?true: false}
+ isCenterSelection={userType !== "TEAM LEADER" ? true : false}
allCenters={allCenters}
selectedCenter={selectedCenter}
handleCenterChangeWrapper={handleCenterChangeWrapper}
@@ -401,44 +425,41 @@ showToastMessage(t(messageKey), "success");
{/* */}
)
- :userType==="TEAM LEADER"?
- dynamicFormForBlock &&
- schema &&
- uiSchema && (
-
- {/* */}
- )
-
-
- : (dynamicForm &&
- schema &&
- uiSchema && (
-
- {/* */}
-
- ))}
+ : userType === "TEAM LEADER"
+ ? dynamicFormForBlock &&
+ schema &&
+ uiSchema && (
+
+ {/* */}
+
+ )
+ : dynamicForm &&
+ schema &&
+ uiSchema && (
+
+ {/* */}
+
+ )}
>
);
diff --git a/src/components/CustomModal.tsx b/src/components/CustomModal.tsx
index e827d730..bb554afa 100644
--- a/src/components/CustomModal.tsx
+++ b/src/components/CustomModal.tsx
@@ -41,7 +41,7 @@ const CustomModal: React.FC = ({
children,
}) => {
const isSmallScreen = useMediaQuery((theme: Theme) =>
- theme.breakpoints.down("sm")
+ theme.breakpoints.down("sm"),
);
return (
@@ -87,7 +87,6 @@ const CustomModal: React.FC = ({
{children}
-
{secondaryBtnText && (