+
>
diff --git a/src/components/UserPortal/CreateDirectChat/CreateDirectChat.module.css b/src/components/UserPortal/CreateDirectChat/CreateDirectChat.module.css
new file mode 100644
index 0000000000..3795e402fa
--- /dev/null
+++ b/src/components/UserPortal/CreateDirectChat/CreateDirectChat.module.css
@@ -0,0 +1,9 @@
+.userData {
+ height: 400px;
+ overflow-y: scroll;
+ overflow-x: hidden !important;
+}
+
+.modalContent {
+ width: 530px;
+}
diff --git a/src/components/UserPortal/CreateDirectChat/CreateDirectChat.test.tsx b/src/components/UserPortal/CreateDirectChat/CreateDirectChat.test.tsx
new file mode 100644
index 0000000000..e3e2eae75c
--- /dev/null
+++ b/src/components/UserPortal/CreateDirectChat/CreateDirectChat.test.tsx
@@ -0,0 +1,1496 @@
+import React from 'react';
+import {
+ act,
+ fireEvent,
+ render,
+ screen,
+ waitFor,
+} from '@testing-library/react';
+import { MockedProvider } from '@apollo/react-testing';
+import { I18nextProvider, useTranslation } from 'react-i18next';
+import { USERS_CONNECTION_LIST } from 'GraphQl/Queries/Queries';
+import { BrowserRouter } from 'react-router-dom';
+import { Provider } from 'react-redux';
+import { store } from 'state/store';
+import i18nForTest from 'utils/i18nForTest';
+import Chat from '../../../screens/UserPortal/Chat/Chat';
+import {
+ CREATE_CHAT,
+ MESSAGE_SENT_TO_CHAT,
+} from 'GraphQl/Mutations/OrganizationMutations';
+import { CHATS_LIST, CHAT_BY_ID } from 'GraphQl/Queries/PlugInQueries';
+import useLocalStorage from 'utils/useLocalstorage';
+
+const { setItem } = useLocalStorage();
+
+const UserConnectionListMock = [
+ {
+ request: {
+ query: USERS_CONNECTION_LIST,
+ variables: {
+ firstName_contains: '',
+ lastName_contains: '',
+ },
+ },
+ result: {
+ data: {
+ users: [
+ {
+ user: {
+ firstName: 'Deanne',
+ lastName: 'Marks',
+ image: null,
+ _id: '6589389d2caa9d8d69087487',
+ email: 'testuser8@example.com',
+ createdAt: '2023-04-13T04:53:17.742Z',
+ organizationsBlockedBy: [],
+ joinedOrganizations: [
+ {
+ _id: '6537904485008f171cf29924',
+ name: 'Unity Foundation',
+ image: null,
+ address: {
+ city: 'Queens',
+ countryCode: 'US',
+ dependentLocality: 'Some Dependent Locality',
+ line1: '123 Coffee Street',
+ line2: 'Apartment 501',
+ postalCode: '11427',
+ sortingCode: 'ABC-133',
+ state: 'NYC',
+ __typename: 'Address',
+ },
+ createdAt: '2023-04-13T05:16:52.827Z',
+ creator: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: null,
+ email: 'testsuperadmin@example.com',
+ createdAt: '2023-04-13T04:53:17.742Z',
+ __typename: 'User',
+ },
+ __typename: 'Organization',
+ },
+ {
+ _id: '6637904485008f171cf29924',
+ name: 'Unity Foundation',
+ image: null,
+ address: {
+ city: 'Staten Island',
+ countryCode: 'US',
+ dependentLocality: 'Some Dependent Locality',
+ line1: '123 church Street',
+ line2: 'Apartment 499',
+ postalCode: '10301',
+ sortingCode: 'ABC-122',
+ state: 'NYC',
+ __typename: 'Address',
+ },
+ createdAt: '2023-04-13T05:16:52.827Z',
+ creator: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: null,
+ email: 'testsuperadmin@example.com',
+ createdAt: '2023-04-13T04:53:17.742Z',
+ __typename: 'User',
+ },
+ __typename: 'Organization',
+ },
+ {
+ _id: '6737904485008f171cf29924',
+ name: 'Unity Foundation',
+ image: null,
+ address: {
+ city: 'Brooklyn',
+ countryCode: 'US',
+ dependentLocality: 'Sample Dependent Locality',
+ line1: '123 Main Street',
+ line2: 'Apt 456',
+ postalCode: '10004',
+ sortingCode: 'ABC-789',
+ state: 'NY',
+ __typename: 'Address',
+ },
+ createdAt: '2023-04-13T05:16:52.827Z',
+ creator: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: null,
+ email: 'testsuperadmin@example.com',
+ createdAt: '2023-04-13T04:53:17.742Z',
+ __typename: 'User',
+ },
+ __typename: 'Organization',
+ },
+ {
+ _id: '6437904485008f171cf29924',
+ name: 'Unity Foundation',
+ image: null,
+ address: {
+ city: 'Bronx',
+ countryCode: 'US',
+ dependentLocality: 'Some Dependent Locality',
+ line1: '123 Random Street',
+ line2: 'Apartment 456',
+ postalCode: '10451',
+ sortingCode: 'ABC-123',
+ state: 'NYC',
+ __typename: 'Address',
+ },
+ createdAt: '2023-04-13T05:16:52.827Z',
+ creator: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: null,
+ email: 'testsuperadmin@example.com',
+ createdAt: '2023-04-13T04:53:17.742Z',
+ __typename: 'User',
+ },
+ __typename: 'Organization',
+ },
+ ],
+ __typename: 'User',
+ },
+ appUserProfile: {
+ _id: '64378abd85308f171cf2993d',
+ adminFor: [],
+ isSuperAdmin: false,
+ createdOrganizations: [],
+ createdEvents: [],
+ eventAdmin: [],
+ __typename: 'AppUserProfile',
+ },
+ __typename: 'UserData',
+ },
+ ],
+ },
+ },
+ },
+ {
+ request: {
+ query: USERS_CONNECTION_LIST,
+ variables: {
+ firstName_contains: 'Disha',
+ lastName_contains: '',
+ },
+ },
+ result: {
+ data: {
+ users: [
+ {
+ user: {
+ firstName: 'Deanne',
+ lastName: 'Marks',
+ image: null,
+ _id: '6589389d2caa9d8d69087487',
+ email: 'testuser8@example.com',
+ createdAt: '2023-04-13T04:53:17.742Z',
+ organizationsBlockedBy: [],
+ joinedOrganizations: [
+ {
+ _id: '6537904485008f171cf29924',
+ name: 'Unity Foundation',
+ image: null,
+ address: {
+ city: 'Queens',
+ countryCode: 'US',
+ dependentLocality: 'Some Dependent Locality',
+ line1: '123 Coffee Street',
+ line2: 'Apartment 501',
+ postalCode: '11427',
+ sortingCode: 'ABC-133',
+ state: 'NYC',
+ __typename: 'Address',
+ },
+ createdAt: '2023-04-13T05:16:52.827Z',
+ creator: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: null,
+ email: 'testsuperadmin@example.com',
+ createdAt: '2023-04-13T04:53:17.742Z',
+ __typename: 'User',
+ },
+ __typename: 'Organization',
+ },
+ {
+ _id: '6637904485008f171cf29924',
+ name: 'Unity Foundation',
+ image: null,
+ address: {
+ city: 'Staten Island',
+ countryCode: 'US',
+ dependentLocality: 'Some Dependent Locality',
+ line1: '123 church Street',
+ line2: 'Apartment 499',
+ postalCode: '10301',
+ sortingCode: 'ABC-122',
+ state: 'NYC',
+ __typename: 'Address',
+ },
+ createdAt: '2023-04-13T05:16:52.827Z',
+ creator: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: null,
+ email: 'testsuperadmin@example.com',
+ createdAt: '2023-04-13T04:53:17.742Z',
+ __typename: 'User',
+ },
+ __typename: 'Organization',
+ },
+ {
+ _id: '6737904485008f171cf29924',
+ name: 'Unity Foundation',
+ image: null,
+ address: {
+ city: 'Brooklyn',
+ countryCode: 'US',
+ dependentLocality: 'Sample Dependent Locality',
+ line1: '123 Main Street',
+ line2: 'Apt 456',
+ postalCode: '10004',
+ sortingCode: 'ABC-789',
+ state: 'NY',
+ __typename: 'Address',
+ },
+ createdAt: '2023-04-13T05:16:52.827Z',
+ creator: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: null,
+ email: 'testsuperadmin@example.com',
+ createdAt: '2023-04-13T04:53:17.742Z',
+ __typename: 'User',
+ },
+ __typename: 'Organization',
+ },
+ {
+ _id: '6437904485008f171cf29924',
+ name: 'Unity Foundation',
+ image: null,
+ address: {
+ city: 'Bronx',
+ countryCode: 'US',
+ dependentLocality: 'Some Dependent Locality',
+ line1: '123 Random Street',
+ line2: 'Apartment 456',
+ postalCode: '10451',
+ sortingCode: 'ABC-123',
+ state: 'NYC',
+ __typename: 'Address',
+ },
+ createdAt: '2023-04-13T05:16:52.827Z',
+ creator: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: null,
+ email: 'testsuperadmin@example.com',
+ createdAt: '2023-04-13T04:53:17.742Z',
+ __typename: 'User',
+ },
+ __typename: 'Organization',
+ },
+ ],
+ __typename: 'User',
+ },
+ appUserProfile: {
+ _id: '64378abd85308f171cf2993d',
+ adminFor: [],
+ isSuperAdmin: false,
+ createdOrganizations: [],
+ createdEvents: [],
+ eventAdmin: [],
+ __typename: 'AppUserProfile',
+ },
+ __typename: 'UserData',
+ },
+ ],
+ },
+ },
+ },
+];
+
+const MESSAGE_SENT_TO_CHAT_MOCK = [
+ {
+ request: {
+ query: MESSAGE_SENT_TO_CHAT,
+ variables: {
+ userId: null,
+ },
+ },
+ result: {
+ data: {
+ messageSentToChat: {
+ _id: '668ec1f1364e03ac47a151',
+ createdAt: '2024-07-10T17:16:33.248Z',
+ messageContent: 'Test ',
+ type: 'STRING',
+ replyTo: null,
+ sender: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: '',
+ },
+ updatedAt: '2024-07-10',
+ },
+ },
+ },
+ },
+ {
+ request: {
+ query: MESSAGE_SENT_TO_CHAT,
+ variables: {
+ userId: '2',
+ },
+ },
+ result: {
+ data: {
+ messageSentToGroupChat: {
+ _id: '668ec1f1df364e03ac47a151',
+ createdAt: '2024-07-10T17:16:33.248Z',
+ messageContent: 'Test ',
+ replyTo: null,
+ type: 'STRING',
+ sender: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: '',
+ },
+ updatedAt: '2024-07-10',
+ },
+ },
+ },
+ },
+ {
+ request: {
+ query: MESSAGE_SENT_TO_CHAT,
+ variables: {
+ userId: '1',
+ },
+ },
+ result: {
+ data: {
+ messageSentToGroupChat: {
+ _id: '668ec1f13603ac4697a151',
+ createdAt: '2024-07-10T17:16:33.248Z',
+ messageContent: 'Test ',
+ replyTo: null,
+ type: 'STRING',
+ sender: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: '',
+ },
+ updatedAt: '2024-07-10',
+ },
+ },
+ },
+ },
+];
+
+const CHAT_BY_ID_QUERY_MOCK = [
+ {
+ request: {
+ query: CHAT_BY_ID,
+ variables: {
+ id: '1',
+ },
+ },
+ result: {
+ data: {
+ chatById: {
+ _id: '1',
+ createdAt: '2345678903456',
+ isGroup: false,
+ creator: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: null,
+ email: 'testsuperadmin@example.com',
+ createdAt: '2023-04-13T04:53:17.742Z',
+ __typename: 'User',
+ },
+ organization: null,
+ name: '',
+ messages: [
+ {
+ _id: '345678',
+ createdAt: '345678908765',
+ messageContent: 'Hello',
+ replyTo: null,
+ type: 'STRING',
+ sender: {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ },
+ ],
+ users: [
+ {
+ _id: '1',
+ firstName: 'Disha',
+ lastName: 'Talreja',
+ email: 'disha@example.com',
+ image: '',
+ },
+ {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ ],
+ },
+ },
+ },
+ },
+ {
+ request: {
+ query: CHAT_BY_ID,
+ variables: {
+ id: '1',
+ },
+ },
+ result: {
+ data: {
+ chatById: {
+ _id: '1',
+ isGroup: false,
+ creator: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: null,
+ email: 'testsuperadmin@example.com',
+ createdAt: '2023-04-13T04:53:17.742Z',
+ __typename: 'User',
+ },
+ organization: null,
+ name: '',
+ createdAt: '2345678903456',
+ messages: [
+ {
+ _id: '345678',
+ createdAt: '345678908765',
+ messageContent: 'Hello',
+ replyTo: null,
+ type: 'STRING',
+ sender: {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ },
+ ],
+ users: [
+ {
+ _id: '1',
+ firstName: 'Disha',
+ lastName: 'Talreja',
+ email: 'disha@example.com',
+ image: '',
+ },
+ {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ ],
+ },
+ },
+ },
+ },
+ {
+ request: {
+ query: CHAT_BY_ID,
+ variables: {
+ id: '',
+ },
+ },
+ result: {
+ data: {
+ chatById: {
+ _id: '1',
+ isGroup: false,
+ creator: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: null,
+ email: 'testsuperadmin@example.com',
+ createdAt: '2023-04-13T04:53:17.742Z',
+ __typename: 'User',
+ },
+ organization: null,
+ name: '',
+ createdAt: '2345678903456',
+ messages: [
+ {
+ _id: '345678',
+ createdAt: '345678908765',
+ messageContent: 'Hello',
+ replyTo: null,
+ type: 'STRING',
+ sender: {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ },
+ ],
+ users: [
+ {
+ _id: '1',
+ firstName: 'Disha',
+ lastName: 'Talreja',
+ email: 'disha@example.com',
+ image: '',
+ },
+ {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ ],
+ },
+ },
+ },
+ },
+];
+
+const CHATS_LIST_MOCK = [
+ {
+ request: {
+ query: CHATS_LIST,
+ variables: {
+ id: null,
+ },
+ },
+ result: {
+ data: {
+ chatsByUserId: [
+ {
+ _id: '65844efc814dd40fgh03db811c4',
+ isGroup: true,
+ creator: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: null,
+ email: 'testsuperadmin@example.com',
+ createdAt: '2023-04-13T04:53:17.742Z',
+ __typename: 'User',
+ },
+ organization: {
+ _id: 'pw3ertyuiophgfre45678',
+ name: 'rtyu',
+ },
+ createdAt: '2345678903456',
+ name: 'Test Group Chat',
+ messages: [
+ {
+ _id: '345678',
+ createdAt: '345678908765',
+ messageContent: 'Hello',
+ replyTo: null,
+ type: 'STRING',
+ sender: {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ },
+ ],
+ users: [
+ {
+ _id: '1',
+ firstName: 'Disha',
+ lastName: 'Talreja',
+ email: 'disha@example.com',
+ image: '',
+ },
+ {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ {
+ _id: '3',
+ firstName: 'Test',
+ lastName: 'User1',
+ email: 'test1@example.com',
+ image: '',
+ },
+ {
+ _id: '4',
+ firstName: 'Test',
+ lastName: 'User2',
+ email: 'test2@example.com',
+ image: '',
+ },
+ {
+ _id: '5',
+ firstName: 'Test',
+ lastName: 'User4',
+ email: 'test4@example.com',
+ image: '',
+ },
+ ],
+ },
+ {
+ _id: '65844efc814ddgh4003db811c4',
+ isGroup: true,
+ creator: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: null,
+ email: 'testsuperadmin@example.com',
+ createdAt: '2023-04-13T04:53:17.742Z',
+ __typename: 'User',
+ },
+ organization: {
+ _id: 'pw3ertyuiophgfre45678',
+ name: 'rtyu',
+ },
+ createdAt: '2345678903456',
+ name: 'Test Group Chat',
+ messages: [
+ {
+ _id: '345678',
+ createdAt: '345678908765',
+ messageContent: 'Hello',
+ replyTo: null,
+ type: 'STRING',
+ sender: {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ },
+ ],
+ users: [
+ {
+ _id: '1',
+ firstName: 'Disha',
+ lastName: 'Talreja',
+ email: 'disha@example.com',
+ image: '',
+ },
+ {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ {
+ _id: '3',
+ firstName: 'Test',
+ lastName: 'User1',
+ email: 'test1@example.com',
+ image: '',
+ },
+ {
+ _id: '4',
+ firstName: 'Test',
+ lastName: 'User2',
+ email: 'test2@example.com',
+ image: '',
+ },
+ {
+ _id: '5',
+ firstName: 'Test',
+ lastName: 'User4',
+ email: 'test4@example.com',
+ image: '',
+ },
+ ],
+ },
+ ],
+ },
+ },
+ },
+ {
+ request: {
+ query: CHATS_LIST,
+ variables: {
+ id: '',
+ },
+ },
+ result: {
+ data: {
+ chatsByUserId: [
+ {
+ _id: '65844ghjefc814dd4003db811c4',
+ isGroup: true,
+ creator: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: null,
+ email: 'testsuperadmin@example.com',
+ createdAt: '2023-04-13T04:53:17.742Z',
+ __typename: 'User',
+ },
+ organization: {
+ _id: 'pw3ertyuiophgfre45678',
+ name: 'rtyu',
+ },
+ createdAt: '2345678903456',
+ name: 'Test Group Chat',
+ messages: [
+ {
+ _id: '345678',
+ createdAt: '345678908765',
+ messageContent: 'Hello',
+ replyTo: null,
+ type: 'STRING',
+ sender: {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ },
+ ],
+ users: [
+ {
+ _id: '1',
+ firstName: 'Disha',
+ lastName: 'Talreja',
+ email: 'disha@example.com',
+ image: '',
+ },
+ {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ {
+ _id: '3',
+ firstName: 'Test',
+ lastName: 'User1',
+ email: 'test1@example.com',
+ image: '',
+ },
+ {
+ _id: '4',
+ firstName: 'Test',
+ lastName: 'User2',
+ email: 'test2@example.com',
+ image: '',
+ },
+ {
+ _id: '5',
+ firstName: 'Test',
+ lastName: 'User4',
+ email: 'test4@example.com',
+ image: '',
+ },
+ ],
+ },
+ {
+ _id: 'ujhgtrdtyuiop',
+ isGroup: true,
+ creator: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: null,
+ email: 'testsuperadmin@example.com',
+ createdAt: '2023-04-13T04:53:17.742Z',
+ __typename: 'User',
+ },
+ organization: {
+ _id: 'pw3ertyuiophgfre45678',
+ name: 'rtyu',
+ },
+ createdAt: '2345678903456',
+ name: 'Test Group Chat',
+ messages: [
+ {
+ _id: '345678',
+ createdAt: '345678908765',
+ messageContent: 'Hello',
+ replyTo: null,
+ type: 'STRING',
+ sender: {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ },
+ ],
+ users: [
+ {
+ _id: '1',
+ firstName: 'Disha',
+ lastName: 'Talreja',
+ email: 'disha@example.com',
+ image: '',
+ },
+ {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ {
+ _id: '3',
+ firstName: 'Test',
+ lastName: 'User1',
+ email: 'test1@example.com',
+ image: '',
+ },
+ {
+ _id: '4',
+ firstName: 'Test',
+ lastName: 'User2',
+ email: 'test2@example.com',
+ image: '',
+ },
+ {
+ _id: '5',
+ firstName: 'Test',
+ lastName: 'User4',
+ email: 'test4@example.com',
+ image: '',
+ },
+ ],
+ },
+ ],
+ },
+ },
+ },
+ {
+ request: {
+ query: CHATS_LIST,
+ variables: {
+ id: '1',
+ },
+ },
+ result: {
+ data: {
+ chatsByUserId: [
+ {
+ _id: '65844efc814dhjmkdftyd4003db811c4',
+ isGroup: true,
+ creator: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: null,
+ email: 'testsuperadmin@example.com',
+ createdAt: '2023-04-13T04:53:17.742Z',
+ __typename: 'User',
+ },
+ organization: {
+ _id: 'pw3ertyuiophgfre45678',
+ name: 'rtyu',
+ },
+ createdAt: '2345678903456',
+ name: 'Test Group Chat',
+ messages: [
+ {
+ _id: '345678',
+ createdAt: '345678908765',
+ messageContent: 'Hello',
+ replyTo: null,
+ type: 'STRING',
+ sender: {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ },
+ ],
+ users: [
+ {
+ _id: '1',
+ firstName: 'Disha',
+ lastName: 'Talreja',
+ email: 'disha@example.com',
+ image: '',
+ },
+ {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ {
+ _id: '3',
+ firstName: 'Test',
+ lastName: 'User1',
+ email: 'test1@example.com',
+ image: '',
+ },
+ {
+ _id: '4',
+ firstName: 'Test',
+ lastName: 'User2',
+ email: 'test2@example.com',
+ image: '',
+ },
+ {
+ _id: '5',
+ firstName: 'Test',
+ lastName: 'User4',
+ email: 'test4@example.com',
+ image: '',
+ },
+ ],
+ },
+ {
+ _id: '65844ewsedrffc814dd4003db811c4',
+ isGroup: true,
+ creator: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: null,
+ email: 'testsuperadmin@example.com',
+ createdAt: '2023-04-13T04:53:17.742Z',
+ __typename: 'User',
+ },
+ organization: {
+ _id: 'pw3ertyuiophgfre45678',
+ name: 'rtyu',
+ },
+ createdAt: '2345678903456',
+ name: 'Test Group Chat',
+ messages: [
+ {
+ _id: '345678',
+ createdAt: '345678908765',
+ messageContent: 'Hello',
+ replyTo: null,
+ type: 'STRING',
+ sender: {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ },
+ ],
+ users: [
+ {
+ _id: '1',
+ firstName: 'Disha',
+ lastName: 'Talreja',
+ email: 'disha@example.com',
+ image: '',
+ },
+ {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ {
+ _id: '3',
+ firstName: 'Test',
+ lastName: 'User1',
+ email: 'test1@example.com',
+ image: '',
+ },
+ {
+ _id: '4',
+ firstName: 'Test',
+ lastName: 'User2',
+ email: 'test2@example.com',
+ image: '',
+ },
+ {
+ _id: '5',
+ firstName: 'Test',
+ lastName: 'User4',
+ email: 'test4@example.com',
+ image: '',
+ },
+ ],
+ },
+ ],
+ },
+ },
+ },
+ {
+ request: {
+ query: CHATS_LIST,
+ variables: {
+ id: '1',
+ },
+ },
+ result: {
+ data: {
+ chatsByUserId: [
+ {
+ _id: '65844efc814dhjmkdftyd4003db811c4',
+ isGroup: true,
+ creator: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: null,
+ email: 'testsuperadmin@example.com',
+ createdAt: '2023-04-13T04:53:17.742Z',
+ __typename: 'User',
+ },
+ organization: {
+ _id: 'pw3ertyuiophgfre45678',
+ name: 'rtyu',
+ },
+ createdAt: '2345678903456',
+ name: 'Test Group Chat',
+ messages: [
+ {
+ _id: '345678',
+ createdAt: '345678908765',
+ messageContent: 'Hello',
+ replyTo: null,
+ type: 'STRING',
+ sender: {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ },
+ ],
+ users: [
+ {
+ _id: '1',
+ firstName: 'Disha',
+ lastName: 'Talreja',
+ email: 'disha@example.com',
+ image: '',
+ },
+ {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ {
+ _id: '3',
+ firstName: 'Test',
+ lastName: 'User1',
+ email: 'test1@example.com',
+ image: '',
+ },
+ {
+ _id: '4',
+ firstName: 'Test',
+ lastName: 'User2',
+ email: 'test2@example.com',
+ image: '',
+ },
+ {
+ _id: '5',
+ firstName: 'Test',
+ lastName: 'User4',
+ email: 'test4@example.com',
+ image: '',
+ },
+ ],
+ },
+ {
+ _id: '65844ewsedrffc814dd4003db811c4',
+ isGroup: true,
+ creator: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: null,
+ email: 'testsuperadmin@example.com',
+ createdAt: '2023-04-13T04:53:17.742Z',
+ __typename: 'User',
+ },
+ organization: {
+ _id: 'pw3ertyuiophgfre45678',
+ name: 'rtyu',
+ },
+ createdAt: '2345678903456',
+ name: 'Test Group Chat',
+ messages: [
+ {
+ _id: '345678',
+ createdAt: '345678908765',
+ messageContent: 'Hello',
+ replyTo: null,
+ type: 'STRING',
+ sender: {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ },
+ ],
+ users: [
+ {
+ _id: '1',
+ firstName: 'Disha',
+ lastName: 'Talreja',
+ email: 'disha@example.com',
+ image: '',
+ },
+ {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ {
+ _id: '3',
+ firstName: 'Test',
+ lastName: 'User1',
+ email: 'test1@example.com',
+ image: '',
+ },
+ {
+ _id: '4',
+ firstName: 'Test',
+ lastName: 'User2',
+ email: 'test2@example.com',
+ image: '',
+ },
+ {
+ _id: '5',
+ firstName: 'Test',
+ lastName: 'User4',
+ email: 'test4@example.com',
+ image: '',
+ },
+ ],
+ },
+ ],
+ },
+ },
+ },
+];
+
+const GROUP_CHAT_BY_ID_QUERY_MOCK = [
+ {
+ request: {
+ query: CHAT_BY_ID,
+ variables: {
+ id: '',
+ },
+ },
+ result: {
+ data: {
+ chatById: {
+ _id: '65844efc814dd4003db811c4',
+ isGroup: true,
+ creator: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: null,
+ email: 'testsuperadmin@example.com',
+ createdAt: '2023-04-13T04:53:17.742Z',
+ __typename: 'User',
+ },
+ organization: {
+ _id: 'pw3ertyuiophgfre45678',
+ name: 'rtyu',
+ },
+ createdAt: '2345678903456',
+ name: 'Test Group Chat',
+ messages: [
+ {
+ _id: '345678',
+ createdAt: '345678908765',
+ messageContent: 'Hello',
+ replyTo: null,
+ type: 'STRING',
+ sender: {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ },
+ ],
+ users: [
+ {
+ _id: '1',
+ firstName: 'Disha',
+ lastName: 'Talreja',
+ email: 'disha@example.com',
+ image: '',
+ },
+ {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ {
+ _id: '3',
+ firstName: 'Test',
+ lastName: 'User1',
+ email: 'test1@example.com',
+ image: '',
+ },
+ {
+ _id: '4',
+ firstName: 'Test',
+ lastName: 'User2',
+ email: 'test2@example.com',
+ image: '',
+ },
+ {
+ _id: '5',
+ firstName: 'Test',
+ lastName: 'User4',
+ email: 'test4@example.com',
+ image: '',
+ },
+ ],
+ },
+ },
+ },
+ },
+];
+
+const CREATE_CHAT_MUTATION_MOCK = [
+ {
+ request: {
+ query: CREATE_CHAT,
+ variables: {
+ organizationId: undefined,
+ userIds: ['1', '6589389d2caa9d8d69087487'],
+ isGroup: false,
+ },
+ },
+ result: {
+ data: {
+ createChat: {
+ _id: '1',
+ createdAt: '2345678903456',
+ isGroup: false,
+ creator: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: null,
+ email: 'testsuperadmin@example.com',
+ createdAt: '2023-04-13T04:53:17.742Z',
+ __typename: 'User',
+ },
+ organization: null,
+ name: '',
+ messages: [
+ {
+ _id: '345678',
+ createdAt: '345678908765',
+ messageContent: 'Hello',
+ replyTo: null,
+ type: 'STRING',
+ sender: {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ },
+ ],
+ users: [
+ {
+ _id: '1',
+ firstName: 'Disha',
+ lastName: 'Talreja',
+ email: 'disha@example.com',
+ image: '',
+ },
+ {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ ],
+ },
+ },
+ },
+ },
+];
+
+async function wait(ms = 100): Promise
{
+ await act(() => {
+ return new Promise((resolve) => {
+ setTimeout(resolve, ms);
+ });
+ });
+}
+
+describe('Testing Create Direct Chat Modal [User Portal]', () => {
+ window.HTMLElement.prototype.scrollIntoView = jest.fn();
+
+ Object.defineProperty(window, 'matchMedia', {
+ writable: true,
+ value: jest.fn().mockImplementation((query) => ({
+ matches: false,
+ media: query,
+ onchange: null,
+ addListener: jest.fn(), // Deprecated
+ removeListener: jest.fn(), // Deprecated
+ addEventListener: jest.fn(),
+ removeEventListener: jest.fn(),
+ dispatchEvent: jest.fn(),
+ })),
+ });
+
+ test('Open and close create new direct chat modal', async () => {
+ const mock = [
+ ...GROUP_CHAT_BY_ID_QUERY_MOCK,
+ ...MESSAGE_SENT_TO_CHAT_MOCK,
+ ...UserConnectionListMock,
+ ...CHATS_LIST_MOCK,
+ ...CHAT_BY_ID_QUERY_MOCK,
+ ...CREATE_CHAT_MUTATION_MOCK,
+ ];
+ render(
+
+
+
+
+
+
+
+
+ ,
+ );
+
+ await wait();
+
+ const dropdown = await screen.findByTestId('dropdown');
+ expect(dropdown).toBeInTheDocument();
+ fireEvent.click(dropdown);
+ const newDirectChatBtn = await screen.findByTestId('newDirectChat');
+ expect(newDirectChatBtn).toBeInTheDocument();
+ fireEvent.click(newDirectChatBtn);
+
+ const submitBtn = await screen.findByTestId('submitBtn');
+ expect(submitBtn).toBeInTheDocument();
+
+ const searchInput = (await screen.findByTestId(
+ 'searchUser',
+ )) as HTMLInputElement;
+ expect(searchInput).toBeInTheDocument();
+
+ fireEvent.change(searchInput, { target: { value: 'Disha' } });
+
+ expect(searchInput.value).toBe('Disha');
+
+ fireEvent.click(submitBtn);
+
+ const closeButton = screen.getByRole('button', { name: /close/i });
+ expect(closeButton).toBeInTheDocument();
+
+ fireEvent.click(closeButton);
+ });
+
+ test('create new direct chat', async () => {
+ setItem('userId', '1');
+ const mock = [
+ ...GROUP_CHAT_BY_ID_QUERY_MOCK,
+ ...MESSAGE_SENT_TO_CHAT_MOCK,
+ ...UserConnectionListMock,
+ ...CHATS_LIST_MOCK,
+ ...CHAT_BY_ID_QUERY_MOCK,
+ ...CREATE_CHAT_MUTATION_MOCK,
+ ];
+ render(
+
+
+
+
+
+
+
+
+ ,
+ );
+
+ await wait();
+
+ const dropdown = await screen.findByTestId('dropdown');
+ expect(dropdown).toBeInTheDocument();
+ fireEvent.click(dropdown);
+ const newDirectChatBtn = await screen.findByTestId('newDirectChat');
+ expect(newDirectChatBtn).toBeInTheDocument();
+ fireEvent.click(newDirectChatBtn);
+
+ const addBtn = await screen.findAllByTestId('addBtn');
+ waitFor(() => {
+ expect(addBtn[0]).toBeInTheDocument();
+ });
+
+ fireEvent.click(addBtn[0]);
+
+ const closeButton = screen.getByRole('button', { name: /close/i });
+ expect(closeButton).toBeInTheDocument();
+
+ fireEvent.click(closeButton);
+
+ await new Promise(process.nextTick);
+
+ await wait();
+ });
+});
diff --git a/src/components/UserPortal/CreateDirectChat/CreateDirectChat.tsx b/src/components/UserPortal/CreateDirectChat/CreateDirectChat.tsx
new file mode 100644
index 0000000000..e0ee9613c3
--- /dev/null
+++ b/src/components/UserPortal/CreateDirectChat/CreateDirectChat.tsx
@@ -0,0 +1,213 @@
+import { Paper, TableBody } from '@mui/material';
+import React, { useState } from 'react';
+import { Button, Form, Modal } from 'react-bootstrap';
+import styles from './CreateDirectChat.module.css';
+import type { ApolloQueryResult } from '@apollo/client';
+import { useMutation, useQuery } from '@apollo/client';
+import useLocalStorage from 'utils/useLocalstorage';
+import {
+ CREATE_CHAT,
+ CREATE_DIRECT_CHAT,
+} from 'GraphQl/Mutations/OrganizationMutations';
+import Table from '@mui/material/Table';
+import TableCell, { tableCellClasses } from '@mui/material/TableCell';
+import TableContainer from '@mui/material/TableContainer';
+import TableHead from '@mui/material/TableHead';
+import TableRow from '@mui/material/TableRow';
+import { styled } from '@mui/material/styles';
+import type { InterfaceQueryUserListItem } from 'utils/interfaces';
+import { USERS_CONNECTION_LIST } from 'GraphQl/Queries/Queries';
+import Loader from 'components/Loader/Loader';
+import { Search } from '@mui/icons-material';
+import { useTranslation } from 'react-i18next';
+import { useParams } from 'react-router-dom';
+
+interface InterfaceCreateDirectChatProps {
+ toggleCreateDirectChatModal: () => void;
+ createDirectChatModalisOpen: boolean;
+ chatsListRefetch: (
+ variables?:
+ | Partial<{
+ id: any;
+ }>
+ | undefined,
+ ) => Promise>;
+}
+
+/**
+ * Styled table cell with custom styles.
+ */
+
+const StyledTableCell = styled(TableCell)(({ theme }) => ({
+ [`&.${tableCellClasses.head}`]: {
+ backgroundColor: ['#31bb6b', '!important'],
+ color: theme.palette.common.white,
+ },
+ [`&.${tableCellClasses.body}`]: {
+ fontSize: 14,
+ },
+}));
+
+/**
+ * Styled table row with custom styles.
+ */
+
+const StyledTableRow = styled(TableRow)(() => ({
+ '&:last-child td, &:last-child th': {
+ border: 0,
+ },
+}));
+
+const { getItem } = useLocalStorage();
+
+export default function createDirectChatModal({
+ toggleCreateDirectChatModal,
+ createDirectChatModalisOpen,
+ chatsListRefetch,
+}: InterfaceCreateDirectChatProps): JSX.Element {
+ const { t } = useTranslation('translation', {
+ keyPrefix: 'userChat',
+ });
+
+ const { orgId: organizationId } = useParams();
+
+ const userId: string | null = getItem('userId');
+
+ const [userName, setUserName] = useState('');
+
+ const [createChat] = useMutation(CREATE_CHAT);
+
+ const handleCreateDirectChat = async (id: string): Promise => {
+ await createChat({
+ variables: {
+ organizationId,
+ userIds: [userId, id],
+ isGroup: false,
+ },
+ });
+ await chatsListRefetch();
+ toggleCreateDirectChatModal();
+ };
+
+ const {
+ data: allUsersData,
+ loading: allUsersLoading,
+ refetch: allUsersRefetch,
+ } = useQuery(USERS_CONNECTION_LIST, {
+ variables: {
+ firstName_contains: '',
+ lastName_contains: '',
+ },
+ });
+
+ const handleUserModalSearchChange = (e: React.FormEvent): void => {
+ e.preventDefault();
+ /* istanbul ignore next */
+ const [firstName, lastName] = userName.split(' ');
+
+ const newFilterData = {
+ firstName_contains: firstName || '',
+ lastName_contains: lastName || '',
+ };
+
+ allUsersRefetch({
+ ...newFilterData,
+ });
+ };
+
+ return (
+ <>
+
+
+ {'Chat'}
+
+
+ {allUsersLoading ? (
+ <>
+
+ >
+ ) : (
+ <>
+
+
{
+ const { value } = e.target;
+ setUserName(value);
+ }}
+ />
+
+
+
+
+
+
+
+ #
+ {'user'}
+ {'Chat'}
+
+
+
+ {allUsersData &&
+ allUsersData.users.length > 0 &&
+ allUsersData.users.map(
+ (
+ userDetails: InterfaceQueryUserListItem,
+ index: number,
+ ) => (
+
+
+ {index + 1}
+
+
+ {userDetails.user.firstName +
+ ' ' +
+ userDetails.user.lastName}
+
+ {userDetails.user.email}
+
+
+
+
+
+ ),
+ )}
+
+
+
+ >
+ )}
+
+
+ >
+ );
+}
diff --git a/src/components/UserPortal/CreateGroupChat/CreateGroupChat.module.css b/src/components/UserPortal/CreateGroupChat/CreateGroupChat.module.css
new file mode 100644
index 0000000000..3795e402fa
--- /dev/null
+++ b/src/components/UserPortal/CreateGroupChat/CreateGroupChat.module.css
@@ -0,0 +1,9 @@
+.userData {
+ height: 400px;
+ overflow-y: scroll;
+ overflow-x: hidden !important;
+}
+
+.modalContent {
+ width: 530px;
+}
diff --git a/src/components/UserPortal/CreateGroupChat/CreateGroupChat.test.tsx b/src/components/UserPortal/CreateGroupChat/CreateGroupChat.test.tsx
new file mode 100644
index 0000000000..7eeaeacac1
--- /dev/null
+++ b/src/components/UserPortal/CreateGroupChat/CreateGroupChat.test.tsx
@@ -0,0 +1,2455 @@
+import React from 'react';
+import {
+ act,
+ fireEvent,
+ render,
+ screen,
+ waitFor,
+ within,
+} from '@testing-library/react';
+import { MockedProvider } from '@apollo/react-testing';
+import { I18nextProvider } from 'react-i18next';
+
+import {
+ USERS_CONNECTION_LIST,
+ USER_JOINED_ORGANIZATIONS,
+} from 'GraphQl/Queries/Queries';
+import { BrowserRouter } from 'react-router-dom';
+import { Provider } from 'react-redux';
+import { store } from 'state/store';
+import i18nForTest from 'utils/i18nForTest';
+import Chat from '../../../screens/UserPortal/Chat/Chat';
+import {
+ CREATE_CHAT,
+ MESSAGE_SENT_TO_CHAT,
+} from 'GraphQl/Mutations/OrganizationMutations';
+import { CHATS_LIST, CHAT_BY_ID } from 'GraphQl/Queries/PlugInQueries';
+import useLocalStorage from 'utils/useLocalstorage';
+import userEvent from '@testing-library/user-event';
+
+const { setItem } = useLocalStorage();
+
+const USER_JOINED_ORG_MOCK = [
+ {
+ request: {
+ query: USER_JOINED_ORGANIZATIONS,
+ variables: {
+ id: '1',
+ },
+ },
+ result: {
+ data: {
+ users: [
+ {
+ user: {
+ joinedOrganizations: [
+ {
+ __typename: 'Organization',
+ _id: '6401ff65ce8e8406b8f07af2',
+ name: 'Test Org 1',
+ image: '',
+ description: 'New Desc',
+ address: {
+ city: 'abc',
+ countryCode: '123',
+ postalCode: '456',
+ state: 'def',
+ dependentLocality: 'ghi',
+ line1: 'asdfg',
+ line2: 'dfghj',
+ sortingCode: '4567',
+ },
+ createdAt: '1234567890',
+ userRegistrationRequired: true,
+ creator: {
+ __typename: 'User',
+ firstName: 'John',
+ lastName: 'Doe',
+ },
+ members: [
+ {
+ _id: '56gheqyr7deyfuiwfewifruy8',
+ user: {
+ _id: '45ydeg2yet721rtgdu32ry',
+ },
+ },
+ ],
+ admins: [
+ {
+ _id: '45gj5678jk45678fvgbhnr4rtgh',
+ user: {
+ _id: '45ydeg2yet721rtgdu32ry',
+ },
+ },
+ ],
+ membershipRequests: [
+ {
+ _id: '56gheqyr7deyfuiwfewifruy8',
+ user: {
+ _id: '45ydeg2yet721rtgdu32ry',
+ },
+ },
+ ],
+ },
+ {
+ __typename: 'Organization',
+ _id: '6401ff65ce8e8406b8f07af2',
+ name: 'Test Org 1',
+ image: '',
+ description: 'New Desc',
+ address: {
+ city: 'abc',
+ countryCode: '123',
+ postalCode: '456',
+ state: 'def',
+ dependentLocality: 'ghi',
+ line1: 'asdfg',
+ line2: 'dfghj',
+ sortingCode: '4567',
+ },
+ createdAt: '1234567890',
+ userRegistrationRequired: true,
+ creator: {
+ __typename: 'User',
+ firstName: 'John',
+ lastName: 'Doe',
+ },
+ members: [
+ {
+ _id: '56gheqyr7deyfuiwfewifruy8',
+ user: {
+ _id: '45ydeg2yet721rtgdu32ry',
+ },
+ },
+ ],
+ admins: [
+ {
+ _id: '45gj5678jk45678fvgbhnr4rtgh',
+ user: {
+ _id: '45ydeg2yet721rtgdu32ry',
+ },
+ },
+ ],
+ membershipRequests: [
+ {
+ _id: '56gheqyr7deyfuiwfewifruy8',
+ user: {
+ _id: '45ydeg2yet721rtgdu32ry',
+ },
+ },
+ ],
+ },
+ {
+ __typename: 'Organization',
+ _id: '6401ff65ce8e8406b8f07af2',
+ name: 'Test Org 1',
+ image: '',
+ description: 'New Desc',
+ address: {
+ city: 'abc',
+ countryCode: '123',
+ postalCode: '456',
+ state: 'def',
+ dependentLocality: 'ghi',
+ line1: 'asdfg',
+ line2: 'dfghj',
+ sortingCode: '4567',
+ },
+ createdAt: '1234567890',
+ userRegistrationRequired: true,
+ creator: {
+ __typename: 'User',
+ firstName: 'John',
+ lastName: 'Doe',
+ },
+ members: [
+ {
+ _id: '56gheqyr7deyfuiwfewifruy8',
+ user: {
+ _id: '45ydeg2yet721rtgdu32ry',
+ },
+ },
+ ],
+ admins: [
+ {
+ _id: '45gj5678jk45678fvgbhnr4rtgh',
+ user: {
+ _id: '45ydeg2yet721rtgdu32ry',
+ },
+ },
+ ],
+ membershipRequests: [
+ {
+ _id: '56gheqyr7deyfuiwfewifruy8',
+ user: {
+ _id: '45ydeg2yet721rtgdu32ry',
+ },
+ },
+ ],
+ },
+ {
+ __typename: 'Organization',
+ _id: '6401ff65ce8e8406b8f07af2',
+ name: 'Test Org 1',
+ image: '',
+ description: 'New Desc',
+ address: {
+ city: 'abc',
+ countryCode: '123',
+ postalCode: '456',
+ state: 'def',
+ dependentLocality: 'ghi',
+ line1: 'asdfg',
+ line2: 'dfghj',
+ sortingCode: '4567',
+ },
+ createdAt: '1234567890',
+ userRegistrationRequired: true,
+ creator: {
+ __typename: 'User',
+ firstName: 'John',
+ lastName: 'Doe',
+ },
+ members: [
+ {
+ _id: '56gheqyr7deyfuiwfewifruy8',
+ user: {
+ _id: '45ydeg2yet721rtgdu32ry',
+ },
+ },
+ ],
+ admins: [
+ {
+ _id: '45gj5678jk45678fvgbhnr4rtgh',
+ user: {
+ _id: '45ydeg2yet721rtgdu32ry',
+ },
+ },
+ ],
+ membershipRequests: [
+ {
+ _id: '56gheqyr7deyfuiwfewifruy8',
+ user: {
+ _id: '45ydeg2yet721rtgdu32ry',
+ },
+ },
+ ],
+ },
+ ],
+ },
+ },
+ ],
+ },
+ },
+ },
+ {
+ request: {
+ query: USER_JOINED_ORGANIZATIONS,
+ variables: {
+ id: '1',
+ },
+ },
+ result: {
+ data: {
+ users: [
+ {
+ user: {
+ joinedOrganizations: [
+ {
+ __typename: 'Organization',
+ _id: '6401ff65ce8e8406b8f07af2',
+ name: 'Test org',
+ image: '',
+ description: 'New Desc',
+ address: {
+ city: 'abc',
+ countryCode: '123',
+ postalCode: '456',
+ state: 'def',
+ dependentLocality: 'ghi',
+ line1: 'asdfg',
+ line2: 'dfghj',
+ sortingCode: '4567',
+ },
+ createdAt: '1234567890',
+ userRegistrationRequired: true,
+ creator: {
+ __typename: 'User',
+ firstName: 'John',
+ lastName: 'Doe',
+ },
+ members: [
+ {
+ _id: '56gheqyr7deyfuiwfewifruy8',
+ user: {
+ _id: '45ydeg2yet721rtgdu32ry',
+ },
+ },
+ ],
+ admins: [
+ {
+ _id: '45gj5678jk45678fvgbhnr4rtgh',
+ user: {
+ _id: '45ydeg2yet721rtgdu32ry',
+ },
+ },
+ ],
+ membershipRequests: [
+ {
+ _id: '56gheqyr7deyfuiwfewifruy8',
+ user: {
+ _id: '45ydeg2yet721rtgdu32ry',
+ },
+ },
+ ],
+ },
+ {
+ __typename: 'Organization',
+ _id: 'qsxhgjhbmnbkhlk,njgjfhgv',
+ name: 'Any Organization',
+ image: '',
+ description: 'New Desc',
+ address: {
+ city: 'abc',
+ countryCode: '123',
+ postalCode: '456',
+ state: 'def',
+ dependentLocality: 'ghi',
+ line1: 'asdfg',
+ line2: 'dfghj',
+ sortingCode: '4567',
+ },
+ createdAt: '1234567890',
+ userRegistrationRequired: true,
+ creator: {
+ __typename: 'User',
+ firstName: 'John',
+ lastName: 'Doe',
+ },
+ members: [
+ {
+ _id: '56gheqyr7deyfuiwfewifruy8',
+ user: {
+ _id: '45ydeg2yet721rtgdu32ry',
+ },
+ },
+ ],
+ admins: [
+ {
+ _id: '45gj5678jk45678fvgbhnr4rtgh',
+ user: {
+ _id: '45ydeg2yet721rtgdu32ry',
+ },
+ },
+ ],
+ membershipRequests: [
+ {
+ _id: '56gheqyr7deyfuiwfewifruy8',
+ user: {
+ _id: '45ydeg2yet721rtgdu32ry',
+ },
+ },
+ ],
+ },
+ ],
+ },
+ },
+ ],
+ },
+ },
+ },
+ {
+ request: {
+ query: USER_JOINED_ORGANIZATIONS,
+ variables: {
+ id: '1',
+ },
+ },
+ result: {
+ data: {
+ users: [
+ {
+ user: {
+ joinedOrganizations: [
+ {
+ __typename: 'Organization',
+ _id: '6401ff65ce8e8406b8fhgjhnm07af2',
+ name: 'Test org',
+ image: '',
+ description: 'New Desc',
+ address: {
+ city: 'abc',
+ countryCode: '123',
+ postalCode: '456',
+ state: 'def',
+ dependentLocality: 'ghi',
+ line1: 'asdfg',
+ line2: 'dfghj',
+ sortingCode: '4567',
+ },
+ createdAt: '1234567890',
+ userRegistrationRequired: true,
+ creator: {
+ __typename: 'User',
+ firstName: 'John',
+ lastName: 'Doe',
+ },
+ members: [
+ {
+ _id: '56gheqyr7deyfuiwfewifruy8',
+ user: {
+ _id: '45ydeg2yet721rtgdu32ry',
+ },
+ },
+ ],
+ admins: [
+ {
+ _id: '45gj5678jk45678fvgbhnr4rtgh',
+ user: {
+ _id: '45ydeg2yet721rtgdu32ry',
+ },
+ },
+ ],
+ membershipRequests: [
+ {
+ _id: '56gheqyr7deyfuiwfewifruy8',
+ user: {
+ _id: '45ydeg2yet721rtgdu32ry',
+ },
+ },
+ ],
+ },
+ {
+ __typename: 'Organization',
+ _id: '6401ff65ce8egfhbn8406b8f07af2',
+ name: 'Any Organization',
+ image: '',
+ description: 'New Desc',
+ address: {
+ city: 'abc',
+ countryCode: '123',
+ postalCode: '456',
+ state: 'def',
+ dependentLocality: 'ghi',
+ line1: 'asdfg',
+ line2: 'dfghj',
+ sortingCode: '4567',
+ },
+ createdAt: '1234567890',
+ userRegistrationRequired: true,
+ creator: {
+ __typename: 'User',
+ firstName: 'John',
+ lastName: 'Doe',
+ },
+ members: [
+ {
+ _id: '56gheqyr7deyfuiwfewifruy8',
+ user: {
+ _id: '45ydeg2yet721rtgdu32ry',
+ },
+ },
+ ],
+ admins: [
+ {
+ _id: '45gj5678jk45678fvgbhnr4rtgh',
+ user: {
+ _id: '45ydeg2yet721rtgdu32ry',
+ },
+ },
+ ],
+ membershipRequests: [
+ {
+ _id: '56gheqyr7deyfuiwfewifruy8',
+ user: {
+ _id: '45ydeg2yet721rtgdu32ry',
+ },
+ },
+ ],
+ },
+ ],
+ },
+ },
+ ],
+ },
+ },
+ },
+ {
+ request: {
+ query: USER_JOINED_ORGANIZATIONS,
+ variables: {
+ id: null,
+ },
+ },
+ result: {
+ data: {
+ users: [
+ {
+ user: {
+ joinedOrganizations: [
+ {
+ __typename: 'Organization',
+ _id: '6401ff65fghce8e8406b8f07af2',
+ name: 'Test org',
+ image: '',
+ description: 'New Desc',
+ address: {
+ city: 'abc',
+ countryCode: '123',
+ postalCode: '456',
+ state: 'def',
+ dependentLocality: 'ghi',
+ line1: 'asdfg',
+ line2: 'dfghj',
+ sortingCode: '4567',
+ },
+ createdAt: '1234567890',
+ userRegistrationRequired: true,
+ creator: {
+ __typename: 'User',
+ firstName: 'John',
+ lastName: 'Doe',
+ },
+ members: [
+ {
+ _id: '56gheqyr7deyfuiwfewifruy8',
+ user: {
+ _id: '45ydeg2yet721rtgdu32ry',
+ },
+ },
+ ],
+ admins: [
+ {
+ _id: '45gj5678jk45678fvgbhnr4rtgh',
+ user: {
+ _id: '45ydeg2yet721rtgdu32ry',
+ },
+ },
+ ],
+ membershipRequests: [
+ {
+ _id: '56gheqyr7deyfuiwfewifruy8',
+ user: {
+ _id: '45ydeg2yet721rtgdu32ry',
+ },
+ },
+ ],
+ },
+ {
+ __typename: 'Organization',
+ _id: '6401ff65ce8e8406b8jygjgf07af2',
+ name: 'Any Organization',
+ image: '',
+ description: 'New Desc',
+ address: {
+ city: 'abc',
+ countryCode: '123',
+ postalCode: '456',
+ state: 'def',
+ dependentLocality: 'ghi',
+ line1: 'asdfg',
+ line2: 'dfghj',
+ sortingCode: '4567',
+ },
+ createdAt: '1234567890',
+ userRegistrationRequired: true,
+ creator: {
+ __typename: 'User',
+ firstName: 'John',
+ lastName: 'Doe',
+ },
+ members: [
+ {
+ _id: '56gheqyr7deyfuiwfewifruy8',
+ user: {
+ _id: '45ydeg2yet721rtgdu32ry',
+ },
+ },
+ ],
+ admins: [
+ {
+ _id: '45gj5678jk45678fvgbhnr4rtgh',
+ user: {
+ _id: '45ydeg2yet721rtgdu32ry',
+ },
+ },
+ ],
+ membershipRequests: [
+ {
+ _id: '56gheqyr7deyfuiwfewifruy8',
+ user: {
+ _id: '45ydeg2yet721rtgdu32ry',
+ },
+ },
+ ],
+ },
+ ],
+ },
+ },
+ ],
+ },
+ },
+ },
+ {
+ request: {
+ query: USER_JOINED_ORGANIZATIONS,
+ variables: {
+ id: null,
+ },
+ },
+ result: {
+ data: {
+ users: [
+ {
+ user: {
+ joinedOrganizations: [
+ {
+ __typename: 'Organization',
+ _id: '6401ff65cehgh8e8406b8f07af2',
+ name: 'Test org',
+ image: '',
+ description: 'New Desc',
+ address: {
+ city: 'abc',
+ countryCode: '123',
+ postalCode: '456',
+ state: 'def',
+ dependentLocality: 'ghi',
+ line1: 'asdfg',
+ line2: 'dfghj',
+ sortingCode: '4567',
+ },
+ createdAt: '1234567890',
+ userRegistrationRequired: true,
+ creator: {
+ __typename: 'User',
+ firstName: 'John',
+ lastName: 'Doe',
+ },
+ members: [
+ {
+ _id: '56gheqyr7deyfuiwfewifruy8',
+ user: {
+ _id: '45ydeg2yet721rtgdu32ry',
+ },
+ },
+ ],
+ admins: [
+ {
+ _id: '45gj5678jk45678fvgbhnr4rtgh',
+ user: {
+ _id: '45ydeg2yet721rtgdu32ry',
+ },
+ },
+ ],
+ membershipRequests: [
+ {
+ _id: '56gheqyr7deyfuiwfewifruy8',
+ user: {
+ _id: '45ydeg2yet721rtgdu32ry',
+ },
+ },
+ ],
+ },
+ {
+ __typename: 'Organization',
+ _id: '6401ff65ce8e8406b8f07af2',
+ name: 'Any Organization',
+ image: '',
+ description: 'New Desc',
+ address: {
+ city: 'abc',
+ countryCode: '123',
+ postalCode: '456',
+ state: 'def',
+ dependentLocality: 'ghi',
+ line1: 'asdfg',
+ line2: 'dfghj',
+ sortingCode: '4567',
+ },
+ createdAt: '1234567890',
+ userRegistrationRequired: true,
+ creator: {
+ __typename: 'User',
+ firstName: 'John',
+ lastName: 'Doe',
+ },
+ members: [
+ {
+ _id: '56gheqyr7deyfuiwfewifruy8',
+ user: {
+ _id: '45ydeg2yet721rtgdu32ry',
+ },
+ },
+ ],
+ admins: [
+ {
+ _id: '45gj5678jk45678fvgbhnr4rtgh',
+ user: {
+ _id: '45ydeg2yet721rtgdu32ry',
+ },
+ },
+ ],
+ membershipRequests: [
+ {
+ _id: '56gheqyr7deyfuiwfewifruy8',
+ user: {
+ _id: '45ydeg2yet721rtgdu32ry',
+ },
+ },
+ ],
+ },
+ ],
+ },
+ },
+ ],
+ },
+ },
+ },
+ {
+ request: {
+ query: USER_JOINED_ORGANIZATIONS,
+ variables: {
+ id: null,
+ },
+ },
+ result: {
+ data: {
+ users: [
+ {
+ user: {
+ joinedOrganizations: [
+ {
+ __typename: 'Organization',
+ _id: '6401ff65ce8e8406nbmnmb8f07af2',
+ name: 'Test org',
+ image: '',
+ description: 'New Desc',
+ address: {
+ city: 'abc',
+ countryCode: '123',
+ postalCode: '456',
+ state: 'def',
+ dependentLocality: 'ghi',
+ line1: 'asdfg',
+ line2: 'dfghj',
+ sortingCode: '4567',
+ },
+ createdAt: '1234567890',
+ userRegistrationRequired: true,
+ creator: {
+ __typename: 'User',
+ firstName: 'John',
+ lastName: 'Doe',
+ },
+ members: [
+ {
+ _id: '56gheqyr7deyfuiwfewifruy8',
+ user: {
+ _id: '45ydeg2yet721rtgdu32ry',
+ },
+ },
+ ],
+ admins: [
+ {
+ _id: '45gj5678jk45678fvgbhnr4rtgh',
+ user: {
+ _id: '45ydeg2yet721rtgdu32ry',
+ },
+ },
+ ],
+ membershipRequests: [
+ {
+ _id: '56gheqyr7deyfuiwfewifruy8',
+ user: {
+ _id: '45ydeg2yet721rtgdu32ry',
+ },
+ },
+ ],
+ },
+ {
+ __typename: 'Organization',
+ _id: '6401ff65ce8e8406b8fnnmm07af2',
+ name: 'Any Organization',
+ image: '',
+ description: 'New Desc',
+ address: {
+ city: 'abc',
+ countryCode: '123',
+ postalCode: '456',
+ state: 'def',
+ dependentLocality: 'ghi',
+ line1: 'asdfg',
+ line2: 'dfghj',
+ sortingCode: '4567',
+ },
+ createdAt: '1234567890',
+ userRegistrationRequired: true,
+ creator: {
+ __typename: 'User',
+ firstName: 'John',
+ lastName: 'Doe',
+ },
+ members: [
+ {
+ _id: '56gheqyr7deyfuiwfewifruy8',
+ user: {
+ _id: '45ydeg2yet721rtgdu32ry',
+ },
+ },
+ ],
+ admins: [
+ {
+ _id: '45gj5678jk45678fvgbhnr4rtgh',
+ user: {
+ _id: '45ydeg2yet721rtgdu32ry',
+ },
+ },
+ ],
+ membershipRequests: [
+ {
+ _id: '56gheqyr7deyfuiwfewifruy8',
+ user: {
+ _id: '45ydeg2yet721rtgdu32ry',
+ },
+ },
+ ],
+ },
+ ],
+ },
+ },
+ ],
+ },
+ },
+ },
+];
+
+const UserConnectionListMock = [
+ {
+ request: {
+ query: USERS_CONNECTION_LIST,
+ variables: {
+ firstName_contains: '',
+ lastName_contains: '',
+ },
+ },
+ result: {
+ data: {
+ users: [
+ {
+ user: {
+ firstName: 'Deanne',
+ lastName: 'Marks',
+ image: null,
+ _id: '6589389d2caa9d8d69087487',
+ email: 'testuser8@example.com',
+ createdAt: '2023-04-13T04:53:17.742Z',
+ organizationsBlockedBy: [],
+ joinedOrganizations: [
+ {
+ _id: '6537904485008f171cf29924',
+ name: 'Unity Foundation',
+ image: null,
+ address: {
+ city: 'Queens',
+ countryCode: 'US',
+ dependentLocality: 'Some Dependent Locality',
+ line1: '123 Coffee Street',
+ line2: 'Apartment 501',
+ postalCode: '11427',
+ sortingCode: 'ABC-133',
+ state: 'NYC',
+ __typename: 'Address',
+ },
+ createdAt: '2023-04-13T05:16:52.827Z',
+ creator: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: null,
+ email: 'testsuperadmin@example.com',
+ createdAt: '2023-04-13T04:53:17.742Z',
+ __typename: 'User',
+ },
+ __typename: 'Organization',
+ },
+ {
+ _id: '6637904485008f171cf29924',
+ name: 'Unity Foundation',
+ image: null,
+ address: {
+ city: 'Staten Island',
+ countryCode: 'US',
+ dependentLocality: 'Some Dependent Locality',
+ line1: '123 church Street',
+ line2: 'Apartment 499',
+ postalCode: '10301',
+ sortingCode: 'ABC-122',
+ state: 'NYC',
+ __typename: 'Address',
+ },
+ createdAt: '2023-04-13T05:16:52.827Z',
+ creator: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: null,
+ email: 'testsuperadmin@example.com',
+ createdAt: '2023-04-13T04:53:17.742Z',
+ __typename: 'User',
+ },
+ __typename: 'Organization',
+ },
+ {
+ _id: '6737904485008f171cf29924',
+ name: 'Unity Foundation',
+ image: null,
+ address: {
+ city: 'Brooklyn',
+ countryCode: 'US',
+ dependentLocality: 'Sample Dependent Locality',
+ line1: '123 Main Street',
+ line2: 'Apt 456',
+ postalCode: '10004',
+ sortingCode: 'ABC-789',
+ state: 'NY',
+ __typename: 'Address',
+ },
+ createdAt: '2023-04-13T05:16:52.827Z',
+ creator: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: null,
+ email: 'testsuperadmin@example.com',
+ createdAt: '2023-04-13T04:53:17.742Z',
+ __typename: 'User',
+ },
+ __typename: 'Organization',
+ },
+ {
+ _id: '6437904485008f171cf29924',
+ name: 'Unity Foundation',
+ image: null,
+ address: {
+ city: 'Bronx',
+ countryCode: 'US',
+ dependentLocality: 'Some Dependent Locality',
+ line1: '123 Random Street',
+ line2: 'Apartment 456',
+ postalCode: '10451',
+ sortingCode: 'ABC-123',
+ state: 'NYC',
+ __typename: 'Address',
+ },
+ createdAt: '2023-04-13T05:16:52.827Z',
+ creator: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: null,
+ email: 'testsuperadmin@example.com',
+ createdAt: '2023-04-13T04:53:17.742Z',
+ __typename: 'User',
+ },
+ __typename: 'Organization',
+ },
+ ],
+ __typename: 'User',
+ },
+ appUserProfile: {
+ _id: '64378abd85308f171cf2993d',
+ adminFor: [],
+ isSuperAdmin: false,
+ createdOrganizations: [],
+ createdEvents: [],
+ eventAdmin: [],
+ __typename: 'AppUserProfile',
+ },
+ __typename: 'UserData',
+ },
+ ],
+ },
+ },
+ },
+ {
+ request: {
+ query: USERS_CONNECTION_LIST,
+ variables: {
+ firstName_contains: '',
+ lastName_contains: '',
+ },
+ },
+ result: {
+ data: {
+ users: {
+ user: [
+ {
+ firstName: 'Disha',
+ lastName: 'Talreja',
+ image: 'img',
+ _id: '1',
+ email: 'disha@email.com',
+ createdAt: '',
+ appUserProfile: {
+ _id: '12',
+ isSuperAdmin: 'false',
+ createdOrganizations: {
+ _id: '345678',
+ },
+ createdEvents: {
+ _id: '34567890',
+ },
+ },
+ organizationsBlockedBy: [],
+ joinedOrganizations: [],
+ },
+ {
+ firstName: 'Disha',
+ lastName: 'Talreja',
+ image: 'img',
+ _id: '1',
+ email: 'disha@email.com',
+ createdAt: '',
+ appUserProfile: {
+ _id: '12',
+ isSuperAdmin: 'false',
+ createdOrganizations: {
+ _id: '345678',
+ },
+ createdEvents: {
+ _id: '34567890',
+ },
+ },
+ organizationsBlockedBy: [],
+ joinedOrganizations: [],
+ },
+ {
+ firstName: 'Disha',
+ lastName: 'Talreja',
+ image: 'img',
+ _id: '1',
+ email: 'disha@email.com',
+ createdAt: '',
+ appUserProfile: {
+ _id: '12',
+ isSuperAdmin: 'false',
+ createdOrganizations: {
+ _id: '345678',
+ },
+ createdEvents: {
+ _id: '34567890',
+ },
+ },
+ organizationsBlockedBy: [],
+ joinedOrganizations: [],
+ },
+ ],
+ },
+ },
+ },
+ },
+ {
+ request: {
+ query: USERS_CONNECTION_LIST,
+ variables: {
+ firstName_contains: 'Disha',
+ lastName_contains: '',
+ },
+ },
+ result: {
+ data: {
+ users: [
+ {
+ user: {
+ firstName: 'Deanne',
+ lastName: 'Marks',
+ image: null,
+ _id: '6589389d2caa9d8d69087487',
+ email: 'testuser8@example.com',
+ createdAt: '2023-04-13T04:53:17.742Z',
+ organizationsBlockedBy: [],
+ joinedOrganizations: [
+ {
+ _id: '6537904485008f171cf29924',
+ name: 'Unity Foundation',
+ image: null,
+ address: {
+ city: 'Queens',
+ countryCode: 'US',
+ dependentLocality: 'Some Dependent Locality',
+ line1: '123 Coffee Street',
+ line2: 'Apartment 501',
+ postalCode: '11427',
+ sortingCode: 'ABC-133',
+ state: 'NYC',
+ __typename: 'Address',
+ },
+ createdAt: '2023-04-13T05:16:52.827Z',
+ creator: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: null,
+ email: 'testsuperadmin@example.com',
+ createdAt: '2023-04-13T04:53:17.742Z',
+ __typename: 'User',
+ },
+ __typename: 'Organization',
+ },
+ {
+ _id: '6637904485008f171cf29924',
+ name: 'Unity Foundation',
+ image: null,
+ address: {
+ city: 'Staten Island',
+ countryCode: 'US',
+ dependentLocality: 'Some Dependent Locality',
+ line1: '123 church Street',
+ line2: 'Apartment 499',
+ postalCode: '10301',
+ sortingCode: 'ABC-122',
+ state: 'NYC',
+ __typename: 'Address',
+ },
+ createdAt: '2023-04-13T05:16:52.827Z',
+ creator: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: null,
+ email: 'testsuperadmin@example.com',
+ createdAt: '2023-04-13T04:53:17.742Z',
+ __typename: 'User',
+ },
+ __typename: 'Organization',
+ },
+ {
+ _id: '6737904485008f171cf29924',
+ name: 'Unity Foundation',
+ image: null,
+ address: {
+ city: 'Brooklyn',
+ countryCode: 'US',
+ dependentLocality: 'Sample Dependent Locality',
+ line1: '123 Main Street',
+ line2: 'Apt 456',
+ postalCode: '10004',
+ sortingCode: 'ABC-789',
+ state: 'NY',
+ __typename: 'Address',
+ },
+ createdAt: '2023-04-13T05:16:52.827Z',
+ creator: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: null,
+ email: 'testsuperadmin@example.com',
+ createdAt: '2023-04-13T04:53:17.742Z',
+ __typename: 'User',
+ },
+ __typename: 'Organization',
+ },
+ {
+ _id: '6437904485008f171cf29924',
+ name: 'Unity Foundation',
+ image: null,
+ address: {
+ city: 'Bronx',
+ countryCode: 'US',
+ dependentLocality: 'Some Dependent Locality',
+ line1: '123 Random Street',
+ line2: 'Apartment 456',
+ postalCode: '10451',
+ sortingCode: 'ABC-123',
+ state: 'NYC',
+ __typename: 'Address',
+ },
+ createdAt: '2023-04-13T05:16:52.827Z',
+ creator: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: null,
+ email: 'testsuperadmin@example.com',
+ createdAt: '2023-04-13T04:53:17.742Z',
+ __typename: 'User',
+ },
+ __typename: 'Organization',
+ },
+ ],
+ __typename: 'User',
+ },
+ appUserProfile: {
+ _id: '64378abd85308f171cf2993d',
+ adminFor: [],
+ isSuperAdmin: false,
+ createdOrganizations: [],
+ createdEvents: [],
+ eventAdmin: [],
+ __typename: 'AppUserProfile',
+ },
+ __typename: 'UserData',
+ },
+ ],
+ },
+ },
+ },
+];
+
+const MESSAGE_SENT_TO_CHAT_MOCK = [
+ {
+ request: {
+ query: MESSAGE_SENT_TO_CHAT,
+ variables: {
+ userId: null,
+ },
+ },
+ result: {
+ data: {
+ messageSentToChat: {
+ _id: '668ec1f1364e03ac47a151',
+ createdAt: '2024-07-10T17:16:33.248Z',
+ messageContent: 'Test ',
+ type: 'STRING',
+ replyTo: null,
+ sender: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: '',
+ },
+ updatedAt: '2024-07-10',
+ },
+ },
+ },
+ },
+ {
+ request: {
+ query: MESSAGE_SENT_TO_CHAT,
+ variables: {
+ userId: '2',
+ },
+ },
+ result: {
+ data: {
+ messageSentToGroupChat: {
+ _id: '668ec1f1df364e03ac47a151',
+ createdAt: '2024-07-10T17:16:33.248Z',
+ messageContent: 'Test ',
+ replyTo: null,
+ type: 'STRING',
+ sender: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: '',
+ },
+ updatedAt: '2024-07-10',
+ },
+ },
+ },
+ },
+ {
+ request: {
+ query: MESSAGE_SENT_TO_CHAT,
+ variables: {
+ userId: '1',
+ },
+ },
+ result: {
+ data: {
+ messageSentToGroupChat: {
+ _id: '668ec1f13603ac4697a151',
+ createdAt: '2024-07-10T17:16:33.248Z',
+ messageContent: 'Test ',
+ replyTo: null,
+ type: 'STRING',
+ sender: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: '',
+ },
+ updatedAt: '2024-07-10',
+ },
+ },
+ },
+ },
+];
+
+const CHAT_BY_ID_QUERY_MOCK = [
+ {
+ request: {
+ query: CHAT_BY_ID,
+ variables: {
+ id: '1',
+ },
+ },
+ result: {
+ data: {
+ chatById: {
+ _id: '1',
+ createdAt: '2345678903456',
+ isGroup: false,
+ creator: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: null,
+ email: 'testsuperadmin@example.com',
+ createdAt: '2023-04-13T04:53:17.742Z',
+ __typename: 'User',
+ },
+ organization: null,
+ name: '',
+ messages: [
+ {
+ _id: '345678',
+ createdAt: '345678908765',
+ messageContent: 'Hello',
+ replyTo: null,
+ type: 'STRING',
+ sender: {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ },
+ ],
+ users: [
+ {
+ _id: '1',
+ firstName: 'Disha',
+ lastName: 'Talreja',
+ email: 'disha@example.com',
+ image: '',
+ },
+ {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ ],
+ },
+ },
+ },
+ },
+ {
+ request: {
+ query: CHAT_BY_ID,
+ variables: {
+ id: '1',
+ },
+ },
+ result: {
+ data: {
+ chatById: {
+ _id: '1',
+ isGroup: false,
+ creator: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: null,
+ email: 'testsuperadmin@example.com',
+ createdAt: '2023-04-13T04:53:17.742Z',
+ __typename: 'User',
+ },
+ organization: null,
+ name: '',
+ createdAt: '2345678903456',
+ messages: [
+ {
+ _id: '345678',
+ createdAt: '345678908765',
+ messageContent: 'Hello',
+ replyTo: null,
+ type: 'STRING',
+ sender: {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ },
+ ],
+ users: [
+ {
+ _id: '1',
+ firstName: 'Disha',
+ lastName: 'Talreja',
+ email: 'disha@example.com',
+ image: '',
+ },
+ {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ ],
+ },
+ },
+ },
+ },
+ {
+ request: {
+ query: CHAT_BY_ID,
+ variables: {
+ id: '',
+ },
+ },
+ result: {
+ data: {
+ chatById: {
+ _id: '1',
+ isGroup: false,
+ creator: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: null,
+ email: 'testsuperadmin@example.com',
+ createdAt: '2023-04-13T04:53:17.742Z',
+ __typename: 'User',
+ },
+ organization: null,
+ name: '',
+ createdAt: '2345678903456',
+ messages: [
+ {
+ _id: '345678',
+ createdAt: '345678908765',
+ messageContent: 'Hello',
+ replyTo: null,
+ type: 'STRING',
+ sender: {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ },
+ ],
+ users: [
+ {
+ _id: '1',
+ firstName: 'Disha',
+ lastName: 'Talreja',
+ email: 'disha@example.com',
+ image: '',
+ },
+ {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ ],
+ },
+ },
+ },
+ },
+];
+
+const CHATS_LIST_MOCK = [
+ {
+ request: {
+ query: CHATS_LIST,
+ variables: {
+ id: null,
+ },
+ },
+ result: {
+ data: {
+ chatsByUserId: [
+ {
+ _id: '65844efc814dd40fgh03db811c4',
+ isGroup: true,
+ creator: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: null,
+ email: 'testsuperadmin@example.com',
+ createdAt: '2023-04-13T04:53:17.742Z',
+ __typename: 'User',
+ },
+ organization: {
+ _id: 'pw3ertyuiophgfre45678',
+ name: 'rtyu',
+ },
+ createdAt: '2345678903456',
+ name: 'Test Group Chat',
+ messages: [
+ {
+ _id: '345678',
+ createdAt: '345678908765',
+ messageContent: 'Hello',
+ replyTo: null,
+ type: 'STRING',
+ sender: {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ },
+ ],
+ users: [
+ {
+ _id: '1',
+ firstName: 'Disha',
+ lastName: 'Talreja',
+ email: 'disha@example.com',
+ image: '',
+ },
+ {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ {
+ _id: '3',
+ firstName: 'Test',
+ lastName: 'User1',
+ email: 'test1@example.com',
+ image: '',
+ },
+ {
+ _id: '4',
+ firstName: 'Test',
+ lastName: 'User2',
+ email: 'test2@example.com',
+ image: '',
+ },
+ {
+ _id: '5',
+ firstName: 'Test',
+ lastName: 'User4',
+ email: 'test4@example.com',
+ image: '',
+ },
+ ],
+ },
+ {
+ _id: '65844efc814ddgh4003db811c4',
+ isGroup: true,
+ creator: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: null,
+ email: 'testsuperadmin@example.com',
+ createdAt: '2023-04-13T04:53:17.742Z',
+ __typename: 'User',
+ },
+ organization: {
+ _id: 'pw3ertyuiophgfre45678',
+ name: 'rtyu',
+ },
+ createdAt: '2345678903456',
+ name: 'Test Group Chat',
+ messages: [
+ {
+ _id: '345678',
+ createdAt: '345678908765',
+ messageContent: 'Hello',
+ replyTo: null,
+ type: 'STRING',
+ sender: {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ },
+ ],
+ users: [
+ {
+ _id: '1',
+ firstName: 'Disha',
+ lastName: 'Talreja',
+ email: 'disha@example.com',
+ image: '',
+ },
+ {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ {
+ _id: '3',
+ firstName: 'Test',
+ lastName: 'User1',
+ email: 'test1@example.com',
+ image: '',
+ },
+ {
+ _id: '4',
+ firstName: 'Test',
+ lastName: 'User2',
+ email: 'test2@example.com',
+ image: '',
+ },
+ {
+ _id: '5',
+ firstName: 'Test',
+ lastName: 'User4',
+ email: 'test4@example.com',
+ image: '',
+ },
+ ],
+ },
+ ],
+ },
+ },
+ },
+ {
+ request: {
+ query: CHATS_LIST,
+ variables: {
+ id: '',
+ },
+ },
+ result: {
+ data: {
+ chatsByUserId: [
+ {
+ _id: '65844ghjefc814dd4003db811c4',
+ isGroup: true,
+ creator: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: null,
+ email: 'testsuperadmin@example.com',
+ createdAt: '2023-04-13T04:53:17.742Z',
+ __typename: 'User',
+ },
+ organization: {
+ _id: 'pw3ertyuiophgfre45678',
+ name: 'rtyu',
+ },
+ createdAt: '2345678903456',
+ name: 'Test Group Chat',
+ messages: [
+ {
+ _id: '345678',
+ createdAt: '345678908765',
+ messageContent: 'Hello',
+ replyTo: null,
+ type: 'STRING',
+ sender: {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ },
+ ],
+ users: [
+ {
+ _id: '1',
+ firstName: 'Disha',
+ lastName: 'Talreja',
+ email: 'disha@example.com',
+ image: '',
+ },
+ {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ {
+ _id: '3',
+ firstName: 'Test',
+ lastName: 'User1',
+ email: 'test1@example.com',
+ image: '',
+ },
+ {
+ _id: '4',
+ firstName: 'Test',
+ lastName: 'User2',
+ email: 'test2@example.com',
+ image: '',
+ },
+ {
+ _id: '5',
+ firstName: 'Test',
+ lastName: 'User4',
+ email: 'test4@example.com',
+ image: '',
+ },
+ ],
+ },
+ {
+ _id: 'ujhgtrdtyuiop',
+ isGroup: true,
+ creator: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: null,
+ email: 'testsuperadmin@example.com',
+ createdAt: '2023-04-13T04:53:17.742Z',
+ __typename: 'User',
+ },
+ organization: {
+ _id: 'pw3ertyuiophgfre45678',
+ name: 'rtyu',
+ },
+ createdAt: '2345678903456',
+ name: 'Test Group Chat',
+ messages: [
+ {
+ _id: '345678',
+ createdAt: '345678908765',
+ messageContent: 'Hello',
+ replyTo: null,
+ type: 'STRING',
+ sender: {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ },
+ ],
+ users: [
+ {
+ _id: '1',
+ firstName: 'Disha',
+ lastName: 'Talreja',
+ email: 'disha@example.com',
+ image: '',
+ },
+ {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ {
+ _id: '3',
+ firstName: 'Test',
+ lastName: 'User1',
+ email: 'test1@example.com',
+ image: '',
+ },
+ {
+ _id: '4',
+ firstName: 'Test',
+ lastName: 'User2',
+ email: 'test2@example.com',
+ image: '',
+ },
+ {
+ _id: '5',
+ firstName: 'Test',
+ lastName: 'User4',
+ email: 'test4@example.com',
+ image: '',
+ },
+ ],
+ },
+ ],
+ },
+ },
+ },
+ {
+ request: {
+ query: CHATS_LIST,
+ variables: {
+ id: '1',
+ },
+ },
+ result: {
+ data: {
+ chatsByUserId: [
+ {
+ _id: '65844efc814dhjmkdftyd4003db811c4',
+ isGroup: true,
+ creator: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: null,
+ email: 'testsuperadmin@example.com',
+ createdAt: '2023-04-13T04:53:17.742Z',
+ __typename: 'User',
+ },
+ organization: {
+ _id: 'pw3ertyuiophgfre45678',
+ name: 'rtyu',
+ },
+ createdAt: '2345678903456',
+ name: 'Test Group Chat',
+ messages: [
+ {
+ _id: '345678',
+ createdAt: '345678908765',
+ messageContent: 'Hello',
+ replyTo: null,
+ type: 'STRING',
+ sender: {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ },
+ ],
+ users: [
+ {
+ _id: '1',
+ firstName: 'Disha',
+ lastName: 'Talreja',
+ email: 'disha@example.com',
+ image: '',
+ },
+ {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ {
+ _id: '3',
+ firstName: 'Test',
+ lastName: 'User1',
+ email: 'test1@example.com',
+ image: '',
+ },
+ {
+ _id: '4',
+ firstName: 'Test',
+ lastName: 'User2',
+ email: 'test2@example.com',
+ image: '',
+ },
+ {
+ _id: '5',
+ firstName: 'Test',
+ lastName: 'User4',
+ email: 'test4@example.com',
+ image: '',
+ },
+ ],
+ },
+ {
+ _id: '65844ewsedrffc814dd4003db811c4',
+ isGroup: true,
+ creator: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: null,
+ email: 'testsuperadmin@example.com',
+ createdAt: '2023-04-13T04:53:17.742Z',
+ __typename: 'User',
+ },
+ organization: {
+ _id: 'pw3ertyuiophgfre45678',
+ name: 'rtyu',
+ },
+ createdAt: '2345678903456',
+ name: 'Test Group Chat',
+ messages: [
+ {
+ _id: '345678',
+ createdAt: '345678908765',
+ messageContent: 'Hello',
+ replyTo: null,
+ type: 'STRING',
+ sender: {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ },
+ ],
+ users: [
+ {
+ _id: '1',
+ firstName: 'Disha',
+ lastName: 'Talreja',
+ email: 'disha@example.com',
+ image: '',
+ },
+ {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ {
+ _id: '3',
+ firstName: 'Test',
+ lastName: 'User1',
+ email: 'test1@example.com',
+ image: '',
+ },
+ {
+ _id: '4',
+ firstName: 'Test',
+ lastName: 'User2',
+ email: 'test2@example.com',
+ image: '',
+ },
+ {
+ _id: '5',
+ firstName: 'Test',
+ lastName: 'User4',
+ email: 'test4@example.com',
+ image: '',
+ },
+ ],
+ },
+ ],
+ },
+ },
+ },
+];
+
+const GROUP_CHAT_BY_ID_QUERY_MOCK = [
+ {
+ request: {
+ query: CHAT_BY_ID,
+ variables: {
+ id: '',
+ },
+ },
+ result: {
+ data: {
+ chatById: {
+ _id: '65844efc814dd4003db811c4',
+ isGroup: true,
+ creator: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: null,
+ email: 'testsuperadmin@example.com',
+ createdAt: '2023-04-13T04:53:17.742Z',
+ __typename: 'User',
+ },
+ organization: {
+ _id: 'pw3ertyuiophgfre45678',
+ name: 'rtyu',
+ },
+ createdAt: '2345678903456',
+ name: 'Test Group Chat',
+ messages: [
+ {
+ _id: '345678',
+ createdAt: '345678908765',
+ messageContent: 'Hello',
+ replyTo: null,
+ type: 'STRING',
+ sender: {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ },
+ ],
+ users: [
+ {
+ _id: '1',
+ firstName: 'Disha',
+ lastName: 'Talreja',
+ email: 'disha@example.com',
+ image: '',
+ },
+ {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ {
+ _id: '3',
+ firstName: 'Test',
+ lastName: 'User1',
+ email: 'test1@example.com',
+ image: '',
+ },
+ {
+ _id: '4',
+ firstName: 'Test',
+ lastName: 'User2',
+ email: 'test2@example.com',
+ image: '',
+ },
+ {
+ _id: '5',
+ firstName: 'Test',
+ lastName: 'User4',
+ email: 'test4@example.com',
+ image: '',
+ },
+ ],
+ },
+ },
+ },
+ },
+];
+
+const CREATE_CHAT_MUTATION = [
+ {
+ request: {
+ query: CREATE_CHAT,
+ variables: {
+ organizationId: '6401ff65ce8e8406b8jygjgf07af2',
+ userIds: [null],
+ name: 'Test Group',
+ isGroup: true,
+ },
+ },
+ result: {
+ data: {
+ createChat: {
+ _id: '65844efc814dd4003db811c4',
+ isGroup: true,
+ creator: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: null,
+ email: 'testsuperadmin@example.com',
+ createdAt: '2023-04-13T04:53:17.742Z',
+ __typename: 'User',
+ },
+ organization: {
+ _id: 'pw3ertyuiophgfre45678',
+ name: 'rtyu',
+ },
+ createdAt: '2345678903456',
+ name: 'Test Group Chat',
+ messages: [
+ {
+ _id: '345678',
+ createdAt: '345678908765',
+ messageContent: 'Hello',
+ replyTo: null,
+ type: 'STRING',
+ sender: {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ },
+ ],
+ users: [
+ {
+ _id: '1',
+ firstName: 'Disha',
+ lastName: 'Talreja',
+ email: 'disha@example.com',
+ image: '',
+ },
+ {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ {
+ _id: '3',
+ firstName: 'Test',
+ lastName: 'User1',
+ email: 'test1@example.com',
+ image: '',
+ },
+ {
+ _id: '4',
+ firstName: 'Test',
+ lastName: 'User2',
+ email: 'test2@example.com',
+ image: '',
+ },
+ {
+ _id: '5',
+ firstName: 'Test',
+ lastName: 'User4',
+ email: 'test4@example.com',
+ image: '',
+ },
+ ],
+ },
+ },
+ },
+ },
+ {
+ request: {
+ query: CREATE_CHAT,
+ variables: {
+ organizationId: '',
+ userIds: [null],
+ name: 'Test Group',
+ isGroup: true,
+ },
+ },
+ result: {
+ data: {
+ createChat: {
+ _id: '65844efc814dd4003db811c4',
+ isGroup: true,
+ creator: {
+ _id: '64378abd85008f171cf2990d',
+ firstName: 'Wilt',
+ lastName: 'Shepherd',
+ image: null,
+ email: 'testsuperadmin@example.com',
+ createdAt: '2023-04-13T04:53:17.742Z',
+ __typename: 'User',
+ },
+ organization: {
+ _id: 'pw3ertyuiophgfre45678',
+ name: 'rtyu',
+ },
+ createdAt: '2345678903456',
+ name: 'Test Group Chat',
+ messages: [
+ {
+ _id: '345678',
+ createdAt: '345678908765',
+ messageContent: 'Hello',
+ replyTo: null,
+ type: 'STRING',
+ sender: {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ },
+ ],
+ users: [
+ {
+ _id: '1',
+ firstName: 'Disha',
+ lastName: 'Talreja',
+ email: 'disha@example.com',
+ image: '',
+ },
+ {
+ _id: '2',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'test@example.com',
+ image: '',
+ },
+ {
+ _id: '3',
+ firstName: 'Test',
+ lastName: 'User1',
+ email: 'test1@example.com',
+ image: '',
+ },
+ {
+ _id: '4',
+ firstName: 'Test',
+ lastName: 'User2',
+ email: 'test2@example.com',
+ image: '',
+ },
+ {
+ _id: '5',
+ firstName: 'Test',
+ lastName: 'User4',
+ email: 'test4@example.com',
+ image: '',
+ },
+ ],
+ },
+ },
+ },
+ },
+];
+
+async function wait(ms = 100): Promise {
+ await act(() => {
+ return new Promise((resolve) => {
+ setTimeout(resolve, ms);
+ });
+ });
+}
+
+describe('Testing Create Group Chat Modal [User Portal]', () => {
+ window.HTMLElement.prototype.scrollIntoView = jest.fn();
+
+ Object.defineProperty(window, 'matchMedia', {
+ writable: true,
+ value: jest.fn().mockImplementation((query) => ({
+ matches: false,
+ media: query,
+ onchange: null,
+ addListener: jest.fn(), // Deprecated
+ removeListener: jest.fn(), // Deprecated
+ addEventListener: jest.fn(),
+ removeEventListener: jest.fn(),
+ dispatchEvent: jest.fn(),
+ })),
+ });
+
+ test('open and close create new direct chat modal', async () => {
+ const mock = [
+ ...USER_JOINED_ORG_MOCK,
+ ...GROUP_CHAT_BY_ID_QUERY_MOCK,
+ ...MESSAGE_SENT_TO_CHAT_MOCK,
+ ...CHAT_BY_ID_QUERY_MOCK,
+ ...CHATS_LIST_MOCK,
+ ...UserConnectionListMock,
+ ...CREATE_CHAT_MUTATION,
+ ...CHATS_LIST_MOCK,
+ ];
+ render(
+
+
+
+
+
+
+
+
+ ,
+ );
+
+ await wait();
+
+ const dropdown = await screen.findByTestId('dropdown');
+ expect(dropdown).toBeInTheDocument();
+ fireEvent.click(dropdown);
+ const newGroupChatBtn = await screen.findByTestId('newGroupChat');
+ expect(newGroupChatBtn).toBeInTheDocument();
+ fireEvent.click(newGroupChatBtn);
+
+ const closeButton = screen.getByRole('button', { name: /close/i });
+ expect(closeButton).toBeInTheDocument();
+
+ fireEvent.click(closeButton);
+ });
+
+ test('create new group chat', async () => {
+ const mock = [
+ ...USER_JOINED_ORG_MOCK,
+ ...GROUP_CHAT_BY_ID_QUERY_MOCK,
+ ...MESSAGE_SENT_TO_CHAT_MOCK,
+ ...CHAT_BY_ID_QUERY_MOCK,
+ ...CHATS_LIST_MOCK,
+ ...UserConnectionListMock,
+ ...CREATE_CHAT_MUTATION,
+ ...CHATS_LIST_MOCK,
+ ];
+ render(
+
+
+
+
+
+
+
+
+ ,
+ );
+
+ await wait();
+
+ const dropdown = await screen.findByTestId('dropdown');
+ expect(dropdown).toBeInTheDocument();
+ fireEvent.click(dropdown);
+
+ const newGroupChatBtn = await screen.findByTestId('newGroupChat');
+ expect(newGroupChatBtn).toBeInTheDocument();
+
+ fireEvent.click(newGroupChatBtn);
+
+ await waitFor(async () => {
+ expect(
+ await screen.findByTestId('createGroupChatModal'),
+ ).toBeInTheDocument();
+ });
+
+ const groupTitleInput = screen.getByLabelText(
+ 'Group name',
+ ) as HTMLInputElement;
+
+ expect(groupTitleInput).toBeInTheDocument();
+
+ fireEvent.change(groupTitleInput, { target: { value: 'Test Group' } });
+ await waitFor(() => {
+ expect(groupTitleInput.value).toBe('Test Group');
+ });
+
+ const selectLabel = /select organization/i;
+ const orgSelect = await screen.findByLabelText('Select Organization');
+ // console.log(prettyDOM(document));
+
+ // act(() => {
+ // fireEvent.change(orgSelect, {
+ // target: { value: '6401ff65ce8e8406b8f07af2' },
+ // });
+ // })
+ // fireEvent.change(orgSelect, {
+ // target: { value: '6401ff65ce8e8406b8f07af2' },
+ // });
+
+ // act(() => {
+ userEvent.click(orgSelect);
+
+ const optionsPopupEl = await screen.findByRole('listbox', {
+ name: selectLabel,
+ });
+
+ userEvent.click(within(optionsPopupEl).getByText(/any organization/i));
+ // });
+
+ // await waitFor(async () => {
+ // const option = await screen.findAllByText('Any Organization');
+
+ // console.log("option", option);
+ // });
+
+ const nextBtn = await screen.findByTestId('nextBtn');
+
+ act(() => {
+ fireEvent.click(nextBtn);
+ });
+
+ const createBtn = await screen.findByTestId('createBtn');
+ await waitFor(async () => {
+ expect(createBtn).toBeInTheDocument();
+ });
+
+ await act(async () => {
+ fireEvent.click(await screen.findByTestId('createBtn'));
+ });
+
+ // await waitFor(() => {
+ // expect(createBtn).not.toBeInTheDocument();
+ // });
+ }, 3000);
+
+ test('add and remove user', async () => {
+ setItem('userId', '1');
+ const mock = [
+ ...USER_JOINED_ORG_MOCK,
+ ...GROUP_CHAT_BY_ID_QUERY_MOCK,
+ ...MESSAGE_SENT_TO_CHAT_MOCK,
+ ...CHAT_BY_ID_QUERY_MOCK,
+ ...CHATS_LIST_MOCK,
+ ...UserConnectionListMock,
+ ...CREATE_CHAT_MUTATION,
+ ...CHATS_LIST_MOCK,
+ ];
+ render(
+
+
+
+
+
+
+
+
+ ,
+ );
+
+ await wait();
+
+ const dropdown = await screen.findByTestId('dropdown');
+ expect(dropdown).toBeInTheDocument();
+ fireEvent.click(dropdown);
+ const newGroupChatBtn = await screen.findByTestId('newGroupChat');
+ expect(newGroupChatBtn).toBeInTheDocument();
+ fireEvent.click(newGroupChatBtn);
+
+ await waitFor(async () => {
+ expect(
+ await screen.findByTestId('createGroupChatModal'),
+ ).toBeInTheDocument();
+ });
+
+ const nextBtn = await screen.findByTestId('nextBtn');
+
+ act(() => {
+ fireEvent.click(nextBtn);
+ });
+
+ await waitFor(async () => {
+ const addBtn = await screen.findAllByTestId('addBtn');
+ expect(addBtn[0]).toBeInTheDocument();
+ });
+
+ const addBtn = await screen.findAllByTestId('addBtn');
+
+ fireEvent.click(addBtn[0]);
+
+ const removeBtn = await screen.findAllByText('Remove');
+ await waitFor(async () => {
+ expect(removeBtn[0]).toBeInTheDocument();
+ });
+ fireEvent.click(removeBtn[0]);
+
+ await waitFor(() => {
+ expect(addBtn[0]).toBeInTheDocument();
+ });
+
+ const submitBtn = await screen.findByTestId('submitBtn');
+
+ expect(submitBtn).toBeInTheDocument();
+
+ const searchInput = (await screen.findByTestId(
+ 'searchUser',
+ )) as HTMLInputElement;
+ expect(searchInput).toBeInTheDocument();
+
+ fireEvent.change(searchInput, { target: { value: 'Disha' } });
+
+ expect(searchInput.value).toBe('Disha');
+
+ fireEvent.click(submitBtn);
+
+ const closeButton = screen.getAllByRole('button', { name: /close/i });
+ expect(closeButton[0]).toBeInTheDocument();
+
+ fireEvent.click(closeButton[0]);
+
+ await wait(500);
+ });
+});
diff --git a/src/components/UserPortal/CreateGroupChat/CreateGroupChat.tsx b/src/components/UserPortal/CreateGroupChat/CreateGroupChat.tsx
new file mode 100644
index 0000000000..099a42310a
--- /dev/null
+++ b/src/components/UserPortal/CreateGroupChat/CreateGroupChat.tsx
@@ -0,0 +1,394 @@
+import {
+ FormControl,
+ InputLabel,
+ MenuItem,
+ Paper,
+ Select,
+ TableBody,
+} from '@mui/material';
+import type { SelectChangeEvent } from '@mui/material/Select';
+import React, { useEffect, useState } from 'react';
+import { Button, Form, Modal } from 'react-bootstrap';
+import styles from './CreateGroupChat.module.css';
+import type { ApolloQueryResult } from '@apollo/client';
+import { useMutation, useQuery } from '@apollo/client';
+import { USER_JOINED_ORGANIZATIONS } from 'GraphQl/Queries/OrganizationQueries';
+import useLocalStorage from 'utils/useLocalstorage';
+import { CREATE_CHAT } from 'GraphQl/Mutations/OrganizationMutations';
+import Table from '@mui/material/Table';
+import TableCell, { tableCellClasses } from '@mui/material/TableCell';
+import TableContainer from '@mui/material/TableContainer';
+import TableHead from '@mui/material/TableHead';
+import TableRow from '@mui/material/TableRow';
+import { styled } from '@mui/material/styles';
+import type { InterfaceQueryUserListItem } from 'utils/interfaces';
+import { USERS_CONNECTION_LIST } from 'GraphQl/Queries/Queries';
+import Loader from 'components/Loader/Loader';
+import { Search } from '@mui/icons-material';
+import { useTranslation } from 'react-i18next';
+
+interface InterfaceCreateGroupChatProps {
+ toggleCreateGroupChatModal: () => void;
+ createGroupChatModalisOpen: boolean;
+ chatsListRefetch: (
+ variables?:
+ | Partial<{
+ id: string;
+ }>
+ | undefined,
+ ) => Promise>;
+}
+
+interface InterfaceOrganization {
+ _id: string;
+ name: string;
+ image: string;
+ description: string;
+ admins: [];
+ members: [];
+ address: {
+ city: string;
+ countryCode: string;
+ line1: string;
+ postalCode: string;
+ state: string;
+ };
+ membershipRequestStatus: string;
+ userRegistrationRequired: boolean;
+ membershipRequests: {
+ _id: string;
+ user: {
+ _id: string;
+ };
+ }[];
+}
+
+/**
+ * Styled table cell with custom styles.
+ */
+
+const StyledTableCell = styled(TableCell)(({ theme }) => ({
+ [`&.${tableCellClasses.head}`]: {
+ backgroundColor: ['#31bb6b', '!important'],
+ color: theme.palette.common.white,
+ },
+ [`&.${tableCellClasses.body}`]: {
+ fontSize: 14,
+ },
+}));
+
+/**
+ * Styled table row with custom styles.
+ */
+
+const StyledTableRow = styled(TableRow)(() => ({
+ '&:last-child td, &:last-child th': {
+ border: 0,
+ },
+}));
+
+const { getItem } = useLocalStorage();
+
+export default function CreateGroupChat({
+ toggleCreateGroupChatModal,
+ createGroupChatModalisOpen,
+ chatsListRefetch,
+}: InterfaceCreateGroupChatProps): JSX.Element {
+ const { t } = useTranslation('translation', {
+ keyPrefix: 'userChat',
+ });
+
+ const userId: string | null = getItem('userId');
+
+ const [createChat] = useMutation(CREATE_CHAT);
+
+ const [organizations, setOrganizations] = useState([]);
+ const [selectedOrganization, setSelectedOrganization] = useState('');
+ const [title, setTitle] = useState('');
+ const [userIds, setUserIds] = useState([]);
+
+ const [addUserModalisOpen, setAddUserModalisOpen] = useState(false);
+
+ function openAddUserModal(): void {
+ setAddUserModalisOpen(true);
+ }
+
+ const toggleAddUserModal = /* istanbul ignore next */ (): void =>
+ setAddUserModalisOpen(!addUserModalisOpen);
+
+ const handleChange = (event: SelectChangeEvent): void => {
+ setSelectedOrganization(event.target.value as string);
+ };
+
+ const { data: joinedOrganizationsData } = useQuery(
+ USER_JOINED_ORGANIZATIONS,
+ {
+ variables: { id: userId },
+ },
+ );
+
+ function reset(): void {
+ setTitle('');
+ setUserIds([]);
+ setSelectedOrganization('');
+ }
+
+ useEffect(() => {
+ setUserIds(userIds);
+ }, [userIds]);
+
+ async function handleCreateGroupChat(): Promise {
+ await createChat({
+ variables: {
+ organizationId: selectedOrganization,
+ userIds: [userId, ...userIds],
+ name: title,
+ isGroup: true,
+ },
+ });
+ chatsListRefetch();
+ toggleAddUserModal();
+ toggleCreateGroupChatModal();
+ reset();
+ }
+
+ const [userName, setUserName] = useState('');
+
+ const {
+ data: allUsersData,
+ loading: allUsersLoading,
+ refetch: allUsersRefetch,
+ } = useQuery(USERS_CONNECTION_LIST, {
+ variables: {
+ firstName_contains: '',
+ lastName_contains: '',
+ },
+ });
+
+ const handleUserModalSearchChange = (e: React.FormEvent): void => {
+ e.preventDefault();
+ /* istanbul ignore next */
+ const [firstName, lastName] = userName.split(' ');
+
+ const newFilterData = {
+ firstName_contains: firstName || '',
+ lastName_contains: lastName || '',
+ };
+
+ allUsersRefetch({
+ ...newFilterData,
+ });
+ };
+
+ useEffect(() => {
+ if (joinedOrganizationsData && joinedOrganizationsData.users.length > 0) {
+ const organizations =
+ joinedOrganizationsData.users[0]?.user?.joinedOrganizations || [];
+ setOrganizations(organizations);
+ }
+ }, [joinedOrganizationsData]);
+
+ return (
+ <>
+
+
+ New Group
+
+
+
+ Group name
+ {
+ setTitle(e.target.value);
+ }}
+ />
+
+
+
+
+
+
+
+ {'Chat'}
+
+
+ {allUsersLoading ? (
+ <>
+
+ >
+ ) : (
+ <>
+
+
{
+ const { value } = e.target;
+ setUserName(value);
+ }}
+ />
+
+
+
+
+
+
+
+
+ #
+ {'user'}
+ {'Chat'}
+
+
+
+ {allUsersData &&
+ allUsersData.users.length > 0 &&
+ allUsersData.users.map(
+ (
+ userDetails: InterfaceQueryUserListItem,
+ index: number,
+ ) => (
+
+
+ {index + 1}
+
+
+ {userDetails.user.firstName +
+ ' ' +
+ userDetails.user.lastName}
+
+ {userDetails.user.email}
+
+
+ {userIds.includes(userDetails.user._id) ? (
+
+ ) : (
+
+ )}
+
+
+ ),
+ )}
+
+
+
+ >
+ )}
+
+
+
+ >
+ );
+}
diff --git a/src/components/UserPortal/DonationCard/DonationCard.test.tsx b/src/components/UserPortal/DonationCard/DonationCard.test.tsx
index 4e49ed8b26..cddf62dd6c 100644
--- a/src/components/UserPortal/DonationCard/DonationCard.test.tsx
+++ b/src/components/UserPortal/DonationCard/DonationCard.test.tsx
@@ -1,5 +1,5 @@
-import React from 'react';
-import { act, render } from '@testing-library/react';
+import React, { act } from 'react';
+import { render } from '@testing-library/react';
import { MockedProvider } from '@apollo/react-testing';
import { I18nextProvider } from 'react-i18next';
diff --git a/src/components/UserPortal/DonationCard/DonationCard.tsx b/src/components/UserPortal/DonationCard/DonationCard.tsx
index 696c5fb57b..63082f6acf 100644
--- a/src/components/UserPortal/DonationCard/DonationCard.tsx
+++ b/src/components/UserPortal/DonationCard/DonationCard.tsx
@@ -3,8 +3,24 @@ import styles from './DonationCard.module.css';
import { type InterfaceDonationCardProps } from 'screens/UserPortal/Donate/Donate';
import { Button } from 'react-bootstrap';
+/**
+ * Displays a card with details about a donation.
+ *
+ * Shows the donor's name, the amount donated, and the date of the donation.
+ * Includes a button to view more details about the donation.
+ *
+ * @param props - The properties passed to the component.
+ * @param name - The name of the donor.
+ * @param amount - The amount donated.
+ * @param updatedAt - The date of the donation, in ISO format.
+ *
+ * @returns The rendered donation card component.
+ */
function donationCard(props: InterfaceDonationCardProps): JSX.Element {
+ // Create a date object from the donation date string
const date = new Date(props.updatedAt);
+
+ // Format the date into a readable string
const formattedDate = new Intl.DateTimeFormat('en-US', {
weekday: 'short',
year: 'numeric',
diff --git a/src/components/UserPortal/EventCard/EventCard.tsx b/src/components/UserPortal/EventCard/EventCard.tsx
index db8cd69785..e93138ce42 100644
--- a/src/components/UserPortal/EventCard/EventCard.tsx
+++ b/src/components/UserPortal/EventCard/EventCard.tsx
@@ -35,21 +35,59 @@ interface InterfaceEventCardProps {
}[];
}
+/**
+ * Displays information about an event and provides an option to register for it.
+ *
+ * Shows the event's title, description, location, start and end dates and times,
+ * creator's name, and registration status. Includes a button to register for the event
+ * if the user is not already registered.
+ *
+ * @param props - The properties for the event card.
+ * @param id - The unique identifier of the event.
+ * @param title - The title of the event.
+ * @param description - A description of the event.
+ * @param location - The location where the event will take place.
+ * @param startDate - The start date of the event in ISO format.
+ * @param endDate - The end date of the event in ISO format.
+ * @param isRegisterable - Indicates if the event can be registered for.
+ * @param isPublic - Indicates if the event is public.
+ * @param endTime - The end time of the event in HH:mm:ss format.
+ * @param startTime - The start time of the event in HH:mm:ss format.
+ * @param recurring - Indicates if the event is recurring.
+ * @param allDay - Indicates if the event lasts all day.
+ * @param creator - The creator of the event with their name and ID.
+ * @param registrants - A list of registrants with their IDs.
+ *
+ * @returns The event card component.
+ */
function eventCard(props: InterfaceEventCardProps): JSX.Element {
+ // Extract the translation functions
const { t } = useTranslation('translation', {
keyPrefix: 'userEventCard',
});
const { t: tCommon } = useTranslation('common');
+
+ // Get user ID from local storage
const { getItem } = useLocalStorage();
const userId = getItem('userId');
+
+ // Create a full name for the event creator
const creatorName = `${props.creator.firstName} ${props.creator.lastName}`;
+
+ // Check if the user is initially registered for the event
const isInitiallyRegistered = props.registrants.some(
(registrant) => registrant.id === userId,
);
+ // Set up the mutation for registering for the event
const [registerEventMutation, { loading }] = useMutation(REGISTER_EVENT);
const [isRegistered, setIsRegistered] = React.useState(isInitiallyRegistered);
+ /**
+ * Handles registering for the event.
+ * If the user is not already registered, sends a mutation request to register.
+ * Displays a success or error message based on the result.
+ */
const handleRegister = async (): Promise => {
if (!isRegistered) {
try {
@@ -65,7 +103,7 @@ function eventCard(props: InterfaceEventCardProps): JSX.Element {
}
} catch (error: unknown) {
/* istanbul ignore next */
- toast.error(error);
+ toast.error(error as string);
}
}
};
diff --git a/src/components/UserPortal/Login/Login.module.css b/src/components/UserPortal/Login/Login.module.css
deleted file mode 100644
index 98be9db02a..0000000000
--- a/src/components/UserPortal/Login/Login.module.css
+++ /dev/null
@@ -1,29 +0,0 @@
-.forgotPasswordContainer {
- display: flex;
- justify-content: flex-end;
- flex-direction: row;
- margin: 5px 0px;
-}
-
-.forgotPasswordText {
- color: black;
- font-size: 12px;
- margin: 2px 0px;
-}
-
-.borderNone {
- border: none;
-}
-
-.colorWhite {
- color: white;
-}
-
-.colorPrimary {
- background: #31bb6b;
-}
-
-.colorPrimaryHover:hover {
- background: #31bb6b;
- border: none;
-}
diff --git a/src/components/UserPortal/Login/Login.test.tsx b/src/components/UserPortal/Login/Login.test.tsx
deleted file mode 100644
index 9248c5e9ec..0000000000
--- a/src/components/UserPortal/Login/Login.test.tsx
+++ /dev/null
@@ -1,306 +0,0 @@
-import type { SetStateAction } from 'react';
-import React from 'react';
-import { act, render, screen } from '@testing-library/react';
-import { MockedProvider } from '@apollo/react-testing';
-import userEvent from '@testing-library/user-event';
-import { I18nextProvider } from 'react-i18next';
-
-import { LOGIN_MUTATION } from 'GraphQl/Mutations/mutations';
-import { BrowserRouter } from 'react-router-dom';
-import { Provider } from 'react-redux';
-import { store } from 'state/store';
-import i18nForTest from 'utils/i18nForTest';
-import { StaticMockLink } from 'utils/StaticMockLink';
-import Login from './Login';
-import { toast } from 'react-toastify';
-
-const MOCKS = [
- {
- request: {
- query: LOGIN_MUTATION,
- variables: {
- email: 'johndoe@gmail.com',
- password: 'johndoe',
- },
- },
- result: {
- data: {
- login: {
- user: {
- _id: '1',
- firstName: 'firstname',
- lastName: 'secondname',
- email: 'tempemail@example.com',
- image: 'image',
- },
- accessToken: 'accessToken',
- refreshToken: 'refreshToken',
- appUserProfile: {
- adminFor: [
- {
- _id: 'id',
- },
- ],
- isSuperAdmin: true,
- },
- },
- },
- },
- },
- {
- request: {
- query: LOGIN_MUTATION,
- variables: {
- email: 'johndoe@gmail.com',
- password: 'jdoe',
- },
- },
- result: {
- data: {
- login: {
- user: {
- _id: '1',
- firstName: 'firstname',
- lastName: 'secondname',
- email: 'tempemail@example.com',
- image: 'image',
- },
- appUserProfile: {
- adminFor: {},
- isSuperAdmin: false,
- },
- accessToken: 'accessToken',
- refreshToken: 'refreshToken',
- },
- },
- },
- },
- {
- request: {
- query: LOGIN_MUTATION,
- variables: {
- email: 'invalid@gmail.com',
- password: 'anything',
- },
- },
- result: {},
- },
-];
-
-const link = new StaticMockLink(MOCKS, true);
-
-async function wait(ms = 100): Promise {
- await act(() => {
- return new Promise((resolve) => {
- setTimeout(resolve, ms);
- });
- });
-}
-
-jest.mock('react-toastify', () => ({
- toast: {
- success: jest.fn(),
- warn: jest.fn(),
- error: jest.fn(),
- },
-}));
-const mockNavigate = jest.fn();
-jest.mock('react-router-dom', () => ({
- ...jest.requireActual('react-router-dom'),
- useNavigate: () => mockNavigate,
-}));
-
-const setCurrentMode: React.Dispatch> = jest.fn();
-
-const props = {
- setCurrentMode,
-};
-
-describe('Testing Login Component [User Portal]', () => {
- test('Component should be rendered properly', async () => {
- render(
-
-
-
-
-
-
-
-
- ,
- );
-
- await wait();
- });
-
- test('Expect the mode to be changed to Register', async () => {
- render(
-
-
-
-
-
-
-
-
- ,
- );
-
- await wait();
-
- userEvent.click(screen.getByTestId('setRegisterBtn'));
-
- expect(setCurrentMode).toBeCalledWith('register');
- });
-
- test('toast.error is triggered if the email input is empty.', async () => {
- render(
-
-
-
-
-
-
-
-
- ,
- );
-
- await wait();
-
- userEvent.click(screen.getByTestId('loginBtn'));
-
- expect(toast.error).toBeCalledWith(
- 'Please enter a valid email and password.',
- );
- });
-
- test('toast.error is triggered if the password input is empty.', async () => {
- const formData = {
- email: 'johndoe@gmail.com',
- password: 'joe',
- };
-
- render(
-
-
-
-
-
-
-
-
- ,
- );
-
- await wait();
-
- userEvent.type(screen.getByPlaceholderText(/Enter Email/i), formData.email);
- userEvent.click(screen.getByTestId('loginBtn'));
-
- expect(toast.error).toBeCalledWith(
- 'Please enter a valid email and password.',
- );
- });
-
- test('Incorrect password is entered.', async () => {
- const formData = {
- email: 'invalid@gmail.com',
- password: 'anything',
- };
-
- render(
-
-
-
-
-
-
-
-
- ,
- );
-
- await wait();
-
- userEvent.type(screen.getByPlaceholderText(/Enter Email/i), formData.email);
-
- userEvent.type(
- screen.getByPlaceholderText(/Enter Password/i),
- formData.password,
- );
-
- userEvent.click(screen.getByTestId('loginBtn'));
-
- expect(toast.error).toBeCalled();
-
- await wait();
- });
-
- test('Login details are entered correctly.', async () => {
- const formData = {
- email: 'johndoe@gmail.com',
- password: 'johndoe',
- };
-
- render(
-
-
-
-
-
-
-
-
- ,
- );
-
- await wait();
-
- userEvent.type(screen.getByPlaceholderText(/Enter Email/i), formData.email);
-
- userEvent.type(
- screen.getByPlaceholderText(/Enter Password/i),
- formData.password,
- );
-
- userEvent.click(screen.getByTestId('loginBtn'));
-
- await wait();
- expect(mockNavigate).toHaveBeenCalledWith('/user/organizations');
- });
-
- test('Current user has not been approved by admin.', async () => {
- const formData = {
- email: 'johndoe@gmail.com',
- password: 'jdoe',
- };
-
- render(
-
-
-
-
-
-
-
-
- ,
- );
-
- await wait();
-
- userEvent.type(screen.getByPlaceholderText(/Enter Email/i), formData.email);
-
- userEvent.type(
- screen.getByPlaceholderText(/Enter Password/i),
- formData.password,
- );
-
- userEvent.click(screen.getByTestId('loginBtn'));
-
- expect(toast.error).toBeCalled();
-
- await wait();
- });
-});
diff --git a/src/components/UserPortal/Login/Login.tsx b/src/components/UserPortal/Login/Login.tsx
deleted file mode 100644
index 517170263e..0000000000
--- a/src/components/UserPortal/Login/Login.tsx
+++ /dev/null
@@ -1,144 +0,0 @@
-import { useMutation } from '@apollo/client';
-import { LockOutlined } from '@mui/icons-material';
-import EmailOutlinedIcon from '@mui/icons-material/EmailOutlined';
-import type { ChangeEvent, SetStateAction } from 'react';
-import React from 'react';
-import { Button, Form, InputGroup } from 'react-bootstrap';
-import { useTranslation } from 'react-i18next';
-import { Link, useNavigate } from 'react-router-dom';
-import { toast } from 'react-toastify';
-
-import { LOGIN_MUTATION } from 'GraphQl/Mutations/mutations';
-import { errorHandler } from 'utils/errorHandler';
-import useLocalStorage from 'utils/useLocalstorage';
-import styles from './Login.module.css';
-
-interface InterfaceLoginProps {
- setCurrentMode: React.Dispatch>;
-}
-
-export default function login(props: InterfaceLoginProps): JSX.Element {
- const { t } = useTranslation('translation', { keyPrefix: 'userLogin' });
- const { t: tCommon } = useTranslation('common');
-
- const navigate = useNavigate();
-
- const { setCurrentMode } = props;
-
- const { setItem } = useLocalStorage();
-
- const handleModeChangeToRegister = (): void => {
- setCurrentMode('register');
- };
-
- const [loginMutation] = useMutation(LOGIN_MUTATION);
-
- const [loginVariables, setLoginVariables] = React.useState({
- email: '',
- password: '',
- });
-
- const handleLogin = async (): Promise => {
- if (!(loginVariables.email && loginVariables.password)) {
- toast.error(t('invalidDetailsMessage'));
- } else {
- try {
- const { data } = await loginMutation({
- variables: {
- email: loginVariables.email,
- password: loginVariables.password,
- },
- });
-
- setItem('token', data.login.accessToken);
- setItem('userId', data.login.user._id);
- navigate('/user/organizations');
- } catch (error: unknown) {
- errorHandler(t, error);
- }
- }
- };
-
- /* istanbul ignore next */
- const handleEmailChange = (e: ChangeEvent): void => {
- const email = e.target.value;
-
- setLoginVariables({
- email,
- password: loginVariables.password,
- });
- };
-
- /* istanbul ignore next */
- const handlePasswordChange = (e: ChangeEvent): void => {
- const password = e.target.value;
-
- setLoginVariables({
- email: loginVariables.email,
- password,
- });
- };
-
- return (
- <>
- {tCommon('login')}
-
-
-
{tCommon('emailAddress')}
-
-
-
-
-
-
- {tCommon('password')}
-
-
-
-
-
-
-
-
-
-
- {tCommon('forgotPassword')}
-
-
-
-
-
-
- >
- );
-}
diff --git a/src/components/UserPortal/OrganizationCard/OrganizationCard.test.tsx b/src/components/UserPortal/OrganizationCard/OrganizationCard.test.tsx
index dba4286290..ba13fe346d 100644
--- a/src/components/UserPortal/OrganizationCard/OrganizationCard.test.tsx
+++ b/src/components/UserPortal/OrganizationCard/OrganizationCard.test.tsx
@@ -1,5 +1,5 @@
-import React from 'react';
-import { act, fireEvent, render, screen } from '@testing-library/react';
+import React, { act } from 'react';
+import { fireEvent, render, screen } from '@testing-library/react';
import { MockedProvider } from '@apollo/react-testing';
import { I18nextProvider } from 'react-i18next';
@@ -250,7 +250,7 @@ describe('Testing OrganizationCard Component [User Portal]', () => {
fireEvent.click(screen.getByTestId('joinBtn'));
await wait();
- expect(toast.success).toHaveBeenCalledWith('users.MembershipRequestSent');
+ expect(toast.success).toHaveBeenCalledWith('MembershipRequestSent');
});
test('send membership request to public org', async () => {
diff --git a/src/components/UserPortal/OrganizationCard/OrganizationCard.tsx b/src/components/UserPortal/OrganizationCard/OrganizationCard.tsx
index fdb2d040d9..e1c2c23beb 100644
--- a/src/components/UserPortal/OrganizationCard/OrganizationCard.tsx
+++ b/src/components/UserPortal/OrganizationCard/OrganizationCard.tsx
@@ -48,6 +48,26 @@ interface InterfaceOrganizationCardProps {
}[];
}
+/**
+ * Displays an organization card with options to join or manage membership.
+ *
+ * Shows the organization's name, image, description, address, number of admins and members,
+ * and provides buttons for joining, withdrawing membership requests, or visiting the organization page.
+ *
+ * @param props - The properties for the organization card.
+ * @param id - The unique identifier of the organization.
+ * @param name - The name of the organization.
+ * @param image - The URL of the organization's image.
+ * @param description - A description of the organization.
+ * @param admins - The list of admins with their IDs.
+ * @param members - The list of members with their IDs.
+ * @param address - The address of the organization including city, country code, line1, postal code, and state.
+ * @param membershipRequestStatus - The status of the membership request (accepted, pending, or empty).
+ * @param userRegistrationRequired - Indicates if user registration is required to join the organization.
+ * @param membershipRequests - The list of membership requests with user IDs.
+ *
+ * @returns The organization card component.
+ */
const userId: string | null = getItem('userId');
function organizationCard(props: InterfaceOrganizationCardProps): JSX.Element {
@@ -58,6 +78,7 @@ function organizationCard(props: InterfaceOrganizationCardProps): JSX.Element {
const navigate = useNavigate();
+ // Mutations for handling organization memberships
const [sendMembershipRequest] = useMutation(SEND_MEMBERSHIP_REQUEST, {
refetchQueries: [
{ query: USER_ORGANIZATION_CONNECTION, variables: { id: props.id } },
@@ -77,6 +98,10 @@ function organizationCard(props: InterfaceOrganizationCardProps): JSX.Element {
variables: { id: userId },
});
+ /**
+ * Handles joining the organization. Sends a membership request if registration is required,
+ * otherwise joins the public organization directly. Displays success or error messages.
+ */
async function joinOrganization(): Promise {
try {
if (props.userRegistrationRequired) {
@@ -85,28 +110,31 @@ function organizationCard(props: InterfaceOrganizationCardProps): JSX.Element {
organizationId: props.id,
},
});
- toast.success(t('MembershipRequestSent'));
+ toast.success(t('MembershipRequestSent') as string);
} else {
await joinPublicOrganization({
variables: {
organizationId: props.id,
},
});
- toast.success(t('orgJoined'));
+ toast.success(t('orgJoined') as string);
}
refetch();
} catch (error: unknown) {
/* istanbul ignore next */
if (error instanceof Error) {
if (error.message === 'User is already a member') {
- toast.error(t('AlreadyJoined'));
+ toast.error(t('AlreadyJoined') as string);
} else {
- toast.error(t('errorOccured'));
+ toast.error(t('errorOccured') as string);
}
}
}
}
+ /**
+ * Handles withdrawing a membership request. Finds the request for the current user and cancels it.
+ */
async function withdrawMembershipRequest(): Promise {
const membershipRequest = props.membershipRequests.find(
(request) => request.user._id === userId,
diff --git a/src/components/UserPortal/OrganizationNavbar/OrganizationNavbar.test.tsx b/src/components/UserPortal/OrganizationNavbar/OrganizationNavbar.test.tsx
index 027234b641..038ff626df 100644
--- a/src/components/UserPortal/OrganizationNavbar/OrganizationNavbar.test.tsx
+++ b/src/components/UserPortal/OrganizationNavbar/OrganizationNavbar.test.tsx
@@ -1,7 +1,7 @@
-import React from 'react';
+import React, { act } from 'react';
import { MockedProvider } from '@apollo/react-testing';
import 'jest-localstorage-mock';
-import { act, render, screen } from '@testing-library/react';
+import { render, screen } from '@testing-library/react';
import { I18nextProvider } from 'react-i18next';
import { Provider } from 'react-redux';
import { BrowserRouter, Router } from 'react-router-dom';
diff --git a/src/components/UserPortal/OrganizationNavbar/OrganizationNavbar.tsx b/src/components/UserPortal/OrganizationNavbar/OrganizationNavbar.tsx
index 90cd75a83c..34022fcfcf 100644
--- a/src/components/UserPortal/OrganizationNavbar/OrganizationNavbar.tsx
+++ b/src/components/UserPortal/OrganizationNavbar/OrganizationNavbar.tsx
@@ -1,6 +1,6 @@
import React from 'react';
import styles from './OrganizationNavbar.module.css';
-import TalawaImage from 'assets/images/talawa-logo-200x200.png';
+import TalawaImage from 'assets/images/talawa-logo-600x600.png';
import { Container, Dropdown, Nav, Navbar, Offcanvas } from 'react-bootstrap';
import { languages } from 'utils/languages';
import i18next from 'i18next';
@@ -26,6 +26,21 @@ type Plugin = {
translated: string;
view: boolean;
};
+
+/**
+ * Displays the organization navbar with navigation options, user settings, and language selection.
+ *
+ * The navbar includes:
+ * - Organization branding and name.
+ * - Navigation links for various plugins based on user permissions.
+ * - Language dropdown for changing the interface language.
+ * - User dropdown for accessing settings and logging out.
+ *
+ * @param props - The properties for the navbar.
+ * @param currentPage - The current page identifier for highlighting the active navigation link.
+ *
+ * @returns The organization navbar component.
+ */
function organizationNavbar(props: InterfaceNavbarProps): JSX.Element {
const { t } = useTranslation('translation', {
keyPrefix: 'userNavbar',
@@ -37,7 +52,7 @@ function organizationNavbar(props: InterfaceNavbarProps): JSX.Element {
const [organizationDetails, setOrganizationDetails] = React.useState<{
name: string;
}>({ name: '' });
- // const dropDirection: DropDirection = screen.width > 767 ? 'start' : 'down';
+
const dropDirection: DropDirection = 'start';
const { orgId: organizationId } = useParams();
@@ -53,6 +68,9 @@ function organizationNavbar(props: InterfaceNavbarProps): JSX.Element {
const { getItem, setItem } = useLocalStorage();
+ /**
+ * Handles user logout by clearing local storage and redirecting to the home page.
+ */
/* istanbul ignore next */
const handleLogout = (): void => {
localStorage.clear();
@@ -60,6 +78,7 @@ function organizationNavbar(props: InterfaceNavbarProps): JSX.Element {
};
const userName = getItem('name');
+
React.useEffect(() => {
if (data) {
setOrganizationDetails({ name: data.organizationsConnection[0].name });
@@ -67,6 +86,7 @@ function organizationNavbar(props: InterfaceNavbarProps): JSX.Element {
}, [data]);
const homeLink = `/user/organization/${organizationId}`;
+
let plugins: Plugin[] = [
{
pluginName: 'People',
@@ -97,15 +117,14 @@ function organizationNavbar(props: InterfaceNavbarProps): JSX.Element {
// view: true,
// },
];
+
if (getItem('talawaPlugins')) {
const talawaPlugins: string = getItem('talawaPlugins') || '{}';
plugins = JSON.parse(talawaPlugins);
}
- const { data: updatedPluginData } = useSubscription(
- PLUGIN_SUBSCRIPTION,
- // { variables: { } }
- );
+ const { data: updatedPluginData } = useSubscription(PLUGIN_SUBSCRIPTION);
+
function getPluginIndex(pluginName: string, pluginsArray: Plugin[]): number {
return pluginsArray.findIndex((plugin) => plugin.pluginName === pluginName);
}
@@ -129,6 +148,7 @@ function organizationNavbar(props: InterfaceNavbarProps): JSX.Element {
}
}
}
+
return (
diff --git a/src/components/UserPortal/OrganizationSidebar/OrganizationSidebar.test.tsx b/src/components/UserPortal/OrganizationSidebar/OrganizationSidebar.test.tsx
index c5fbcf335e..c08240462a 100644
--- a/src/components/UserPortal/OrganizationSidebar/OrganizationSidebar.test.tsx
+++ b/src/components/UserPortal/OrganizationSidebar/OrganizationSidebar.test.tsx
@@ -1,5 +1,5 @@
-import React from 'react';
-import { act, render, screen } from '@testing-library/react';
+import React, { act } from 'react';
+import { render, screen } from '@testing-library/react';
import { MockedProvider } from '@apollo/react-testing';
import { I18nextProvider } from 'react-i18next';
diff --git a/src/components/UserPortal/OrganizationSidebar/OrganizationSidebar.tsx b/src/components/UserPortal/OrganizationSidebar/OrganizationSidebar.tsx
index 6e5aa42d70..796d30d568 100644
--- a/src/components/UserPortal/OrganizationSidebar/OrganizationSidebar.tsx
+++ b/src/components/UserPortal/OrganizationSidebar/OrganizationSidebar.tsx
@@ -18,40 +18,68 @@ import type {
InterfaceMemberInfo,
} from 'utils/interfaces';
+/**
+ * OrganizationSidebar displays the sidebar for an organization, showing a list of members and events.
+ *
+ * This component fetches and displays:
+ * - The top 3 members of the organization with their images and names.
+ * - The top 3 upcoming events for the organization with their titles, start, and end dates.
+ *
+ * It includes:
+ * - A link to view all members.
+ * - A link to view all events.
+ *
+ * The sidebar handles loading states and displays appropriate messages while data is being fetched.
+ *
+ * @returns JSX.Element representing the organization sidebar.
+ */
export default function organizationSidebar(): JSX.Element {
+ // Translation functions for different namespaces
const { t } = useTranslation('translation', {
keyPrefix: 'organizationSidebar',
});
const { t: tCommon } = useTranslation('common');
+ // Extract the organization ID from the URL parameters
const { orgId: organizationId } = useParams();
- const [members, setMembers] = React.useState([]);
- const [events, setEvents] = React.useState([]);
- const eventsLink = `/user/events/id=${organizationId}`;
- const peopleLink = `/user/people/id=${organizationId}`;
+ const [members, setMembers] = React.useState<
+ InterfaceMemberInfo[] | undefined
+ >(undefined);
+ const [events, setEvents] = React.useState<
+ InterfaceQueryOrganizationEventListItem[] | undefined
+ >(undefined);
+ const eventsLink = `/user/events/${organizationId}`;
+ const peopleLink = `/user/people/${organizationId}`;
+ // Query to fetch members of the organization
const { data: memberData, loading: memberLoading } = useQuery(
ORGANIZATIONS_MEMBER_CONNECTION_LIST,
{
variables: {
orgId: organizationId,
- first: 3,
- skip: 0,
+ first: 3, // Fetch top 3 members
+ skip: 0, // No offset
},
},
);
+ // Query to fetch events of the organization
const { data: eventsData, loading: eventsLoading } = useQuery(
ORGANIZATION_EVENT_CONNECTION_LIST,
{
variables: {
organization_id: organizationId,
- first: 3,
- skip: 0,
+ first: 3, // Fetch top 3 upcoming events
+ skip: 0, // No offset
},
},
);
+ /**
+ * Effect hook to update members state when memberData is fetched.
+ *
+ * Sets the members state with the data from the query.
+ */
/* istanbul ignore next */
useEffect(() => {
if (memberData) {
@@ -59,6 +87,11 @@ export default function organizationSidebar(): JSX.Element {
}
}, [memberData]);
+ /**
+ * Effect hook to update events state when eventsData is fetched.
+ *
+ * Sets the events state with the data from the query.
+ */
/* istanbul ignore next */
useEffect(() => {
if (eventsData) {
@@ -68,6 +101,7 @@ export default function organizationSidebar(): JSX.Element {
return (
+ {/* Members section */}
{tCommon('members')}
@@ -77,44 +111,42 @@ export default function organizationSidebar(): JSX.Element {
) : (
- {members.length ? (
- members.map(
- (
- member: InterfaceMemberInfo,
- index: React.Key | null | undefined,
- ) => {
- const memberName = `${member.firstName} ${member.lastName}`;
- return (
-
-
-
-
{memberName}
-
-
- );
- },
- )
+ {members && members.length ? (
+ members.map((member: InterfaceMemberInfo) => {
+ const memberName = `${member.firstName} ${member.lastName}`;
+ return (
+
+
+
+
{memberName}
+
+
+ );
+ })
) : (
{t('noMembers')}
)}
)}
+ {/* Link to view all members */}
{t('viewAll')}
+
+ {/* Events section */}
{t('events')}
@@ -124,42 +156,39 @@ export default function organizationSidebar(): JSX.Element {