@@ -465,10 +507,13 @@ function orgList(): JSX.Element {
required
value={formState.name}
onChange={(e): void => {
- setFormState({
- ...formState,
- name: e.target.value,
- });
+ const inputText = e.target.value;
+ if (inputText.length < 50) {
+ setFormState({
+ ...formState,
+ name: e.target.value,
+ });
+ }
}}
/>
@@ -481,10 +526,13 @@ function orgList(): JSX.Element {
required
value={formState.descrip}
onChange={(e): void => {
- setFormState({
- ...formState,
- descrip: e.target.value,
- });
+ const descriptionText = e.target.value;
+ if (descriptionText.length < 200) {
+ setFormState({
+ ...formState,
+ descrip: e.target.value,
+ });
+ }
}}
/>
@@ -497,10 +545,13 @@ function orgList(): JSX.Element {
required
value={formState.location}
onChange={(e): void => {
- setFormState({
- ...formState,
- location: e.target.value,
- });
+ const locationText = e.target.value;
+ if (locationText.length < 100) {
+ setFormState({
+ ...formState,
+ location: e.target.value,
+ });
+ }
}}
/>
@@ -611,8 +662,8 @@ function orgList(): JSX.Element {
{t('goToStore')}
@@ -635,7 +686,7 @@ function orgList(): JSX.Element {
className={styles.greenregbtn}
onClick={closeDialogModal}
value="invite"
- data-testid="submitOrganizationForm"
+ data-testid="enableEverythingForm"
>
{t('enableEverything')}
diff --git a/src/screens/OrgList/OrgListMocks.ts b/src/screens/OrgList/OrgListMocks.ts
index 1a1ab30ab7..833535f4aa 100644
--- a/src/screens/OrgList/OrgListMocks.ts
+++ b/src/screens/OrgList/OrgListMocks.ts
@@ -1,3 +1,7 @@
+import {
+ CREATE_ORGANIZATION_MUTATION,
+ CREATE_SAMPLE_ORGANIZATION_MUTATION,
+} from 'GraphQl/Mutations/mutations';
import {
ORGANIZATION_CONNECTION_LIST,
USER_ORGANIZATION_LIST,
@@ -84,6 +88,7 @@ const MOCKS = [
first: 8,
skip: 0,
filter: '',
+ orderBy: 'createdAt_ASC',
},
notifyOnNetworkStatusChange: true,
},
@@ -102,6 +107,39 @@ const MOCKS = [
data: superAdminUser,
},
},
+ {
+ request: {
+ query: CREATE_SAMPLE_ORGANIZATION_MUTATION,
+ },
+ result: {
+ data: {
+ createSampleOrganization: {
+ id: '1',
+ name: 'Sample Organization',
+ },
+ },
+ },
+ },
+ {
+ request: {
+ query: CREATE_ORGANIZATION_MUTATION,
+ variables: {
+ description: 'This is a dummy organization',
+ location: 'Delhi, India',
+ name: 'Dummy Organization',
+ visibleInSearch: true,
+ isPublic: false,
+ image: '',
+ },
+ },
+ result: {
+ data: {
+ createOrganization: {
+ _id: '1',
+ },
+ },
+ },
+ },
];
const MOCKS_EMPTY = [
{
@@ -111,6 +149,7 @@ const MOCKS_EMPTY = [
first: 8,
skip: 0,
filter: '',
+ orderBy: 'createdAt_ASC',
},
notifyOnNetworkStatusChange: true,
},
@@ -130,6 +169,40 @@ const MOCKS_EMPTY = [
},
},
];
+const MOCKS_WITH_ERROR = [
+ {
+ request: {
+ query: ORGANIZATION_CONNECTION_LIST,
+ variables: {
+ first: 8,
+ skip: 0,
+ filter: '',
+ orderBy: 'createdAt_ASC',
+ },
+ notifyOnNetworkStatusChange: true,
+ },
+ result: {
+ data: {
+ organizationsConnection: organizations,
+ },
+ },
+ },
+ {
+ request: {
+ query: USER_ORGANIZATION_LIST,
+ variables: { id: '123' },
+ },
+ result: {
+ data: superAdminUser,
+ },
+ },
+ {
+ request: {
+ query: CREATE_SAMPLE_ORGANIZATION_MUTATION,
+ },
+ error: new Error('Failed to create sample organization'),
+ },
+];
// MOCKS FOR ADMIN
const MOCKS_ADMIN = [
@@ -140,6 +213,7 @@ const MOCKS_ADMIN = [
first: 8,
skip: 0,
filter: '',
+ orderBy: 'createdAt_ASC',
},
notifyOnNetworkStatusChange: true,
},
@@ -160,4 +234,4 @@ const MOCKS_ADMIN = [
},
];
-export { MOCKS, MOCKS_ADMIN, MOCKS_EMPTY };
+export { MOCKS, MOCKS_ADMIN, MOCKS_EMPTY, MOCKS_WITH_ERROR };
diff --git a/src/screens/OrgPost/OrgPost.test.tsx b/src/screens/OrgPost/OrgPost.test.tsx
index 5c8672e122..fecaa77169 100644
--- a/src/screens/OrgPost/OrgPost.test.tsx
+++ b/src/screens/OrgPost/OrgPost.test.tsx
@@ -245,7 +245,9 @@ describe('Organisation Post Page', () => {
});
}
await debounceWait();
+ const searchBtn = screen.getByTestId('searchBtn');
userEvent.type(screen.getByPlaceholderText(/Search By/i), 'postone{enter}');
+ userEvent.click(searchBtn);
await debounceWait();
const sortDropdown = screen.getByTestId('sort');
userEvent.click(sortDropdown);
diff --git a/src/screens/OrgPost/OrgPost.tsx b/src/screens/OrgPost/OrgPost.tsx
index 3408f3f96c..f4dc98eee8 100644
--- a/src/screens/OrgPost/OrgPost.tsx
+++ b/src/screens/OrgPost/OrgPost.tsx
@@ -138,19 +138,28 @@ function orgPost(): JSX.Element {
if (orgPostListError) {
window.location.assign('/orglist');
}
+ const handleSearch = (value: string): void => {
+ const filterData = {
+ id: currentUrl,
+ title_contains: showTitle ? value : undefined,
+ text_contains: !showTitle ? value : undefined,
+ };
+ refetch(filterData);
+ };
- const handleSearch = (e: any): void => {
+ const handleSearchByEnter = (e: any): void => {
if (e.key === 'Enter') {
const { value } = e.target;
- const filterData = {
- id: currentUrl,
- title_contains: showTitle ? value : null,
- text_contains: !showTitle ? value : null,
- };
- refetch(filterData);
+ handleSearch(value);
}
};
+ const handleSearchByBtnClick = (): void => {
+ const inputValue =
+ (document.getElementById('searchPosts') as HTMLInputElement)?.value || '';
+ handleSearch(inputValue);
+ };
+
const handleSorting = (option: string): void => {
setSortingOption(option);
};
@@ -196,17 +205,19 @@ function orgPost(): JSX.Element {
@@ -253,12 +264,9 @@ function orgPost(): JSX.Element {
title="Sort Post"
data-testid="sort"
>
-
+
- {t('sortPost')}
+ {sortingOption === 'latest' ? t('Latest') : t('Oldest')}
{
await wait();
const searchInput = screen.getByTestId('searchByName');
+ const searchBtn = screen.getByTestId('searchBtn');
+ userEvent.type(searchInput, '');
+ userEvent.click(searchBtn);
+ await wait();
+ userEvent.clear(searchInput);
+
userEvent.type(searchInput, 'l{enter}');
+ await wait();
+ await screen.findByTestId('searchAndNotFound');
+ userEvent.clear(searchInput);
+ userEvent.type(searchInput, 'l');
+ userEvent.click(searchBtn);
+ await wait();
await screen.findByTestId('searchAndNotFound');
});
diff --git a/src/screens/Requests/Requests.tsx b/src/screens/Requests/Requests.tsx
index c991d5d05e..d5c52ef2a4 100644
--- a/src/screens/Requests/Requests.tsx
+++ b/src/screens/Requests/Requests.tsx
@@ -238,23 +238,34 @@ const Requests = (): JSX.Element => {
}
};
- /* istanbul ignore next */
- const handleSearchByName = async (e: any): Promise => {
+ const handleSearch = async (value: string): Promise => {
+ setSearchByName(value);
+ if (value === '') {
+ resetAndRefetch();
+ return;
+ }
+ await refetchUsers({
+ firstName_contains: value,
+ lastName_contains: '',
+ // Later on we can add several search and filter options
+ });
+ };
+
+ const handleSearchByEnter = (e: any): void => {
if (e.key === 'Enter') {
const { value } = e.target;
- setSearchByName(value);
- if (value === '') {
- resetAndRefetch();
- return;
- }
- await refetchUsers({
- firstName_contains: value,
- lastName_contains: '',
- // Later on we can add several search and filter options
- });
+ handleSearch(value);
}
};
+ const handleSearchByBtnClick = (): void => {
+ const inputElement = document.getElementById(
+ 'searchRequests'
+ ) as HTMLInputElement;
+ const inputValue = inputElement?.value || '';
+ handleSearch(inputValue);
+ };
+
const headerTitles: string[] = [
'#',
t('name'),
@@ -307,16 +318,19 @@ const Requests = (): JSX.Element => {
>
diff --git a/src/screens/UserPortal/Chat/Chat.test.tsx b/src/screens/UserPortal/Chat/Chat.test.tsx
index 6476e9ee40..a2f709d8a4 100644
--- a/src/screens/UserPortal/Chat/Chat.test.tsx
+++ b/src/screens/UserPortal/Chat/Chat.test.tsx
@@ -148,7 +148,7 @@ describe('Testing People Screen [User Portal]', () => {
expect(screen.queryAllByText('Noble Mittal')).not.toBe([]);
});
- test('Search functionality works as expected', async () => {
+ test('Search functionality works as expected by pressing enter key', async () => {
render(
@@ -163,7 +163,31 @@ describe('Testing People Screen [User Portal]', () => {
await wait();
+ userEvent.type(screen.getByTestId('searchInput'), 'j{enter}');
+ await wait();
+
+ expect(getOrganizationIdSpy).toHaveBeenCalled();
+ expect(screen.queryByText('John Cena')).toBeInTheDocument();
+ expect(screen.queryByText('Noble Mittal')).not.toBeInTheDocument();
+ });
+
+ test('Search functionality works as expected by clicking search Btn', async () => {
+ render(
+
+
+
+
+
+
+
+
+
+ );
+
+ await wait();
+ const searchBtn = screen.getByTestId('searchBtn');
userEvent.type(screen.getByTestId('searchInput'), 'j');
+ userEvent.click(searchBtn);
await wait();
expect(getOrganizationIdSpy).toHaveBeenCalled();
diff --git a/src/screens/UserPortal/Chat/Chat.tsx b/src/screens/UserPortal/Chat/Chat.tsx
index 1ae9d5764d..aef6b24026 100644
--- a/src/screens/UserPortal/Chat/Chat.tsx
+++ b/src/screens/UserPortal/Chat/Chat.tsx
@@ -57,17 +57,23 @@ export default function chat(): JSX.Element {
},
});
- const handleSearch = (
- event: React.ChangeEvent
- ): void => {
- const newFilter = event.target.value;
- setFilterName(newFilter);
+ const handleSearch = (value: string): void => {
+ setFilterName(value);
- const filter = {
- firstName_contains: newFilter,
- };
-
- contactRefetch(filter);
+ contactRefetch({
+ firstName_contains: value,
+ });
+ };
+ const handleSearchByEnter = (e: any): void => {
+ if (e.key === 'Enter') {
+ const { value } = e.target;
+ handleSearch(value);
+ }
+ };
+ const handleSearchByBtnClick = (): void => {
+ const value =
+ (document.getElementById('searchChats') as HTMLInputElement)?.value || '';
+ handleSearch(value);
};
React.useEffect(() => {
@@ -92,14 +98,17 @@ export default function chat(): JSX.Element {
diff --git a/src/screens/UserPortal/Events/Events.test.tsx b/src/screens/UserPortal/Events/Events.test.tsx
index 4243efa8ee..52e658a641 100644
--- a/src/screens/UserPortal/Events/Events.test.tsx
+++ b/src/screens/UserPortal/Events/Events.test.tsx
@@ -288,7 +288,7 @@ describe('Testing Events Screen [User Portal]', () => {
expect(screen.queryByText(mockEventTitle)).toBeInTheDocument();
});
- test('Search works as expected when user types in search input', async () => {
+ test('Search works as expected when user types in search input and press enter key', async () => {
const getOrganizationIdSpy = jest
.spyOn(getOrganizationId, 'default')
.mockImplementation(() => {
@@ -311,7 +311,7 @@ describe('Testing Events Screen [User Portal]', () => {
expect(getOrganizationIdSpy).toHaveBeenCalled();
- const randomSearchInput = 'test';
+ const randomSearchInput = 'test{enter}';
userEvent.type(screen.getByTestId('searchInput'), randomSearchInput);
await wait();
@@ -332,6 +332,55 @@ describe('Testing Events Screen [User Portal]', () => {
expect(screen.queryByText(mockEventTitleAbsent)).not.toBeInTheDocument();
});
+ test('Search works as expected when user types in search input and clicks search Btn', async () => {
+ const getOrganizationIdSpy = jest
+ .spyOn(getOrganizationId, 'default')
+ .mockImplementation(() => {
+ return '';
+ });
+
+ render(
+
+
+
+
+
+
+
+
+
+ );
+
+ await wait();
+
+ expect(getOrganizationIdSpy).toHaveBeenCalled();
+ const searchInput = screen.getByTestId('searchInput');
+ const searchBtn = screen.getByTestId('searchBtn');
+ userEvent.type(searchInput, '');
+ userEvent.click(searchBtn);
+ await wait();
+ userEvent.clear(searchInput);
+ userEvent.type(searchInput, 'test');
+ userEvent.click(searchBtn);
+
+ await wait();
+
+ let mockEventTitle = '';
+ if (MOCKS[0].result?.data.eventsByOrganizationConnection) {
+ mockEventTitle =
+ MOCKS[0].result?.data.eventsByOrganizationConnection[0].title;
+ }
+
+ let mockEventTitleAbsent = '';
+ if (MOCKS[0].result?.data.eventsByOrganizationConnection) {
+ mockEventTitleAbsent =
+ MOCKS[0].result?.data.eventsByOrganizationConnection[1].title;
+ }
+
+ expect(screen.queryByText(mockEventTitle)).toBeInTheDocument();
+ expect(screen.queryByText(mockEventTitleAbsent)).not.toBeInTheDocument();
+ });
+
test('Create event works as expected when event is not an all day event.', async () => {
const getOrganizationIdSpy = jest
.spyOn(getOrganizationId, 'default')
@@ -469,5 +518,6 @@ describe('Testing Events Screen [User Portal]', () => {
const calenderView = 'Calendar View';
expect(screen.queryAllByText(calenderView)).not.toBeNull();
+ expect(screen.getByText('Sun')).toBeInTheDocument();
});
});
diff --git a/src/screens/UserPortal/Events/Events.tsx b/src/screens/UserPortal/Events/Events.tsx
index caf1d72fd2..13bf916b6c 100644
--- a/src/screens/UserPortal/Events/Events.tsx
+++ b/src/screens/UserPortal/Events/Events.tsx
@@ -5,7 +5,10 @@ import EventCard from 'components/UserPortal/EventCard/EventCard';
import UserSidebar from 'components/UserPortal/UserSidebar/UserSidebar';
import { Button, Dropdown, Form, InputGroup } from 'react-bootstrap';
import PaginationList from 'components/PaginationList/PaginationList';
-import { ORGANIZATION_EVENTS_CONNECTION } from 'GraphQl/Queries/Queries';
+import {
+ ORGANIZATION_EVENTS_CONNECTION,
+ ORGANIZATIONS_LIST,
+} from 'GraphQl/Queries/Queries';
import { useMutation, useQuery } from '@apollo/client';
import { SearchOutlined } from '@mui/icons-material';
import styles from './Events.module.css';
@@ -18,6 +21,7 @@ import { CREATE_EVENT_MUTATION } from 'GraphQl/Mutations/mutations';
import dayjs from 'dayjs';
import { toast } from 'react-toastify';
import { errorHandler } from 'utils/errorHandler';
+import EventCalendar from 'components/EventCalendar/EventCalendar';
interface InterfaceEventCardProps {
id: string;
@@ -50,7 +54,6 @@ export default function events(): JSX.Element {
const [page, setPage] = React.useState(0);
const [rowsPerPage, setRowsPerPage] = React.useState(5);
const [events, setEvents] = React.useState([]);
- const [filterName, setFilterName] = React.useState('');
const [mode, setMode] = React.useState(0);
const [showCreateEventModal, setShowCreateEventModal] = React.useState(false);
const [eventTitle, setEventTitle] = React.useState('');
@@ -76,8 +79,15 @@ export default function events(): JSX.Element {
},
});
+ const { data: orgData } = useQuery(ORGANIZATIONS_LIST, {
+ variables: { id: organizationId },
+ });
+
const [create] = useMutation(CREATE_EVENT_MUTATION);
+ const userId = localStorage.getItem('id') as string;
+ const userRole = localStorage.getItem('UserType') as string;
+
const createEvent = async (): Promise => {
try {
const { data: createEventData } = await create({
@@ -109,6 +119,7 @@ export default function events(): JSX.Element {
setStartTime('08:00:00');
setEndTime('10:00:00');
}
+ setShowCreateEventModal(false);
} catch (error: any) {
/* istanbul ignore next */
errorHandler(t, error);
@@ -136,16 +147,23 @@ export default function events(): JSX.Element {
setPage(0);
};
- const handleSearch = (
- event: React.ChangeEvent
- ): void => {
- const newFilter = event.target.value;
- setFilterName(newFilter);
- const filter = {
- title_contains: newFilter,
- };
+ const handleSearch = (value: string): void => {
+ refetch({
+ title_contains: value,
+ });
setPage(0);
- refetch(filter);
+ };
+ const handleSearchByEnter = (e: any): void => {
+ if (e.key === 'Enter') {
+ const { value } = e.target;
+ handleSearch(value);
+ }
+ };
+ const handleSearchByBtnClick = (): void => {
+ const value =
+ (document.getElementById('searchEvents') as HTMLInputElement)?.value ||
+ '';
+ handleSearch(value);
};
const handleEventTitleChange = (
@@ -198,15 +216,18 @@ export default function events(): JSX.Element {
>
@@ -243,83 +264,95 @@ export default function events(): JSX.Element {