diff --git a/.github/workflows/code_coverage_disable_check.py b/.github/workflows/code_coverage_disable_check.py new file mode 100644 index 0000000000..1a55c3f720 --- /dev/null +++ b/.github/workflows/code_coverage_disable_check.py @@ -0,0 +1,167 @@ +"""Code Coverage Disable Checker Script. + +Methodology: + + Recursively analyzes TypeScript files in the specified directories or + checks specific files + to ensure they do not contain code coverage disable statements. + + This script enforces proper code coverage practices in the project. + +NOTE: + This script complies with our python3 coding and documentation standards. + It complies with: + + 1) Pylint + 2) Pydocstyle + 3) Pycodestyle + 4) Flake8 + 5) Python Black + +""" + +import os +import re +import argparse +import sys + + +def has_code_coverage_disable(file_path): + """ + Check if a TypeScript file contains code coverage disable statements. + + Args: + file_path (str): Path to the TypeScript file. + + Returns: + bool: True if code coverage disable statement is found, False + otherwise. + """ + code_coverage_disable_pattern = re.compile( + r"""//?\s*istanbul\s+ignore(?:\s+(?:next|-line))?[^\n]*| + /\*\s*istanbul\s+ignore\s+(?:next|-line)\s*\*/""", + re.IGNORECASE, + ) + try: + with open(file_path, "r", encoding="utf-8") as file: + content = file.read() + return bool(code_coverage_disable_pattern.search(content)) + except FileNotFoundError: + print(f"File not found: {file_path}") + return False + except PermissionError: + print(f"Permission denied: {file_path}") + return False + except (IOError, OSError) as e: + print(f"Error reading file {file_path}: {e}") + return False + + +def check_code_coverage(files_or_dirs): + """ + Check TypeScript files for code coverage disable statements. + + Args: + files_or_dirs (list): List of files or directories to check. + + Returns: + bool: True if code coverage disable statement is found, False + otherwise. + """ + code_coverage_found = False + + for item in files_or_dirs: + if os.path.isdir(item): + # If it's a directory, recursively walk through the files in it + for root, _, files in os.walk(item): + if "node_modules" in root: + continue + for file_name in files: + if ( + file_name.endswith(".tsx") + or file_name.endswith(".ts") + and not file_name.endswith(".test.tsx") + and not file_name.endswith(".test.ts") + and not file_name.endswith(".spec.tsx") + and not file_name.endswith(".spec.ts") + ): + file_path = os.path.join(root, file_name) + if has_code_coverage_disable(file_path): + print( + f"""File {file_path} contains code coverage disable statement.""" + ) + code_coverage_found = True + elif os.path.isfile(item): + # If it's a file, check it directly + if ( + item.endswith(".tsx") + or item.endswith(".ts") + and not item.endswith(".test.tsx") + and not item.endswith(".test.ts") + and not item.endswith(".spec.tsx") + and not item.endswith(".spec.ts") + ): + if has_code_coverage_disable(item): + print( + f"""File {item} contains code coverage disable statement. Please remove it and add the appropriate tests.""" + ) + code_coverage_found = True + + return code_coverage_found + + +def arg_parser_resolver(): + """Resolve the CLI arguments provided by the user. + + Returns: + result: Parsed argument object + """ + parser = argparse.ArgumentParser() + parser.add_argument( + "--directory", + type=str, + nargs="+", + default=[os.getcwd()], + help="""One or more directories to check for code coverage disable + statements (default: current directory).""", + ) + parser.add_argument( + "--files", + type=str, + nargs="+", + default=[], + help="""One or more files to check directly for code coverage disable + statements (default: check directories).""", + ) + return parser.parse_args() + + +def main(): + """ + Execute the script's main functionality. + + This function serves as the entry point for the script. It performs + the following tasks: + 1. Validates and retrieves the files or directories to check from + command line arguments. + 2. Checks files or directories for code coverage disable statements. + 3. Provides informative messages based on the analysis. + 4. Exits with an error if code coverage disable statements are found. + + Raises: + SystemExit: If an error occurs during execution. + """ + args = arg_parser_resolver() + files_or_dirs = args.files if args.files else args.directory + # Check code coverage in the specified files or directories + code_coverage_found = check_code_coverage(files_or_dirs) + + if code_coverage_found: + print("Code coverage disable check failed. Exiting with error.") + sys.exit(1) + + print("Code coverage disable check completed successfully.") + + +if __name__ == "__main__": + main() diff --git a/.github/workflows/eslint_disable_check.py b/.github/workflows/eslint_disable_check.py index 201b4462b8..a24a80949e 100644 --- a/.github/workflows/eslint_disable_check.py +++ b/.github/workflows/eslint_disable_check.py @@ -4,13 +4,13 @@ Methodology: - Recursively analyzes TypeScript files in the 'src' directory and its subdirectories - as well as 'setup.ts' files to ensure they do not contain eslint-disable statements. + Recursively analyzes TypeScript files in the specified directory + or checks specific files directly to ensure they do not contain + eslint-disable statements. This script enforces code quality practices in the project. NOTE: - This script complies with our python3 coding and documentation standards. It complies with: @@ -18,14 +18,15 @@ 2) Pydocstyle 3) Pycodestyle 4) Flake8 + 5) Python Black """ - import os import re import argparse import sys + def has_eslint_disable(file_path): """ Check if a TypeScript file contains eslint-disable statements. @@ -36,43 +37,65 @@ def has_eslint_disable(file_path): Returns: bool: True if eslint-disable statement is found, False otherwise. """ - eslint_disable_pattern = re.compile(r'//\s*eslint-disable(?:-next-line|-line)?', re.IGNORECASE) - + eslint_disable_pattern = re.compile( + r"""\/\/\s*eslint-disable(?:-next-line + |-line)?[^\n]*|\/\*\s*eslint-disable[^\*]*\*\/""", + re.IGNORECASE, + ) + try: - with open(file_path, 'r', encoding='utf-8') as file: + with open(file_path, "r", encoding="utf-8") as file: content = file.read() return bool(eslint_disable_pattern.search(content)) - except Exception as e: + except FileNotFoundError: + print(f"File not found: {file_path}") + return False + except PermissionError: + print(f"Permission denied: {file_path}") + return False + except (IOError, OSError) as e: print(f"Error reading file {file_path}: {e}") return False -def check_eslint(directory): + +def check_eslint(files_or_directories): """ - Recursively check TypeScript files for eslint-disable statements in the 'src' directory. + Check TypeScript files for eslint-disable statements. Args: - directory (str): Path to the directory. + files_or_directories (list): List of files or directories to check. Returns: bool: True if eslint-disable statement is found, False otherwise. """ eslint_found = False - for root, dirs, files in os.walk(os.path.join(directory, 'src')): - for file_name in files: - if file_name.endswith('.tsx') and not file_name.endswith('.test.tsx'): - file_path = os.path.join(root, file_name) - if has_eslint_disable(file_path): - print(f'File {file_path} contains eslint-disable statement.') + for item in files_or_directories: + if os.path.isfile(item): + # If it's a file, directly check it + if item.endswith(".ts") or item.endswith(".tsx"): + if has_eslint_disable(item): + print(f"File {item} contains eslint-disable statement. Please remove them and ensure the code adheres to the specified ESLint rules.") eslint_found = True - - setup_path = os.path.join(directory, 'setup.ts') - if os.path.exists(setup_path) and has_eslint_disable(setup_path): - print(f'Setup file {setup_path} contains eslint-disable statement.') - eslint_found = True + elif os.path.isdir(item): + # If it's a directory, walk through it and check all + # .ts and .tsx files + for root, _, files in os.walk(item): + if "node_modules" in root: + continue + for file_name in files: + if file_name.endswith(".ts") or file_name.endswith(".tsx"): + file_path = os.path.join(root, file_name) + if has_eslint_disable(file_path): + print( + f"""File {file_path} contains eslint-disable + statement.""" + ) + eslint_found = True return eslint_found + def arg_parser_resolver(): """Resolve the CLI arguments provided by the user. @@ -80,21 +103,32 @@ def arg_parser_resolver(): result: Parsed argument object """ parser = argparse.ArgumentParser() + parser.add_argument( + "--files", + type=str, + nargs="+", + default=[], + help="""List of files to check for eslint disable + statements (default: None).""", + ) parser.add_argument( "--directory", type=str, - default=os.getcwd(), - help="Path to the directory to check (default: current directory)" + nargs="+", + default=[os.getcwd()], + help="""One or more directories to check for eslint disable + statements (default: current directory).""", ) return parser.parse_args() + def main(): """ Execute the script's main functionality. This function serves as the entry point for the script. It performs the following tasks: - 1. Validates and retrieves the directory to check from + 1. Validates and retrieves the files and directories to check from command line arguments. 2. Recursively checks TypeScript files for eslint-disable statements. 3. Provides informative messages based on the analysis. @@ -105,12 +139,10 @@ def main(): """ args = arg_parser_resolver() - if not os.path.exists(args.directory): - print(f"Error: The specified directory '{args.directory}' does not exist.") - sys.exit(1) - - # Check eslint in the specified directory - eslint_found = check_eslint(args.directory) + # Determine whether to check files or directories based on the arguments + files_or_directories = args.files if args.files else args.directory + # Check eslint in the specified files or directories + eslint_found = check_eslint(files_or_directories) if eslint_found: print("ESLint-disable check failed. Exiting with error.") @@ -118,5 +150,6 @@ def main(): print("ESLint-disable check completed successfully.") + if __name__ == "__main__": main() diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 95572a6d81..4708e39869 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -59,7 +59,7 @@ jobs: if: steps.changed-files.outputs.only_changed != 'true' env: CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} - run: npx eslint ${CHANGED_FILES} && python .github/workflows/eslint_disable_check.py + run: npx eslint ${CHANGED_FILES} - name: Check for TSDoc comments run: npm run check-tsdoc # Run the TSDoc check script @@ -181,6 +181,30 @@ jobs: - name: Checkout code uses: actions/checkout@v4 + - name: Get changed files + id: changed-files + uses: tj-actions/changed-files@v45 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: 3.9 + + - name: Run Python script + run: | + python .github/workflows/eslint_disable_check.py --files ${{ steps.changed-files.outputs.all_changed_files }} + + Check-Code-Coverage-Disable: + name: Check for code coverage disable + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Get changed files + id: changed-files + uses: tj-actions/changed-files@v45 + - name: Set up Python uses: actions/setup-python@v5 with: @@ -188,12 +212,12 @@ jobs: - name: Run Python script run: | - python .github/workflows/eslint_disable_check.py + python .github/workflows/code_coverage_disable_check.py --files ${{ steps.changed-files.outputs.all_changed_files }} Test-Application: name: Test Application runs-on: ubuntu-latest - needs: [Code-Quality-Checks, Check-ESlint-Disable] + needs: [Code-Quality-Checks, Check-ESlint-Disable,Check-Code-Coverage-Disable] steps: - name: Checkout the Repository uses: actions/checkout@v4 diff --git a/public/locales/en/translation.json b/public/locales/en/translation.json index 50e45906f6..a6cb90d3d1 100644 --- a/public/locales/en/translation.json +++ b/public/locales/en/translation.json @@ -414,6 +414,7 @@ "recurringEvent": "Recurring Event", "isPublic": "Is Public", "isRegistrable": "Is Registrable", + "createChat": "Create Chat", "createEvent": "Create Event", "enterFilter": "Enter Filter", "enterTitle": "Enter Title", @@ -553,6 +554,7 @@ "recurringEvent": "Recurring Event", "isPublic": "Is Public", "isRegistrable": "Is Registrable", + "createChat": "Create Chat", "updatePost": "Update Post", "eventDetails": "Event Details", "eventDeleted": "Event deleted successfully.", @@ -1204,6 +1206,7 @@ "enterDescription": "Enter Description", "publicEvent": "Is Public", "registerable": "Is Registerable", + "createChat": "Create Chat", "monthlyCalendarView": "Monthly Calendar", "yearlyCalendarView": "Yearly Calender", "startTime": "startTime", @@ -1259,14 +1262,22 @@ "endOfResults": "endOfResults" }, "userChat": { + "add": "Add", "chat": "Chat", "search": "Search", "messages": "Messages", - "contacts": "Contacts" + "contacts": "Contacts", + "create": "Create", + "newChat": "New Chat", + "newGroupChat": "New Group Chat", + "groupInfo": "Group Info", + "members": "Members", + "addMembers": "Add Members" }, "userChatRoom": { "selectContact": "Select a contact to start conversation", - "sendMessage": "Send Message" + "sendMessage": "Send Message", + "reply": "Reply" }, "orgProfileField": { "loading": "Loading...", diff --git a/public/locales/fr/translation.json b/public/locales/fr/translation.json index 454abe6de9..416d00c4b4 100644 --- a/public/locales/fr/translation.json +++ b/public/locales/fr/translation.json @@ -439,7 +439,8 @@ "startDate": "Date de début", "endDate": "Date de fin", "talawaApiUnavailable": "API Talawa indisponible", - "done": "Fait" + "done": "Fait", + "createChat": "Créer une discussion" }, "organizationActionItems": { "actionItemCategory": "Catégorie de l'Action", @@ -579,7 +580,8 @@ "registerEvent": "Inscrire à l'événement", "close": "Fermer", "talawaApiUnavailable": "API Talawa non disponible", - "done": "Terminé" + "done": "Terminé", + "createChat": "Créer une discussion" }, "funds": { "title": "Fonds", @@ -1215,7 +1217,8 @@ "eventDescription": "Description de l'événement", "eventLocation": "Lieu de l'événement", "startDate": "Date de début", - "endDate": "Date de fin" + "endDate": "Date de fin", + "createChat": "Créer une discussion" }, "userEventCard": { "starts": "Départs", @@ -1259,14 +1262,22 @@ "endOfResults": "Fin des résultats" }, "userChat": { + "add": "Ajouter", "chat": "Chat", "contacts": "Contacts", "search": "rechercher", - "messages": "messages" + "messages": "messages", + "create": "créer", + "newChat": "nouvelle discussion", + "newGroupChat": "Nouvelle discussion de groupe", + "groupInfo": "Informations sur le groupe", + "members": "Membres", + "addMembers": "Add Members" }, "userChatRoom": { "selectContact": "Sélectionnez un contact pour démarrer la conversation", - "sendMessage": "Envoyer le message" + "sendMessage": "Envoyer le message", + "reply": "répondre" }, "orgProfileField": { "loading": "Chargement...", diff --git a/public/locales/hi/translation.json b/public/locales/hi/translation.json index 49289fed4f..6abb8abefc 100644 --- a/public/locales/hi/translation.json +++ b/public/locales/hi/translation.json @@ -439,7 +439,8 @@ "startDate": "प्रारंभ तिथि", "endDate": "समाप्ति तिथि", "talawaApiUnavailable": "Talawa API अनुपलब्ध", - "done": "पूर्ण" + "done": "पूर्ण", + "createChat": "चैट बनाएं" }, "organizationActionItems": { "actionItemCategory": "क्रिया वस्तु श्रेणी", @@ -579,7 +580,8 @@ "registerEvent": "कार्यक्रम के लिए पंजीकरण करें", "close": "बंद करें", "talawaApiUnavailable": "Talawa API अनुपलब्ध", - "done": "समाप्त" + "done": "समाप्त", + "createChat": "चैट बनाएं" }, "funds": { "title": "फंड", @@ -1215,7 +1217,8 @@ "eventDescription": "कार्यक्रम विवरण", "eventLocation": "कार्यक्रम स्थान", "startDate": "प्रारंभ तिथि", - "endDate": "समाप्ति तिथि" + "endDate": "समाप्ति तिथि", + "createChat": "चैट बनाएं" }, "userEventCard": { "starts": "प्रारंभ होगा", @@ -1259,14 +1262,22 @@ "endOfResults": "परिणाम समाप्त" }, "userChat": { + "add": "जोड़ें", "chat": "बात करना", "contacts": "संपर्क", "search": "खोज", - "messages": "संदेश" + "messages": "संदेश", + "create": "बनाएं", + "newChat": "नई चैट", + "newGroupChat": "नया समूह चैट", + "groupInfo": "समूह जानकारी", + "members": "सदस्यों", + "addMembers": "सदस्य जोड़ें" }, "userChatRoom": { "selectContact": "बातचीत शुरू करने के लिए एक संपर्क चुनें", - "sendMessage": "मेसेज भेजें" + "sendMessage": "मेसेज भेजें", + "reply": "जवाब" }, "orgProfileField": { "loading": "लोड हो रहा है...", diff --git a/public/locales/sp/translation.json b/public/locales/sp/translation.json index 606e5063fd..79d7436c39 100644 --- a/public/locales/sp/translation.json +++ b/public/locales/sp/translation.json @@ -439,7 +439,8 @@ "on": "En", "after": "Después de", "occurences": "ocurrencias", - "done": "Hecho" + "done": "Hecho", + "createChat": "Crear chat" }, "organizationActionItems": { "actionItemCategory": "Categoría de Acción", @@ -579,7 +580,8 @@ "on": "En", "after": "Después de", "occurences": "ocurrencias", - "done": "Hecho" + "done": "Hecho", + "createChat": "Crear chat" }, "funds": { "title": "Fondos", @@ -1218,7 +1220,8 @@ "publicEvent": "Es público", "registerable": "Es registrable", "monthlyCalendarView": "Calendario mensual", - "yearlyCalendarView": "Calendario anual" + "yearlyCalendarView": "Calendario anual", + "createChat": "Crear chat" }, "userEventCard": { "location": "Ubicación", @@ -1262,14 +1265,22 @@ "createAdvertisement": "Crear publicidad" }, "userChat": { + "add": "Agregar", "chat": "Charlar", "search": "Buscar", "contacts": "Contactos", - "messages": "Mensajes" + "messages": "Mensajes", + "create": "crear", + "newChat": "nueva charla", + "newGroupChat": "Nuevo chat grupal", + "groupInfo": "Información del grupo", + "members": "Miembros", + "addMembers": "Add Members" }, "userChatRoom": { "selectContact": "Seleccione un contacto para iniciar una conversación", - "sendMessage": "Enviar mensaje" + "sendMessage": "Enviar mensaje", + "reply": "responder" }, "orgProfileField": { "loading": "Cargando..", diff --git a/public/locales/zh/translation.json b/public/locales/zh/translation.json index 1138f3df39..32a4f953be 100644 --- a/public/locales/zh/translation.json +++ b/public/locales/zh/translation.json @@ -439,7 +439,8 @@ "startDate": "开始日期", "endDate": "结束日期", "talawaApiUnavailable": "塔拉瓦 API 不可用", - "done": "完成" + "done": "完成", + "createChat": "创建聊天" }, "organizationActionItems": { "actionItemCategory": "行动项类别", @@ -579,7 +580,8 @@ "registerEvent": "注册活动", "close": "关闭", "talawaApiUnavailable": "塔拉瓦 API 不可用", - "done": "完成" + "done": "完成", + "createChat": "创建聊天" }, "funds": { "title": "基金", @@ -1215,7 +1217,8 @@ "eventDescription": "活动描述", "eventLocation": "活动位置", "startDate": "开始日期", - "endDate": "结束日期" + "endDate": "结束日期", + "createChat": "创建聊天" }, "userEventCard": { "starts": "开始", @@ -1259,14 +1262,22 @@ "endOfResults": "结果结束" }, "userChat": { + "add": "添加", "chat": "聊天", "contacts": "联系方式", "search": "搜索", - "messages": "消息" + "messages": "消息", + "create": "创造", + "newChat": "新聊天", + "newGroupChat": "新群聊", + "groupInfo": "集团信息", + "members": "会员", + "addMembers": "Add Members" }, "userChatRoom": { "selectContact": "选择联系人开始对话", - "sendMessage": "发信息" + "sendMessage": "发信息", + "reply": "回复" }, "orgProfileField": { "loading": "加载中...", diff --git a/src/App.test.tsx b/src/App.spec.tsx similarity index 70% rename from src/App.test.tsx rename to src/App.spec.tsx index f4fba2ebf8..45b73943cf 100644 --- a/src/App.test.tsx +++ b/src/App.spec.tsx @@ -1,25 +1,27 @@ -import React, { act } from 'react'; +import React from 'react'; import { render, screen } from '@testing-library/react'; import { Provider } from 'react-redux'; import { MockedProvider } from '@apollo/react-testing'; import { BrowserRouter } from 'react-router-dom'; import { I18nextProvider } from 'react-i18next'; -import 'jest-location-mock'; +import { describe, it, expect, vi } from 'vitest'; import App from './App'; import { store } from 'state/store'; import { CHECK_AUTH } from 'GraphQl/Queries/Queries'; import i18nForTest from './utils/i18nForTest'; import { StaticMockLink } from 'utils/StaticMockLink'; -import useLocalStorage from 'utils/useLocalstorage'; -const { setItem } = useLocalStorage(); +vi.mock('@mui/x-charts/PieChart', () => ({ + pieArcLabelClasses: vi.fn(), + PieChart: vi.fn().mockImplementation(() => <>Test), + pieArcClasses: vi.fn(), +})); -// Mock the modules for PieChart rendering as they require a trasformer being used (which is not done by Jest) -// These modules are used by the Feedback components -jest.mock('@mui/x-charts/PieChart', () => ({ - pieArcLabelClasses: jest.fn(), - PieChart: jest.fn().mockImplementation(() => <>Test), - pieArcClasses: jest.fn(), +vi.mock('/src/assets/svgs/palisadoes.svg?react', () => ({ + default: () => Mocked SVG, +})); +vi.mock('/src/assets/svgs/talawa.svg?react', () => ({ + default: () => Mocked SVG, })); const MOCKS = [ @@ -59,16 +61,13 @@ const link = new StaticMockLink(MOCKS, true); const link2 = new StaticMockLink([], true); async function wait(ms = 100): Promise { - await act(() => { - return new Promise((resolve) => { - setTimeout(resolve, ms); - }); + await new Promise((resolve) => { + setTimeout(resolve, ms); }); } describe('Testing the App Component', () => { - test('Component should be rendered properly and user is loggedin', async () => { - setItem('AdminFor', [{ name: 'adi', _id: '1234', image: '' }]); + it('Component should be rendered properly and user is logged in', async () => { render( @@ -83,9 +82,9 @@ describe('Testing the App Component', () => { await wait(); - window.location.assign('/orglist'); + window.history.pushState({}, '', '/orglist'); await wait(); - expect(window.location).toBeAt('/orglist'); + expect(window.location.pathname).toBe('/orglist'); expect( screen.getByText( 'An open source application by Palisadoes Foundation volunteers', @@ -93,7 +92,7 @@ describe('Testing the App Component', () => { ).toBeTruthy(); }); - test('Component should be rendered properly and user is loggedout', async () => { + it('Component should be rendered properly and user is logged out', async () => { render( diff --git a/src/App.tsx b/src/App.tsx index 4d2ca76010..f78778bb1a 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -30,7 +30,7 @@ import CommunityProfile from 'screens/CommunityProfile/CommunityProfile'; import OrganizationVenues from 'screens/OrganizationVenues/OrganizationVenues'; import Leaderboard from 'screens/Leaderboard/Leaderboard'; -import React, { useEffect } from 'react'; +import React from 'react'; // User Portal Components import Donate from 'screens/UserPortal/Donate/Donate'; import Events from 'screens/UserPortal/Events/Events'; @@ -39,20 +39,15 @@ import Organizations from 'screens/UserPortal/Organizations/Organizations'; import People from 'screens/UserPortal/People/People'; import Settings from 'screens/UserPortal/Settings/Settings'; import Chat from 'screens/UserPortal/Chat/Chat'; -import { useQuery } from '@apollo/client'; -import { CHECK_AUTH } from 'GraphQl/Queries/Queries'; import Advertisements from 'components/Advertisements/Advertisements'; import SecuredRouteForUser from 'components/UserPortal/SecuredRouteForUser/SecuredRouteForUser'; - -import useLocalStorage from 'utils/useLocalstorage'; import UserScreen from 'screens/UserPortal/UserScreen/UserScreen'; import EventDashboardScreen from 'components/EventDashboardScreen/EventDashboardScreen'; import Campaigns from 'screens/UserPortal/Campaigns/Campaigns'; import Pledges from 'screens/UserPortal/Pledges/Pledges'; import VolunteerManagement from 'screens/UserPortal/Volunteer/VolunteerManagement'; -import LeaveOrganization from 'screens/UserPortal/LeaveOrganization/LeaveOrganization'; -const { setItem } = useLocalStorage(); +// const { setItem } = useLocalStorage(); /** * This is the main function for our application. It sets up all the routes and components, @@ -97,20 +92,20 @@ function app(): JSX.Element { // TODO: Fetch Installed plugin extras and store for use within MainContent and Side Panel Components. - const { data, loading } = useQuery(CHECK_AUTH); + // const { data, loading } = useQuery(CHECK_AUTH); - useEffect(() => { - if (data) { - setItem('name', `${data.checkAuth.firstName} ${data.checkAuth.lastName}`); - setItem('id', data.checkAuth._id); - setItem('email', data.checkAuth.email); - setItem('IsLoggedIn', 'TRUE'); - setItem('FirstName', data.checkAuth.firstName); - setItem('LastName', data.checkAuth.lastName); - setItem('UserImage', data.checkAuth.image); - setItem('Email', data.checkAuth.email); - } - }, [data, loading]); + // useEffect(() => { + // if (data) { + // setItem('name', `${data.checkAuth.firstName} ${data.checkAuth.lastName}`); + // setItem('id', data.checkAuth._id); + // setItem('email', data.checkAuth.email); + // setItem('IsLoggedIn', 'TRUE'); + // setItem('FirstName', data.checkAuth.firstName); + // setItem('LastName', data.checkAuth.lastName); + // setItem('UserImage', data.checkAuth.image); + // setItem('Email', data.checkAuth.email); + // } + // }, [data, loading]); const extraRoutes = Object.entries(installedPlugins).map( ( @@ -190,19 +185,16 @@ function app(): JSX.Element { }> } /> } /> - } /> + {/* } /> */} }> } /> } /> } /> } /> } /> + } /> } /> } /> - } - /> } @@ -215,7 +207,6 @@ function app(): JSX.Element { - {/* */} } /> diff --git a/src/GraphQl/Mutations/OrganizationMutations.ts b/src/GraphQl/Mutations/OrganizationMutations.ts index 68a0c9026c..152668ab1e 100644 --- a/src/GraphQl/Mutations/OrganizationMutations.ts +++ b/src/GraphQl/Mutations/OrganizationMutations.ts @@ -63,6 +63,7 @@ export const CREATE_CHAT = gql` $organizationId: ID $isGroup: Boolean! $name: String + $image: String ) { createChat( data: { @@ -70,6 +71,7 @@ export const CREATE_CHAT = gql` organizationId: $organizationId isGroup: $isGroup name: $name + image: $image } ) { _id @@ -77,20 +79,67 @@ export const CREATE_CHAT = gql` } `; +export const ADD_USER_TO_GROUP_CHAT = gql` + mutation addUserToGroupChat($userId: ID!, $chatId: ID!) { + addUserToGroupChat(userId: $userId, chatId: $chatId) { + _id + } + } +`; + +export const MARK_CHAT_MESSAGES_AS_READ = gql` + mutation markChatMessagesAsRead($chatId: ID!, $userId: ID!) { + markChatMessagesAsRead(chatId: $chatId, userId: $userId) { + _id + } + } +`; + +export const UPDATE_CHAT = gql` + mutation updateChat($input: UpdateChatInput!) { + updateChat(input: $input) { + _id + } + } +`; + +export const EDIT_CHAT_MESSAGE = gql` + mutation updateChatMessage( + $messageId: ID! + $messageContent: String! + $chatId: ID! + ) { + updateChatMessage( + input: { + messageId: $messageId + messageContent: $messageContent + chatId: $chatId + } + ) { + _id + messageContent + updatedAt + } + } +`; + export const SEND_MESSAGE_TO_CHAT = gql` mutation sendMessageToChat( $chatId: ID! $replyTo: ID - $messageContent: String! + $media: String + $messageContent: String ) { sendMessageToChat( chatId: $chatId replyTo: $replyTo messageContent: $messageContent + media: $media ) { _id createdAt messageContent + media replyTo { _id createdAt diff --git a/src/GraphQl/Mutations/mutations.ts b/src/GraphQl/Mutations/mutations.ts index 628328987e..79b8c1cfd1 100644 --- a/src/GraphQl/Mutations/mutations.ts +++ b/src/GraphQl/Mutations/mutations.ts @@ -283,6 +283,7 @@ export const CREATE_EVENT_MUTATION = gql` $count: PositiveInt $interval: PositiveInt $weekDayOccurenceInMonth: Int + $createChat: Boolean! ) { createEvent( data: { @@ -298,6 +299,7 @@ export const CREATE_EVENT_MUTATION = gql` startTime: $startTime endTime: $endTime location: $location + createChat: $createChat } recurrenceRuleData: { recurrenceStartDate: $recurrenceStartDate diff --git a/src/GraphQl/Queries/PlugInQueries.ts b/src/GraphQl/Queries/PlugInQueries.ts index 508da522e9..346fb712f3 100644 --- a/src/GraphQl/Queries/PlugInQueries.ts +++ b/src/GraphQl/Queries/PlugInQueries.ts @@ -167,6 +167,7 @@ export const CHAT_BY_ID = gql` _id createdAt messageContent + media replyTo { _id createdAt @@ -192,18 +193,73 @@ export const CHAT_BY_ID = gql` firstName lastName email + image + } + admins { + _id + firstName + lastName + email + image } + unseenMessagesByUsers } } `; -export const CHATS_LIST = gql` - query ChatsByUserId($id: ID!) { - chatsByUserId(id: $id) { +export const GROUP_CHAT_LIST = gql` + query groupChatsByUserId { + getGroupChatsByUserId { _id isGroup name + creator { + _id + firstName + lastName + email + } + messages { + _id + createdAt + messageContent + media + sender { + _id + firstName + lastName + email + } + } + organization { + _id + name + } + users { + _id + firstName + lastName + email + image + } + admins { + _id + firstName + lastName + email + image + } + unseenMessagesByUsers + } + } +`; +export const UNREAD_CHAT_LIST = gql` + query unreadChatList { + getUnreadChatsByUserId { + _id + isGroup + name creator { _id firstName @@ -214,6 +270,7 @@ export const CHATS_LIST = gql` _id createdAt messageContent + media sender { _id firstName @@ -232,10 +289,73 @@ export const CHATS_LIST = gql` email image } + admins { + _id + firstName + lastName + email + image + } + unseenMessagesByUsers } } `; +export const CHATS_LIST = gql` + query ChatsByUserId($id: ID!, $searchString: String) { + chatsByUserId( + id: $id + where: { + name_contains: $searchString + user: { + firstName_contains: $searchString + lastName_contains: $searchString + } + } + ) { + _id + isGroup + name + image + creator { + _id + firstName + lastName + email + } + messages { + _id + createdAt + messageContent + sender { + _id + firstName + lastName + email + } + } + organization { + _id + name + } + users { + _id + firstName + lastName + email + image + } + admins { + _id + firstName + lastName + email + image + } + unseenMessagesByUsers + } + } +`; /** * GraphQL query to check if an organization is a sample organization. * diff --git a/src/components/GroupChatDetails/GroupChatDetails.module.css b/src/components/GroupChatDetails/GroupChatDetails.module.css new file mode 100644 index 0000000000..61119875f0 --- /dev/null +++ b/src/components/GroupChatDetails/GroupChatDetails.module.css @@ -0,0 +1,94 @@ +.groupInfo { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; +} + +.memberList { + max-height: 300px; + overflow: scroll; +} + +.memberList::-webkit-scrollbar { + display: none; +} + +.listItem { + display: flex; + align-items: center; + gap: 10px; +} + +.groupMembersList { + display: flex; + align-items: center; + justify-content: space-between; +} + +.groupMembersList p { + margin: 0; + color: #959595; +} + +.membersImage { + width: 40px !important; +} + +.groupImage { + margin-bottom: 10px; +} + +.editImgBtn { + padding: 2px 6px 6px 8px; + border-radius: 100%; + background-color: white; + border: 1px solid #959595; + color: #959595; + outline: none; + position: relative; + top: -40px; + left: 40px; +} + +.chatImage { + height: 120px; + border-radius: 100%; + width: 120px; +} + +.editChatNameContainer { + display: flex; + gap: 15px; + align-items: center; + font-size: 20px; + margin-bottom: 10px; +} + +.editChatNameContainer input { + border: none; + border-bottom: 1px solid rgb(171, 171, 171); + outline: none; + padding: 0px 5px; +} + +.editChatNameContainer h3 { + margin: 0; +} + +.cancelIcon { + color: rgb(197, 42, 42); + cursor: pointer; + font-size: 16px; +} + +.checkIcon { + color: rgb(42, 197, 42); + cursor: pointer; +} + +.chatUserDetails { + display: flex; + gap: 10px; + align-items: center; +} diff --git a/src/components/GroupChatDetails/GroupChatDetails.test.tsx b/src/components/GroupChatDetails/GroupChatDetails.test.tsx new file mode 100644 index 0000000000..4a4aa73b61 --- /dev/null +++ b/src/components/GroupChatDetails/GroupChatDetails.test.tsx @@ -0,0 +1,603 @@ +import React from 'react'; +import { + render, + screen, + // fireEvent, + // waitFor, + act, + fireEvent, + waitFor, +} from '@testing-library/react'; +import GroupChatDetails from './GroupChatDetails'; +import { MockedProvider } from '@apollo/client/testing'; +import { + ADD_USER_TO_GROUP_CHAT, + UPDATE_CHAT, +} from 'GraphQl/Mutations/OrganizationMutations'; +import { USERS_CONNECTION_LIST } from 'GraphQl/Queries/Queries'; +import { I18nextProvider, initReactI18next } from 'react-i18next'; +import i18n from 'i18next'; +import { useLocalStorage } from 'utils/useLocalstorage'; + +const { setItem } = useLocalStorage(); + +async function wait(ms = 100): Promise { + await act(() => { + return new Promise((resolve) => { + setTimeout(resolve, ms); + }); + }); +} + +i18n.use(initReactI18next).init({ + lng: 'en', + resources: { + en: { + translation: { + // Add your translations here + }, + }, + }, +}); + +const mockChat = { + _id: '1', + isGroup: true, + name: 'Test Group', + image: '', + messages: [], + admins: [ + { + _id: 'hbjguyt7y9890i9otyugttiyuh', + firstName: 'Admin', + lastName: 'User', + email: 'admin@example.com', + }, + ], + users: [ + { + _id: 'hbjguyt7y9890i9otyugttiyuh', + firstName: 'Admin', + lastName: 'User', + email: 'admin@example.com', + }, + { + _id: 'gjhnbbjku68979089ujhvserty', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + }, + ], + unseenMessagesByUsers: JSON.parse( + '{"hbjguyt7y9890i9otyugttiyuh": 0, "gjhnbbjku68979089ujhvserty": 0}', + ), + description: 'Test Description', +}; + +const mocks = [ + { + 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', + }, + ], + }, + }, + }, + { + request: { + query: ADD_USER_TO_GROUP_CHAT, + variables: { userId: '6589389d2caa9d8d69087487', chatId: '1' }, + }, + result: { + data: { + addUserToGroupChat: { + _id: '1', + success: true, + }, + }, + }, + }, + { + request: { + query: UPDATE_CHAT, + variables: { input: { _id: '1', image: '', name: 'New Group name' } }, + }, + result: { + data: { + updateChat: { + _id: '1', + success: true, + }, + }, + }, + }, + { + request: { + query: UPDATE_CHAT, + variables: {}, + }, + result: { + data: { + updateChat: { + _id: '1', + success: true, + }, + }, + }, + }, +]; + +describe('GroupChatDetails', () => { + it('renders correctly', async () => { + const chat = { + _id: '1', + isGroup: true, + name: 'Test Group', + image: '', + messages: [], + admins: [], + users: [], + unseenMessagesByUsers: JSON.parse( + '{"hbjguyt7y9890i9otyugttiyuh": 0, "gjhnbbjku68979089ujhvserty": 0}', + ), + description: 'Test Description', + }; + render( + + + + + , + ); + + await wait(); + + expect(screen.getByText('Test Group')).toBeInTheDocument(); + expect(screen.getByText('Test Description')).toBeInTheDocument(); + const closeButton = screen.getByRole('button', { name: /close/i }); + expect(closeButton).toBeInTheDocument(); + + fireEvent.click(closeButton); + }); + + it('edit chat title', async () => { + render( + + + + + , + ); + + await wait(); + await act(async () => { + fireEvent.click(await screen.findByTestId('editTitleBtn')); + }); + + await waitFor(async () => { + expect(await screen.findByTestId('chatNameInput')).toBeInTheDocument(); + }); + await act(async () => { + fireEvent.change(await screen.findByTestId('chatNameInput'), { + target: { value: 'New Group name' }, + }); + }); + + await act(async () => { + fireEvent.click(await screen.findByTestId('updateTitleBtn')); + }); + + await wait(); + + await waitFor( + async () => { + expect(await screen.findByTestId('editTitleBtn')).toBeInTheDocument(); + }, + { timeout: 5000 }, + ); + + await act(async () => { + fireEvent.click(await screen.findByTestId('editTitleBtn')); + }); + + await waitFor(async () => { + expect(await screen.findByTestId('cancelEditBtn')).toBeInTheDocument(); + }); + + act(() => { + fireEvent.click(screen.getByTestId('cancelEditBtn')); + }); + + await waitFor( + async () => { + expect(await screen.findByTestId('editTitleBtn')).toBeInTheDocument(); + }, + { timeout: 5000 }, + ); + }); + + it('add user to group chat', async () => { + setItem('userId', 'hbjguyt7y9890i9otyugttiyuh'); + render( + + + + + , + ); + + await wait(); + await act(async () => { + fireEvent.click(await screen.findByTestId('addMembers')); + }); + + await waitFor(async () => { + expect(await screen.findByTestId('searchUser')).toBeInTheDocument(); + }); + + await act(async () => { + fireEvent.change(await screen.findByTestId('searchUser'), { + target: { value: 'Disha' }, + }); + }); + + await act(async () => { + fireEvent.click(await screen.findByTestId('searchBtn')); + }); + + await wait(); + + await waitFor( + async () => { + expect(await screen.findByTestId('user')).toBeInTheDocument(); + }, + { timeout: 5000 }, + ); + + await act(async () => { + fireEvent.click(await screen.findByTestId('addUserBtn')); + }); + + await wait(10000); + }); + // test case for updating group chat image + it('update group chat image', async () => { + render( + + + + + , + ); + + await wait(); + + await waitFor( + async () => { + expect(await screen.findByTestId('editImageBtn')).toBeInTheDocument(); + }, + { timeout: 5000 }, + ); + + await act(async () => { + fireEvent.click(await screen.findByTestId('editImageBtn')); + }); + + const fileInput = screen.getByTestId('fileInput'); + const smallFile = new File(['small-file-content'], 'small-file.jpg'); // Small file + + Object.defineProperty(fileInput, 'files', { + value: [smallFile], + }); + + fireEvent.change(fileInput); + + await wait(10000); + }); +}); diff --git a/src/components/GroupChatDetails/GroupChatDetails.tsx b/src/components/GroupChatDetails/GroupChatDetails.tsx new file mode 100644 index 0000000000..e252a286be --- /dev/null +++ b/src/components/GroupChatDetails/GroupChatDetails.tsx @@ -0,0 +1,442 @@ +import { Paper, TableBody } from '@mui/material'; +import React, { useRef, useState } from 'react'; +import { Button, Form, ListGroup, Modal } from 'react-bootstrap'; +import styles from './GroupChatDetails.module.css'; +import type { ApolloQueryResult } from '@apollo/client'; +import { useMutation, useQuery } from '@apollo/client'; +import { + ADD_USER_TO_GROUP_CHAT, + UPDATE_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, Add } from '@mui/icons-material'; +import { useTranslation } from 'react-i18next'; +import Avatar from 'components/Avatar/Avatar'; +import { FiEdit } from 'react-icons/fi'; +import { FaCheck, FaX } from 'react-icons/fa6'; +import convertToBase64 from 'utils/convertToBase64'; +import useLocalStorage from 'utils/useLocalstorage'; + +type DirectMessage = { + _id: string; + createdAt: Date; + sender: { + _id: string; + firstName: string; + lastName: string; + image: string; + }; + replyTo: + | { + _id: string; + createdAt: Date; + sender: { + _id: string; + firstName: string; + lastName: string; + image: string; + }; + messageContent: string; + receiver: { + _id: string; + firstName: string; + lastName: string; + }; + } + | undefined; + messageContent: string; + media: string; +}; + +type Chat = { + _id: string; + isGroup: boolean; + name?: string; + image?: string; + messages: DirectMessage[]; + admins: { + _id: string; + firstName: string; + lastName: string; + email: string; + }[]; + users: { + _id: string; + firstName: string; + lastName: string; + email: string; + }[]; + unseenMessagesByUsers: string; + description: string; +}; + +interface InterfaceGoroupChatDetailsProps { + toggleGroupChatDetailsModal: () => void; + groupChatDetailsModalisOpen: boolean; + chat: Chat; + chatRefetch: ( + variables?: + | Partial<{ + id: string; + }> + | undefined, + ) => Promise>; +} + +const StyledTableCell = styled(TableCell)(({ theme }) => ({ + [`&.${tableCellClasses.head}`]: { + backgroundColor: ['#31bb6b', '!important'], + color: theme.palette.common.white, + }, + [`&.${tableCellClasses.body}`]: { + fontSize: 14, + }, +})); + +const StyledTableRow = styled(TableRow)(() => ({ + '&:last-child td, &:last-child th': { + border: 0, + }, +})); + +/** + * Component for displaying and managing group chat details. + * + * @param props - The component props. + * @param toggleGroupChatDetailsModal - Function to toggle the group chat details modal. + * @param groupChatDetailsModalisOpen - Boolean indicating if the group chat details modal is open. + * @param chat - The chat object containing details about the group chat. + * @param chatRefetch - Function to refetch the chat data. + * @returns The rendered component. + */ +export default function groupChatDetails({ + toggleGroupChatDetailsModal, + groupChatDetailsModalisOpen, + chat, + chatRefetch, +}: InterfaceGoroupChatDetailsProps): JSX.Element { + const { t } = useTranslation('translation', { + keyPrefix: 'userChat', + }); + + const [userName, setUserName] = useState(''); + const { getItem } = useLocalStorage(); + + const userId = getItem('userId'); + + const [editChatTitle, setEditChatTitle] = useState(false); + const [chatName, setChatName] = useState(chat?.name || ''); + + const [addUser] = useMutation(ADD_USER_TO_GROUP_CHAT); + + const [addUserModalisOpen, setAddUserModalisOpen] = useState(false); + + function openAddUserModal(): void { + setAddUserModalisOpen(true); + } + + const toggleAddUserModal = (): void => + setAddUserModalisOpen(!addUserModalisOpen); + + const { + data: allUsersData, + loading: allUsersLoading, + refetch: allUsersRefetch, + } = useQuery(USERS_CONNECTION_LIST, { + variables: { + firstName_contains: '', + lastName_contains: '', + }, + }); + + const addUserToGroupChat = async (userId: string): Promise => { + await addUser({ + variables: { + userId, + chatId: chat._id, + }, + }); + }; + + 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, + }); + }; + + const [selectedImage, setSelectedImage] = useState(''); + + const [updateChat] = useMutation(UPDATE_CHAT); + + const fileInputRef = useRef(null); + + const handleImageClick = (): void => { + fileInputRef?.current?.click(); + }; + + const handleImageChange = async ( + e: React.ChangeEvent, + ): Promise => { + const file = e.target.files?.[0]; + if (file) { + const base64 = await convertToBase64(file); + setSelectedImage(base64); + await updateChat(); + await chatRefetch(); + setSelectedImage(''); + } + }; + + return ( + <> + + + {t('groupInfo')} + + + +
+ {chat?.image ? ( + + ) : ( + + )} + + + {editChatTitle ? ( +
+ { + setChatName(e.target.value); + }} + /> + { + await updateChat({ + variables: { + input: { + _id: chat._id, + image: selectedImage ? selectedImage : '', + name: chatName, + }, + }, + }); + setEditChatTitle(false); + await chatRefetch(); + }} + /> + { + setEditChatTitle(false); + setChatName(chat.name || ''); + }} + /> +
+ ) : ( +
+

{chat?.name}

+ { + setEditChatTitle(true); + }} + /> +
+ )} + +

+ {chat?.users.length} {t('members')} +

+

{chat?.description}

+
+ +
+
+ {chat.users.length} {t('members')} +
+ + {chat.admins.map((admin) => admin._id).includes(userId) && ( + { + openAddUserModal(); + }} + > + {t('addMembers')} + + )} + {chat.users.map( + (user: { + _id: string; + firstName: string; + lastName: string; + }) => ( + +
+ + {user.firstName} {user.lastName} +
+ +
+ {chat.admins + .map((admin) => admin._id) + .includes(user._id) && ( +

Admin

+ )} +
+
+ ), + )} +
+
+
+
+ + + {'Chat'} + + + {allUsersLoading ? ( + <> + + + ) : ( + <> +
+
+ { + const { value } = e.target; + setUserName(value); + }} + /> + + +
+ + + + + + # + {'user'} + {'Chat'} + + + + {console.log(allUsersData)} + {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/LoginPortalToggle/LoginPortalToggle.module.css b/src/components/LoginPortalToggle/LoginPortalToggle.module.css index 227f65aa9a..db51554389 100644 --- a/src/components/LoginPortalToggle/LoginPortalToggle.module.css +++ b/src/components/LoginPortalToggle/LoginPortalToggle.module.css @@ -22,13 +22,13 @@ } .activeLink { - color: var(--bs-white); + color: white; border: 1px solid var(--bs-primary); - background-color: var(--active-button-bg); + background-color: var(--toggle-button-bg); } .activeLink:hover { color: var(--bs-white); - background-color: var(--active-hover); + background-color: var(--toggle-button-bg); border: 1px solid var(--bs-primary); } diff --git a/src/components/UserPortal/ChatRoom/ChatRoom.module.css b/src/components/UserPortal/ChatRoom/ChatRoom.module.css index 5fc98351cd..5f89e6122a 100644 --- a/src/components/UserPortal/ChatRoom/ChatRoom.module.css +++ b/src/components/UserPortal/ChatRoom/ChatRoom.module.css @@ -4,8 +4,9 @@ /* background-color: rgba(196, 255, 211, 0.3); */ } -.backgroundWhite { +.sendMessageInput { background-color: white; + border-radius: 12px 0px 0px 12px; } .grey { @@ -152,7 +153,8 @@ } .contactImage { - height: fit-content; + height: 45px !important; + border-radius: 100%; } .senderInfo { @@ -235,6 +237,38 @@ animation-duration: 1s; } +.attachment { + padding: 10px; + background-color: rgb(219, 219, 219); + height: 200px; + display: flex; + align-items: flex-start; + border-radius: 10px; +} + +.attachment img { + height: 100%; + width: 100%; + object-fit: cover; + border-radius: 8px; +} + +.messageAttachment { + height: 300px; + width: 300px; + border-radius: 10px; + object-fit: cover; + margin: 10px 0px 10px 10px; +} + +.addAttachmentBtn { + border: none; + outline: none; + margin: 0 10px; + background-color: white; + font-size: 20px; +} + @keyframes test { from { background-color: white; diff --git a/src/components/UserPortal/ChatRoom/ChatRoom.spec.tsx b/src/components/UserPortal/ChatRoom/ChatRoom.spec.tsx index fef1b67fa5..ef88baaf4c 100644 --- a/src/components/UserPortal/ChatRoom/ChatRoom.spec.tsx +++ b/src/components/UserPortal/ChatRoom/ChatRoom.spec.tsx @@ -7,21 +7,27 @@ import { fireEvent, waitFor, } from '@testing-library/react'; -import { MockSubscriptionLink, MockedProvider } from '@apollo/react-testing'; +import { MockedProvider, MockSubscriptionLink } from '@apollo/react-testing'; import { I18nextProvider } from 'react-i18next'; import { BrowserRouter } from 'react-router-dom'; import { Provider } from 'react-redux'; import { store } from 'state/store'; import i18nForTest from 'utils/i18nForTest'; -import { CHATS_LIST, CHAT_BY_ID } from 'GraphQl/Queries/PlugInQueries'; import { + CHATS_LIST, + CHAT_BY_ID, + GROUP_CHAT_LIST, + UNREAD_CHAT_LIST, +} from 'GraphQl/Queries/PlugInQueries'; +import { + MARK_CHAT_MESSAGES_AS_READ, MESSAGE_SENT_TO_CHAT, SEND_MESSAGE_TO_CHAT, } from 'GraphQl/Mutations/OrganizationMutations'; import ChatRoom from './ChatRoom'; -import { useLocalStorage } from 'utils/useLocalstorage'; import { StaticMockLink } from 'utils/StaticMockLink'; import { vi } from 'vitest'; +import useLocalStorage from 'utils/useLocalstorage'; /** * Unit tests for the ChatRoom component @@ -58,6 +64,7 @@ const MESSAGE_SENT_TO_CHAT_MOCK = [ _id: '1', }, messageContent: 'Test ', + media: null, replyTo: null, sender: { _id: '64378abd85008f171cf2990d', @@ -83,6 +90,36 @@ const MESSAGE_SENT_TO_CHAT_MOCK = [ _id: '668ec1f1df364e03ac47a151', createdAt: '2024-07-10T17:16:33.248Z', messageContent: 'Test ', + media: null, + chatMessageBelongsTo: { + _id: '1', + }, + replyTo: null, + sender: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: '', + }, + updatedAt: '2024-07-10', + }, + }, + }, + }, + { + request: { + query: MESSAGE_SENT_TO_CHAT, + variables: { + userId: '8', + }, + }, + result: { + data: { + messageSentToChat: { + _id: '668ec1f1df364e03ac47a151', + createdAt: '2024-07-10T17:16:33.248Z', + messageContent: 'Test ', + media: null, chatMessageBelongsTo: { _id: '1', }, @@ -111,6 +148,7 @@ const MESSAGE_SENT_TO_CHAT_MOCK = [ _id: '668ec1f13603ac4697a151', createdAt: '2024-07-10T17:16:33.248Z', messageContent: 'Test ', + media: null, chatMessageBelongsTo: { _id: '1', }, @@ -128,17 +166,15 @@ const MESSAGE_SENT_TO_CHAT_MOCK = [ }, ]; -const CHAT_BY_ID_QUERY_MOCK = [ +const UNREAD_CHAT_LIST_QUERY_MOCK = [ { request: { - query: CHAT_BY_ID, - variables: { - id: '1', - }, + query: UNREAD_CHAT_LIST, + variables: {}, }, result: { data: { - chatById: { + getUnreadChatsByUserId: { _id: '1', createdAt: '2345678903456', isGroup: false, @@ -155,10 +191,12 @@ const CHAT_BY_ID_QUERY_MOCK = [ name: '', messages: [ { - _id: '4', + _id: '345678', createdAt: '345678908765', messageContent: 'Hello', + media: null, replyTo: null, + type: 'STRING', sender: { _id: '2', firstName: 'Test', @@ -184,21 +222,27 @@ const CHAT_BY_ID_QUERY_MOCK = [ image: '', }, ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), }, }, }, }, { request: { - query: CHAT_BY_ID, + query: UNREAD_CHAT_LIST, variables: { - id: '1', + id: '8', }, }, result: { data: { - chatById: { + getUnreadChatsByUserId: { _id: '1', + createdAt: '2345678903456', isGroup: false, creator: { _id: '64378abd85008f171cf2990d', @@ -211,13 +255,14 @@ const CHAT_BY_ID_QUERY_MOCK = [ }, organization: null, name: '', - createdAt: '2345678903456', messages: [ { - _id: '4', + _id: '345678', createdAt: '345678908765', messageContent: 'Hello', + media: null, replyTo: null, + type: 'STRING', sender: { _id: '2', firstName: 'Test', @@ -243,21 +288,27 @@ const CHAT_BY_ID_QUERY_MOCK = [ image: '', }, ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), }, }, }, }, { request: { - query: CHAT_BY_ID, + query: UNREAD_CHAT_LIST, variables: { - id: '', + id: '8', }, }, result: { data: { - chatById: { + getUnreadChatsByUserId: { _id: '1', + createdAt: '2345678903456', isGroup: false, creator: { _id: '64378abd85008f171cf2990d', @@ -270,13 +321,14 @@ const CHAT_BY_ID_QUERY_MOCK = [ }, organization: null, name: '', - createdAt: '2345678903456', messages: [ { - _id: '4', + _id: '345678', createdAt: '345678908765', messageContent: 'Hello', + media: null, replyTo: null, + type: 'STRING', sender: { _id: '2', firstName: 'Test', @@ -302,894 +354,5309 @@ const CHAT_BY_ID_QUERY_MOCK = [ image: '', }, ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), }, }, }, }, -]; - -const CHATS_LIST_MOCK = [ { request: { - query: CHATS_LIST, - variables: { - id: null, - }, + query: UNREAD_CHAT_LIST, + variables: {}, }, 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, - sender: { - _id: '2', - firstName: 'Test', - lastName: 'User', - email: 'test@example.com', - image: '', - }, - }, - ], - users: [ - { - _id: '1', - firstName: 'Disha', - lastName: 'Talreja', - email: 'disha@example.com', - image: '', - }, - { + getUnreadChatsByUserId: { + _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', + media: null, + replyTo: null, + type: 'STRING', + sender: { _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', + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', }, - createdAt: '2345678903456', - name: 'Test Group Chat', - messages: [ - { - _id: '345678', - createdAt: '345678908765', - messageContent: 'Hello', - replyTo: null, - 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: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, }, }, }, { request: { - query: CHATS_LIST, - variables: { - id: '', - }, + query: UNREAD_CHAT_LIST, + variables: {}, }, 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, - sender: { - _id: '2', - firstName: 'Test', - lastName: 'User', - email: 'test@example.com', - image: '', - }, - }, - ], - users: [ - { - _id: '1', - firstName: 'Disha', - lastName: 'Talreja', - email: 'disha@example.com', - image: '', - }, - { + getUnreadChatsByUserId: { + _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', + media: null, + replyTo: null, + type: 'STRING', + sender: { _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', + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', }, - createdAt: '2345678903456', - name: 'Test Group Chat', - messages: [ - { - _id: '345678', - createdAt: '345678908765', - messageContent: 'Hello', - replyTo: null, - 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getUnreadChatsByUserId: { + _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', + media: null, + replyTo: null, + type: 'STRING', + sender: { _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: '', - }, - ], - }, - ], + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, }, }, }, { request: { - query: CHATS_LIST, + query: UNREAD_CHAT_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, - sender: { - _id: '2', - firstName: 'Test', - lastName: 'User', - email: 'test@example.com', - image: '', - }, - }, - ], - users: [ - { - _id: '1', - firstName: 'Disha', - lastName: 'Talreja', - email: 'disha@example.com', - image: '', - }, - { + getUnreadChatsByUserId: { + _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', + media: null, + replyTo: null, + type: 'STRING', + sender: { _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', + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', }, - createdAt: '2345678903456', - name: 'Test Group Chat', - messages: [ - { - _id: '345678', - createdAt: '345678908765', - messageContent: 'Hello', - replyTo: null, - 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: { + id: '1', + }, + }, + result: { + data: { + getUnreadChatsByUserId: { + _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', + media: null, + replyTo: null, + type: 'STRING', + sender: { _id: '2', firstName: 'Test', lastName: 'User', email: 'test@example.com', image: '', }, - { - _id: '3', - firstName: 'Test', - lastName: 'User1', - email: 'test1@example.com', - image: '', - }, - { - _id: '4', + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: { + id: '1', + }, + }, + result: { + data: { + getUnreadChatsByUserId: { + _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', + media: null, + replyTo: null, + type: 'STRING', + sender: { + _id: '2', firstName: 'Test', - lastName: 'User2', - email: 'test2@example.com', + lastName: 'User', + email: 'test@example.com', image: '', }, - { - _id: '5', + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + getUnreadChatsByUserId: { + _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', + media: null, + replyTo: null, + type: 'STRING', + sender: { + _id: '2', firstName: 'Test', - lastName: 'User4', - email: 'test4@example.com', + 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + getUnreadChatsByUserId: { + _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', + media: null, + 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: { + id: '8', + }, + }, + result: { + data: { + getUnreadChatsByUserId: { + _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', + media: null, + 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: { + id: '8', + }, + }, + result: { + data: { + getUnreadChatsByUserId: { + _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', + media: null, + 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: { + id: '8', + }, + }, + result: { + data: { + getUnreadChatsByUserId: { + _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', + media: null, + 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + }, + }, + }, +]; + +const GROUP_CHAT_LIST_QUERY_MOCK = [ + { + request: { + query: GROUP_CHAT_LIST, + variables: { + id: '', + }, + }, + result: { + data: { + getGroupChatsByUserId: { + _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', + media: null, + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, + { + request: { + query: GROUP_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getGroupChatsByUserId: { + _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', + media: null, + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, + { + request: { + query: GROUP_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getGroupChatsByUserId: { + _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', + media: null, + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, + { + request: { + query: GROUP_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getGroupChatsByUserId: { + _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', + media: null, + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, + { + request: { + query: GROUP_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getGroupChatsByUserId: { + _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', + media: null, + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, + { + request: { + query: GROUP_CHAT_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + getGroupChatsByUserId: { + _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', + media: null, + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, + { + request: { + query: GROUP_CHAT_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + getGroupChatsByUserId: { + _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', + media: null, + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, + { + request: { + query: GROUP_CHAT_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + getGroupChatsByUserId: { + _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', + media: null, + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, +]; + +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: '4', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + }, + }, + }, + }, + }, + { + 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: '4', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + }, + }, + }, + }, + }, + { + 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: '4', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + }, + }, + }, + }, + }, +]; + +const CHATS_LIST_MOCK = [ + { + request: { + query: CHATS_LIST, + variables: { + id: '8', + }, + }, + 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', + media: null, + replyTo: null, + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }, + }, + { + _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', + media: null, + replyTo: null, + 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: '', + }, + ], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }, + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: '8', + }, + }, + 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', + media: null, + replyTo: null, + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }, + }, + { + _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', + media: null, + replyTo: null, + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }, + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: '8', + }, + }, + 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', + media: null, + replyTo: null, + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }, + }, + { + _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', + media: null, + replyTo: null, + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }, + }, + ], + }, + }, + }, + { + 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', + media: null, + replyTo: null, + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }, + }, + { + _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', + media: null, + replyTo: null, + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }, + }, + ], + }, + }, + }, + { + 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', + media: null, + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }, + }, + { + _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', + media: null, + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }, + }, + ], + }, + }, + }, + { + 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', + media: null, + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }, + }, + { + _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', + media: null, + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }, + }, + ], + }, + }, + }, + { + 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', + media: null, + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }, + }, + { + _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', + media: null, + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }, + }, + ], + }, + }, + }, + { + 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', + media: null, + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }, + }, + { + _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', + media: null, + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }, + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: '2', + }, + }, + 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', + media: null, + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }), + }, + { + _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', + media: null, + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }), + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: '2', + }, + }, + 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', + media: null, + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }, + }, + { + _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', + media: null, + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }, + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: '2', + }, + }, + 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', + media: null, + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }, + }, + { + _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', + media: null, + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }, + }, + ], + }, + }, + }, + { + 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', + media: null, + replyTo: null, + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }, + }, + { + _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', + media: null, + replyTo: null, + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }, + }, + ], + }, + }, + }, + { + 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', + media: null, + replyTo: null, + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: { + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }, + }, + { + _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', + media: null, + replyTo: null, + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }), + }, + ], + }, + }, + }, +]; + +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: '2', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }), + }, + }, + }, + }, + { + request: { + query: CHAT_BY_ID, + variables: { + id: '1', + }, + }, + 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', + media: null, + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }), + }, + }, + }, + }, + { + request: { + query: CHAT_BY_ID, + variables: { + id: '1', + }, + }, + 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', + media: null, + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + }), + }, + }, + }, + }, + { + request: { + query: CHAT_BY_ID, + variables: { + id: '1', + }, + }, + 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: '1', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + replyTo: null, + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + }, + }, + }, + }, + { + request: { + query: CHAT_BY_ID, + variables: { + id: '1', + }, + }, + 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: '1', + createdAt: '345678908765', + messageContent: 'Hello', + media: '', + replyTo: null, + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + }, + }, + }, + }, +]; + +const SEND_MESSAGE_TO_CHAT_MOCK = [ + { + request: { + query: SEND_MESSAGE_TO_CHAT, + variables: { + chatId: '1', + replyTo: '4', + messageContent: 'Test reply message', + media: 'https://test.com/image.jpg', + }, + }, + result: { + data: { + sendMessageToChat: { + _id: '668ec1f1364e03ac47a151', + createdAt: '2024-07-10T17:16:33.248Z', + messageContent: 'Test ', + media: null, + replyTo: null, + sender: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: '', + }, + updatedAt: '2024-07-10', + }, + }, + }, + }, + { + request: { + query: SEND_MESSAGE_TO_CHAT, + variables: { + chatId: '1', + replyTo: '4', + messageContent: 'Test reply message', + media: '', + }, + }, + result: { + data: { + sendMessageToChat: { + _id: '668ec1f1364e03ac47a151', + createdAt: '2024-07-10T17:16:33.248Z', + messageContent: 'Test ', + media: '', + replyTo: null, + sender: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: '', + }, + updatedAt: '2024-07-10', + }, + }, + }, + }, + { + request: { + query: SEND_MESSAGE_TO_CHAT, + variables: { + chatId: '1', + replyTo: '1', + messageContent: 'Test reply message', + }, + }, + result: { + data: { + sendMessageToChat: { + _id: '668ec1f1364e03ac47a151', + createdAt: '2024-07-10T17:16:33.248Z', + messageContent: 'Test ', + media: null, + replyTo: null, + sender: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: '', + }, + updatedAt: '2024-07-10', + }, + }, + }, + }, + { + request: { + query: SEND_MESSAGE_TO_CHAT, + variables: { + chatId: '1', + replyTo: undefined, + messageContent: 'Hello', + media: '', + }, + }, + result: { + data: { + sendMessageToChat: { + _id: '668ec1f1364e03ac47a151', + createdAt: '2024-07-10T17:16:33.248Z', + messageContent: 'Test ', + media: null, + replyTo: null, + sender: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: '', + }, + updatedAt: '2024-07-10', + }, + }, + }, + }, + { + request: { + query: SEND_MESSAGE_TO_CHAT, + variables: { + chatId: '1', + replyTo: '345678', + messageContent: 'Test reply message', + media: '', + }, + }, + result: { + data: { + sendMessageToChat: { + _id: '668ec1f1364e03ac47a151', + createdAt: '2024-07-10T17:16:33.248Z', + messageContent: 'Test ', + media: null, + replyTo: null, + sender: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: '', + }, + updatedAt: '2024-07-10', + }, + }, + }, + }, + { + request: { + query: SEND_MESSAGE_TO_CHAT, + variables: { + chatId: '1', + replyTo: undefined, + messageContent: 'Test message', + media: '', + }, + }, + result: { + data: { + sendMessageToChat: { + _id: '668ec1f1364e03ac47a151', + createdAt: '2024-07-10T17:16:33.248Z', + messageContent: 'Test ', + media: null, + replyTo: null, + sender: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: '', + }, + updatedAt: '2024-07-10', + }, + }, + }, + }, + { + request: { + query: SEND_MESSAGE_TO_CHAT, + variables: { + chatId: '1', + replyTo: undefined, + messageContent: 'Test reply message', + media: '', + }, + }, + result: { + data: { + sendMessageToChat: { + _id: '668ec1f1364e03ac47a151', + createdAt: '2024-07-10T17:16:33.248Z', + messageContent: 'Test ', + media: null, + replyTo: null, + sender: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: '', + }, + updatedAt: '2024-07-10', + }, + }, + }, + }, +]; + +const MARK_CHAT_MESSAGES_AS_READ_MOCK = [ + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: null, + chatId: '1', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: '8', + chatId: '1', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: '8', + chatId: '1', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: '8', + chatId: '1', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: '8', + chatId: '1', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: '8', + chatId: '1', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: '8', + chatId: '1', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: '8', + chatId: '1', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: '8', + chatId: '1', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: '8', + chatId: '1', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, }, }, }, -]; - -const GROUP_CHAT_BY_ID_QUERY_MOCK = [ { request: { - query: CHAT_BY_ID, + query: MARK_CHAT_MESSAGES_AS_READ, variables: { - id: '', + userId: '8', + chatId: '1', }, }, 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: '2', - createdAt: '345678908765', - messageContent: 'Hello', - replyTo: null, - 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: '', - }, - ], + markChatMessagesAsRead: { + _id: '1', }, }, }, }, { request: { - query: CHAT_BY_ID, + query: MARK_CHAT_MESSAGES_AS_READ, variables: { - id: '1', + userId: '8', + chatId: '1', }, }, 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: '1', - createdAt: '345678908765', - messageContent: 'Hello', - replyTo: null, - 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: '', - }, - ], + markChatMessagesAsRead: { + _id: '1', }, }, }, }, { request: { - query: CHAT_BY_ID, + query: MARK_CHAT_MESSAGES_AS_READ, variables: { - id: '1', + userId: '8', + chatId: '1', }, }, 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: '1', - createdAt: '345678908765', - messageContent: 'Hello', - replyTo: null, - 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: '', - }, - ], + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: '8', + chatId: '1', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: null, + chatId: '1', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: null, + chatId: '1', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', }, }, }, }, -]; - -const SEND_MESSAGE_TO_CHAT_MOCK = [ { request: { - query: SEND_MESSAGE_TO_CHAT, + query: MARK_CHAT_MESSAGES_AS_READ, variables: { + userId: null, chatId: '1', - replyTo: '4', - messageContent: 'Test reply message', }, }, result: { data: { - sendMessageToChat: { - _id: '668ec1f1364e03ac47a151', - createdAt: '2024-07-10T17:16:33.248Z', - messageContent: 'Test ', - replyTo: null, - sender: { - _id: '64378abd85008f171cf2990d', - firstName: 'Wilt', - lastName: 'Shepherd', - image: '', - }, - updatedAt: '2024-07-10', + markChatMessagesAsRead: { + _id: '1', }, }, }, }, { request: { - query: SEND_MESSAGE_TO_CHAT, + query: MARK_CHAT_MESSAGES_AS_READ, variables: { - chatId: '1', - replyTo: '4', - messageContent: 'Test reply message', + userId: null, + chatId: '', }, }, result: { data: { - sendMessageToChat: { - _id: '668ec1f1364e03ac47a151', - createdAt: '2024-07-10T17:16:33.248Z', - messageContent: 'Test ', - replyTo: null, - sender: { - _id: '64378abd85008f171cf2990d', - firstName: 'Wilt', - lastName: 'Shepherd', - image: '', - }, - updatedAt: '2024-07-10', + markChatMessagesAsRead: { + _id: '1', }, }, }, }, { request: { - query: SEND_MESSAGE_TO_CHAT, + query: MARK_CHAT_MESSAGES_AS_READ, variables: { + userId: '2', chatId: '1', - replyTo: '1', - messageContent: 'Test reply message', }, }, result: { data: { - sendMessageToChat: { - _id: '668ec1f1364e03ac47a151', - createdAt: '2024-07-10T17:16:33.248Z', - messageContent: 'Test ', - replyTo: null, - sender: { - _id: '64378abd85008f171cf2990d', - firstName: 'Wilt', - lastName: 'Shepherd', - image: '', - }, - updatedAt: '2024-07-10', + markChatMessagesAsRead: { + _id: '1', }, }, }, }, { request: { - query: SEND_MESSAGE_TO_CHAT, + query: MARK_CHAT_MESSAGES_AS_READ, variables: { + userId: '2', chatId: '1', - replyTo: undefined, - messageContent: 'Hello', }, }, result: { data: { - sendMessageToChat: { - _id: '668ec1f1364e03ac47a151', - createdAt: '2024-07-10T17:16:33.248Z', - messageContent: 'Test ', - replyTo: null, - sender: { - _id: '64378abd85008f171cf2990d', - firstName: 'Wilt', - lastName: 'Shepherd', - image: '', - }, - updatedAt: '2024-07-10', + markChatMessagesAsRead: { + _id: '1', }, }, }, }, { request: { - query: SEND_MESSAGE_TO_CHAT, + query: MARK_CHAT_MESSAGES_AS_READ, variables: { + userId: '2', chatId: '1', - replyTo: '345678', - messageContent: 'Test reply message', }, }, result: { data: { - sendMessageToChat: { - _id: '668ec1f1364e03ac47a151', - createdAt: '2024-07-10T17:16:33.248Z', - messageContent: 'Test ', - replyTo: null, - sender: { - _id: '64378abd85008f171cf2990d', - firstName: 'Wilt', - lastName: 'Shepherd', - image: '', - }, - updatedAt: '2024-07-10', + markChatMessagesAsRead: { + _id: '1', }, }, }, }, { request: { - query: SEND_MESSAGE_TO_CHAT, + query: MARK_CHAT_MESSAGES_AS_READ, variables: { - chatId: '1', - replyTo: undefined, - messageContent: 'Test message', + userId: null, + chatId: '', }, }, result: { data: { - sendMessageToChat: { - _id: '668ec1f1364e03ac47a151', - createdAt: '2024-07-10T17:16:33.248Z', - messageContent: 'Test ', - replyTo: null, - sender: { - _id: '64378abd85008f171cf2990d', - firstName: 'Wilt', - lastName: 'Shepherd', - image: '', - }, - updatedAt: '2024-07-10', + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: '1', + chatId: '', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: '1', + chatId: '', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: '1', + chatId: '', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', }, }, }, @@ -1198,20 +5665,28 @@ const SEND_MESSAGE_TO_CHAT_MOCK = [ describe('Testing Chatroom Component [User Portal]', () => { window.HTMLElement.prototype.scrollIntoView = vi.fn(); + beforeEach(() => { + vi.clearAllMocks(); + vi.resetModules(); + }); it('Chat room should display fallback content if no chat is active', async () => { const mocks = [ ...MESSAGE_SENT_TO_CHAT_MOCK, ...CHAT_BY_ID_QUERY_MOCK, ...CHATS_LIST_MOCK, + ...GROUP_CHAT_BY_ID_QUERY_MOCK, ...SEND_MESSAGE_TO_CHAT_MOCK, + ...MARK_CHAT_MESSAGES_AS_READ_MOCK, + ...GROUP_CHAT_LIST_QUERY_MOCK, + ...UNREAD_CHAT_LIST_QUERY_MOCK, ]; render( - + @@ -1227,14 +5702,18 @@ describe('Testing Chatroom Component [User Portal]', () => { ...MESSAGE_SENT_TO_CHAT_MOCK, ...CHAT_BY_ID_QUERY_MOCK, ...CHATS_LIST_MOCK, + ...GROUP_CHAT_BY_ID_QUERY_MOCK, ...SEND_MESSAGE_TO_CHAT_MOCK, + ...MARK_CHAT_MESSAGES_AS_READ_MOCK, + ...GROUP_CHAT_LIST_QUERY_MOCK, + ...UNREAD_CHAT_LIST_QUERY_MOCK, ]; render( - + @@ -1251,6 +5730,9 @@ describe('Testing Chatroom Component [User Portal]', () => { ...CHATS_LIST_MOCK, ...GROUP_CHAT_BY_ID_QUERY_MOCK, ...SEND_MESSAGE_TO_CHAT_MOCK, + ...MARK_CHAT_MESSAGES_AS_READ_MOCK, + ...GROUP_CHAT_LIST_QUERY_MOCK, + ...UNREAD_CHAT_LIST_QUERY_MOCK, ]; const link2 = new StaticMockLink(mocks, true); render( @@ -1258,7 +5740,7 @@ describe('Testing Chatroom Component [User Portal]', () => { - + @@ -1281,9 +5763,6 @@ describe('Testing Chatroom Component [User Portal]', () => { act(() => { fireEvent.click(sendBtn); }); - await waitFor(() => { - expect(input.value).toBeFalsy(); - }); const messages = await screen.findAllByTestId('message'); @@ -1336,6 +5815,9 @@ describe('Testing Chatroom Component [User Portal]', () => { ...CHAT_BY_ID_QUERY_MOCK, ...CHATS_LIST_MOCK, ...SEND_MESSAGE_TO_CHAT_MOCK, + ...MARK_CHAT_MESSAGES_AS_READ_MOCK, + ...GROUP_CHAT_LIST_QUERY_MOCK, + ...UNREAD_CHAT_LIST_QUERY_MOCK, ]; const link2 = new StaticMockLink(mocks, true); render( @@ -1343,7 +5825,7 @@ describe('Testing Chatroom Component [User Portal]', () => { - + @@ -1366,9 +5848,6 @@ describe('Testing Chatroom Component [User Portal]', () => { act(() => { fireEvent.click(sendBtn); }); - await waitFor(() => { - expect(input.value).toBeFalsy(); - }); const messages = await screen.findAllByTestId('message'); @@ -1419,13 +5898,16 @@ describe('Testing Chatroom Component [User Portal]', () => { ...CHAT_BY_ID_QUERY_MOCK, ...CHATS_LIST_MOCK, ...SEND_MESSAGE_TO_CHAT_MOCK, + ...MARK_CHAT_MESSAGES_AS_READ_MOCK, + ...GROUP_CHAT_LIST_QUERY_MOCK, + ...UNREAD_CHAT_LIST_QUERY_MOCK, ]; render( - + @@ -1439,95 +5921,18 @@ describe('Testing Chatroom Component [User Portal]', () => { ...MESSAGE_SENT_TO_CHAT_MOCK, ...CHAT_BY_ID_QUERY_MOCK, ...CHATS_LIST_MOCK, + ...GROUP_CHAT_BY_ID_QUERY_MOCK, ...SEND_MESSAGE_TO_CHAT_MOCK, + ...MARK_CHAT_MESSAGES_AS_READ_MOCK, + ...GROUP_CHAT_LIST_QUERY_MOCK, + ...UNREAD_CHAT_LIST_QUERY_MOCK, ]; render( - - - - - , - ); - await wait(); - - const input = (await screen.findByTestId( - 'messageInput', - )) as HTMLInputElement; - - act(() => { - fireEvent.change(input, { target: { value: 'Test message' } }); - }); - expect(input.value).toBe('Test message'); - - const sendBtn = await screen.findByTestId('sendMessage'); - - expect(sendBtn).toBeInTheDocument(); - act(() => { - fireEvent.click(sendBtn); - }); - await waitFor(() => { - expect(input.value).toBeFalsy(); - }); - - const messages = await screen.findAllByTestId('message'); - - expect(messages.length).not.toBe(0); - - act(() => { - fireEvent.mouseOver(messages[0]); - }); - - expect(await screen.findByTestId('moreOptions')).toBeInTheDocument(); - - const moreOptionsBtn = await screen.findByTestId('dropdown'); - act(() => { - fireEvent.click(moreOptionsBtn); - }); - - const replyBtn = await screen.findByTestId('replyBtn'); - - act(() => { - fireEvent.click(replyBtn); - }); - - const replyMsg = await screen.findByTestId('replyMsg'); - - await waitFor(() => { - expect(replyMsg).toBeInTheDocument(); - }); - - act(() => { - fireEvent.change(input, { target: { value: 'Test reply message' } }); - }); - expect(input.value).toBe('Test reply message'); - - const closeReplyBtn = await screen.findByTestId('closeReply'); - - expect(closeReplyBtn).toBeInTheDocument(); - - fireEvent.click(closeReplyBtn); - - await wait(500); - }); - - it('reply to message', async () => { - const mocks = [ - ...MESSAGE_SENT_TO_CHAT_MOCK, - ...CHAT_BY_ID_QUERY_MOCK, - ...CHATS_LIST_MOCK, - ...SEND_MESSAGE_TO_CHAT_MOCK, - ]; - const link2 = new StaticMockLink(mocks, true); - render( - - - - - + @@ -1550,9 +5955,6 @@ describe('Testing Chatroom Component [User Portal]', () => { act(() => { fireEvent.click(sendBtn); }); - await waitFor(() => { - expect(input.value).toBeFalsy(); - }); const messages = await screen.findAllByTestId('message'); @@ -1569,18 +5971,6 @@ describe('Testing Chatroom Component [User Portal]', () => { fireEvent.click(moreOptionsBtn); }); - const replyBtn = await screen.findByTestId('replyBtn'); - - act(() => { - fireEvent.click(replyBtn); - }); - - const replyMsg = await screen.findByTestId('replyMsg'); - - await waitFor(() => { - expect(replyMsg).toBeInTheDocument(); - }); - act(() => { fireEvent.change(input, { target: { value: 'Test reply message' } }); }); @@ -1590,6 +5980,6 @@ describe('Testing Chatroom Component [User Portal]', () => { fireEvent.click(sendBtn); }); - await wait(400); + await wait(500); }); }); diff --git a/src/components/UserPortal/ChatRoom/ChatRoom.tsx b/src/components/UserPortal/ChatRoom/ChatRoom.tsx index 27768dce5a..fd06a47c12 100644 --- a/src/components/UserPortal/ChatRoom/ChatRoom.tsx +++ b/src/components/UserPortal/ChatRoom/ChatRoom.tsx @@ -5,18 +5,31 @@ import { Button, Dropdown, Form, InputGroup } from 'react-bootstrap'; import styles from './ChatRoom.module.css'; import PermContactCalendarIcon from '@mui/icons-material/PermContactCalendar'; import { useTranslation } from 'react-i18next'; -import { CHAT_BY_ID } from 'GraphQl/Queries/PlugInQueries'; +import { CHAT_BY_ID, UNREAD_CHAT_LIST } from 'GraphQl/Queries/PlugInQueries'; +import type { ApolloQueryResult } from '@apollo/client'; import { useMutation, useQuery, useSubscription } from '@apollo/client'; import { + EDIT_CHAT_MESSAGE, + MARK_CHAT_MESSAGES_AS_READ, MESSAGE_SENT_TO_CHAT, SEND_MESSAGE_TO_CHAT, } from 'GraphQl/Mutations/OrganizationMutations'; import useLocalStorage from 'utils/useLocalstorage'; import Avatar from 'components/Avatar/Avatar'; import { MoreVert, Close } from '@mui/icons-material'; +import GroupChatDetails from 'components/GroupChatDetails/GroupChatDetails'; +import { GrAttachment } from 'react-icons/gr'; +import convertToBase64 from 'utils/convertToBase64'; interface InterfaceChatRoomProps { selectedContact: string; + chatListRefetch: ( + variables?: + | Partial<{ + id: string; + }> + | undefined, + ) => Promise>; } /** @@ -59,7 +72,7 @@ type DirectMessage = { } | undefined; messageContent: string; - type: string; + media: string; }; type Chat = { @@ -68,12 +81,20 @@ type Chat = { name?: string; image?: string; messages: DirectMessage[]; + admins: { + _id: string; + firstName: string; + lastName: string; + email: string; + }[]; users: { _id: string; firstName: string; lastName: string; email: string; }[]; + unseenMessagesByUsers: string; + description: string; }; export default function chatRoom(props: InterfaceChatRoomProps): JSX.Element { @@ -93,10 +114,23 @@ export default function chatRoom(props: InterfaceChatRoomProps): JSX.Element { const userId = getItem('userId'); const [chatTitle, setChatTitle] = useState(''); const [chatSubtitle, setChatSubtitle] = useState(''); + const [chatImage, setChatImage] = useState(''); const [newMessage, setNewMessage] = useState(''); const [chat, setChat] = useState(); const [replyToDirectMessage, setReplyToDirectMessage] = useState(null); + const [editMessage, setEditMessage] = useState(null); + const [groupChatDetailsModalisOpen, setGroupChatDetailsModalisOpen] = + useState(false); + + const [attachment, setAttachment] = useState(''); + + const openGroupChatDetails = (): void => { + setGroupChatDetailsModalisOpen(true); + }; + + const toggleGroupChatDetailsModal = (): void => + setGroupChatDetailsModalisOpen(!groupChatDetailsModalisOpen); /** * Handles changes to the new message input field. @@ -114,7 +148,23 @@ export default function chatRoom(props: InterfaceChatRoomProps): JSX.Element { variables: { chatId: props.selectedContact, replyTo: replyToDirectMessage?._id, + media: attachment, + messageContent: newMessage, + }, + }); + + const [editChatMessage] = useMutation(EDIT_CHAT_MESSAGE, { + variables: { + messageId: editMessage?._id, messageContent: newMessage, + chatId: props.selectedContact, + }, + }); + + const [markChatMessagesAsRead] = useMutation(MARK_CHAT_MESSAGES_AS_READ, { + variables: { + chatId: props.selectedContact, + userId: userId, }, }); @@ -124,8 +174,23 @@ export default function chatRoom(props: InterfaceChatRoomProps): JSX.Element { }, }); + // const { refetch: chatListRefetch } = useQuery(CHATS_LIST, { + // variables: { + // id: userId, + // }, + // }); + + const { refetch: unreadChatListRefetch } = useQuery(UNREAD_CHAT_LIST, { + variables: { + id: userId, + }, + }); + useEffect(() => { - chatRefetch(); + markChatMessagesAsRead().then(() => { + props.chatListRefetch(); + unreadChatListRefetch(); + }); }, [props.selectedContact]); useEffect(() => { @@ -135,6 +200,7 @@ export default function chatRoom(props: InterfaceChatRoomProps): JSX.Element { if (chat.isGroup) { setChatTitle(chat.name); setChatSubtitle(`${chat.users.length} members`); + setChatImage(chat.image); } else { const otherUser = chat.users.find( (user: { _id: string }) => user._id !== userId, @@ -142,32 +208,40 @@ export default function chatRoom(props: InterfaceChatRoomProps): JSX.Element { if (otherUser) { setChatTitle(`${otherUser.firstName} ${otherUser.lastName}`); setChatSubtitle(otherUser.email); + setChatImage(otherUser.image); } } } }, [chatData]); const sendMessage = async (): Promise => { - await sendMessageToChat(); + if (editMessage) { + await editChatMessage(); + } else { + await sendMessageToChat(); + } await chatRefetch(); setReplyToDirectMessage(null); setNewMessage(''); + setAttachment(''); + await props.chatListRefetch({ id: userId }); }; useSubscription(MESSAGE_SENT_TO_CHAT, { variables: { userId: userId, }, - onData: (messageSubscriptionData) => { - const chatMessage = messageSubscriptionData.data?.data?.messageSentToChat; - const chatId = chatMessage?.chatMessageBelongsTo?._id; - - if (!chatId) return; - if (chatId === props.selectedContact) { + onData: async (messageSubscriptionData) => { + if ( + messageSubscriptionData?.data.data.messageSentToChat && + messageSubscriptionData?.data.data.messageSentToChat + .chatMessageBelongsTo['_id'] == props.selectedContact + ) { + await markChatMessagesAsRead(); chatRefetch(); - } else { - chatRefetch({ id: chatId }); } + props.chatListRefetch(); + unreadChatListRefetch(); }, }); @@ -177,6 +251,22 @@ export default function chatRoom(props: InterfaceChatRoomProps): JSX.Element { ?.lastElementChild?.scrollIntoView({ block: 'end' }); }); + const fileInputRef = useRef(null); + + const handleAddAttachment = (): void => { + fileInputRef?.current?.click(); + }; + + const handleImageChange = async ( + e: React.ChangeEvent, + ): Promise => { + const file = e.target.files?.[0]; + if (file) { + const base64 = await convertToBase64(file); + setAttachment(base64); + } + }; + return (
- -
+ {chatImage ? ( + {chatTitle} + ) : ( + + )} +
(chat?.isGroup ? openGroupChatDetails() : null)} + className={styles.userDetails} + >

{chatTitle}

{chatSubtitle}

@@ -271,6 +372,13 @@ export default function chatRoom(props: InterfaceChatRoomProps): JSX.Element {
)} + {message.media && ( + attachment + )} {message.messageContent}
@@ -291,7 +399,16 @@ export default function chatRoom(props: InterfaceChatRoomProps): JSX.Element { }} data-testid="replyBtn" > - Reply + {t('reply')} + + { + setEditMessage(message); + setNewMessage(message.messageContent); + }} + data-testid="replyToMessage" + > + Edit @@ -314,6 +431,13 @@ export default function chatRoom(props: InterfaceChatRoomProps): JSX.Element {
+ {!!replyToDirectMessage?._id && (
@@ -349,14 +473,33 @@ export default function chatRoom(props: InterfaceChatRoomProps): JSX.Element {
)} + {attachment && ( +
+ attachment + + +
+ )} + +
); } diff --git a/src/components/UserPortal/ContactCard/ContactCard.module.css b/src/components/UserPortal/ContactCard/ContactCard.module.css index 19d66596c9..59d857efe2 100644 --- a/src/components/UserPortal/ContactCard/ContactCard.module.css +++ b/src/components/UserPortal/ContactCard/ContactCard.module.css @@ -10,8 +10,8 @@ .contactImage { width: 45px !important; - height: auto !important; - border-radius: 10px; + height: 45px !important; + border-radius: 100%; display: flex; align-items: center; justify-content: center; @@ -19,9 +19,10 @@ .contactNameContainer { display: flex; - flex-direction: column; padding: 0px 10px; - justify-content: center; + justify-content: space-between; + align-items: center; + flex-grow: 1; } .grey { @@ -35,3 +36,13 @@ .bgWhite { background-color: white; } + +.lastMessage { + margin-bottom: 0; + font-size: 14px; + color: rgba(163, 163, 163, 0.839); +} + +.unseenMessagesCount { + border-radius: 50%; +} diff --git a/src/components/UserPortal/ContactCard/ContactCard.spec.tsx b/src/components/UserPortal/ContactCard/ContactCard.spec.tsx index 1d32360301..572a38feb7 100644 --- a/src/components/UserPortal/ContactCard/ContactCard.spec.tsx +++ b/src/components/UserPortal/ContactCard/ContactCard.spec.tsx @@ -42,6 +42,8 @@ let props = { image: '', selectedContact: '', type: '', + unseenMessages: 2, + lastMessage: '', setSelectedContact: vi.fn(), setSelectedChatType: vi.fn(), }; diff --git a/src/components/UserPortal/ContactCard/ContactCard.tsx b/src/components/UserPortal/ContactCard/ContactCard.tsx index ef6bf2c9d5..5ec7c9c1d3 100644 --- a/src/components/UserPortal/ContactCard/ContactCard.tsx +++ b/src/components/UserPortal/ContactCard/ContactCard.tsx @@ -1,6 +1,7 @@ import React from 'react'; import styles from './ContactCard.module.css'; import Avatar from 'components/Avatar/Avatar'; +import { Badge } from 'react-bootstrap'; interface InterfaceContactCardProps { id: string; @@ -9,6 +10,8 @@ interface InterfaceContactCardProps { selectedContact: string; setSelectedContact: React.Dispatch>; isGroup: boolean; + unseenMessages: number; + lastMessage: string; } /** @@ -66,7 +69,15 @@ function contactCard(props: InterfaceContactCardProps): JSX.Element { /> )}
- {props.title} +
+ {props.title}{' '} +

{props.lastMessage}

+
+ {!!props.unseenMessages && ( + + {props.unseenMessages} + + )}
diff --git a/src/components/UserPortal/CreateDirectChat/CreateDirectChat.spec.tsx b/src/components/UserPortal/CreateDirectChat/CreateDirectChat.spec.tsx index 5526206708..ccf23a882b 100644 --- a/src/components/UserPortal/CreateDirectChat/CreateDirectChat.spec.tsx +++ b/src/components/UserPortal/CreateDirectChat/CreateDirectChat.spec.tsx @@ -16,9 +16,15 @@ import i18nForTest from 'utils/i18nForTest'; import Chat from '../../../screens/UserPortal/Chat/Chat'; import { CREATE_CHAT, + MARK_CHAT_MESSAGES_AS_READ, MESSAGE_SENT_TO_CHAT, } from 'GraphQl/Mutations/OrganizationMutations'; -import { CHATS_LIST, CHAT_BY_ID } from 'GraphQl/Queries/PlugInQueries'; +import { + CHATS_LIST, + CHAT_BY_ID, + GROUP_CHAT_LIST, + UNREAD_CHAT_LIST, +} from 'GraphQl/Queries/PlugInQueries'; import useLocalStorage from 'utils/useLocalstorage'; import { vi } from 'vitest'; const { setItem } = useLocalStorage(); @@ -347,6 +353,9 @@ const MESSAGE_SENT_TO_CHAT_MOCK = [ data: { messageSentToChat: { _id: '668ec1f1364e03ac47a151', + chatMessageBelongsTo: { + _id: '1', + }, createdAt: '2024-07-10T17:16:33.248Z', messageContent: 'Test ', type: 'STRING', @@ -373,6 +382,9 @@ const MESSAGE_SENT_TO_CHAT_MOCK = [ data: { messageSentToChat: { _id: '668ec1f1df364e03ac47a151', + chatMessageBelongsTo: { + _id: '1', + }, createdAt: '2024-07-10T17:16:33.248Z', messageContent: 'Test ', replyTo: null, @@ -399,6 +411,9 @@ const MESSAGE_SENT_TO_CHAT_MOCK = [ data: { messageSentToChat: { _id: '668ec1f13603ac4697a151', + chatMessageBelongsTo: { + _id: '1', + }, createdAt: '2024-07-10T17:16:33.248Z', messageContent: 'Test ', replyTo: null, @@ -447,6 +462,7 @@ const CHAT_BY_ID_QUERY_MOCK = [ createdAt: '345678908765', messageContent: 'Hello', replyTo: null, + media: null, type: 'STRING', sender: { _id: '2', @@ -473,6 +489,19 @@ const CHAT_BY_ID_QUERY_MOCK = [ image: '', }, ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), }, }, }, @@ -507,6 +536,7 @@ const CHAT_BY_ID_QUERY_MOCK = [ createdAt: '345678908765', messageContent: 'Hello', replyTo: null, + media: null, type: 'STRING', sender: { _id: '2', @@ -533,6 +563,19 @@ const CHAT_BY_ID_QUERY_MOCK = [ image: '', }, ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), }, }, }, @@ -567,6 +610,226 @@ const CHAT_BY_ID_QUERY_MOCK = [ createdAt: '345678908765', messageContent: 'Hello', replyTo: null, + media: 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + }, + }, + }, +]; + +const UNREAD_CHAT_LIST_QUERY_MOCK = [ + { + request: { + query: UNREAD_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getUnreadChatsByUserId: { + _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, + media: 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getUnreadChatsByUserId: { + _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, + media: 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getUnreadChatsByUserId: { + _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, + media: null, type: 'STRING', sender: { _id: '2', @@ -575,44 +838,2036 @@ const CHAT_BY_ID_QUERY_MOCK = [ 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: '', - }, - ], - }, + }, + ], + users: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getUnreadChatsByUserId: { + _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, + media: 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: { + id: '1', + }, + }, + result: { + data: { + getUnreadChatsByUserId: { + _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, + media: 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: { + id: '1', + }, + }, + result: { + data: { + getUnreadChatsByUserId: { + _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, + media: 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: { + id: '1', + }, + }, + result: { + data: { + getUnreadChatsByUserId: { + _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, + media: 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + getUnreadChatsByUserId: { + _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, + media: 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + getUnreadChatsByUserId: { + _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, + media: 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + }, + }, + }, +]; + +const GROUP_CHAT_BY_USER_ID_QUERY_MOCK = [ + { + request: { + query: GROUP_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getGroupChatsByUserId: { + _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, + media: 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + }, + }, + }, + { + request: { + query: GROUP_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getGroupChatsByUserId: { + _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, + media: 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + }, + }, + }, + { + request: { + query: GROUP_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getGroupChatsByUserId: { + _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, + media: 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + }, + }, + }, +]; + +const CHATS_LIST_MOCK = [ + { + request: { + query: CHATS_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844efc814dd40fgh03db811c4', + isGroup: true, + image: null, + 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, + media: 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + { + _id: '65844efc814ddgh4003db811c4', + isGroup: true, + image: null, + 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, + media: 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844efc814dd40fgh03db811c4', + isGroup: true, + image: null, + 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, + media: 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + { + _id: '65844efc814ddgh4003db811c4', + isGroup: true, + image: null, + 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, + media: 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844efc814dd40fgh03db811c4', + isGroup: true, + image: null, + 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, + media: 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + { + _id: '65844efc814ddgh4003db811c4', + isGroup: true, + image: null, + 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, + media: null, + type: 'STRING', + sender: { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', + }, + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@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: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844efc814dd40fgh03db811c4', + isGroup: true, + image: null, + 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, + media: 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + { + _id: '65844efc814ddgh4003db811c4', + isGroup: true, + image: null, + 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, + media: 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844efc814dd40fgh03db811c4', + isGroup: true, + image: null, + 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, + media: 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + { + _id: '65844efc814ddgh4003db811c4', + isGroup: true, + image: null, + 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, + media: 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: '', + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844ghjefc814dd4003db811c4', + isGroup: true, + image: null, + 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, + media: 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + { + _id: 'ujhgtrdtyuiop', + isGroup: true, + image: null, + 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, + media: 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: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: '1', + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844efc814dhjmkdftyd4003db811c4', + isGroup: true, + image: null, + 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, + media: 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + { + _id: '65844ewsedrffc814dd4003db811c4', + isGroup: true, + image: null, + 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, + media: 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], }, }, }, -]; - -const CHATS_LIST_MOCK = [ { request: { query: CHATS_LIST, variables: { - id: null, + id: '1', }, }, result: { data: { chatsByUserId: [ { - _id: '65844efc814dd40fgh03db811c4', + _id: '65844efc814dhjmkdftyd4003db811c4', isGroup: true, + image: null, creator: { _id: '64378abd85008f171cf2990d', firstName: 'Wilt', @@ -634,6 +2889,7 @@ const CHATS_LIST_MOCK = [ createdAt: '345678908765', messageContent: 'Hello', replyTo: null, + media: null, type: 'STRING', sender: { _id: '2', @@ -681,10 +2937,27 @@ const CHATS_LIST_MOCK = [ image: '', }, ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), }, { - _id: '65844efc814ddgh4003db811c4', + _id: '65844ewsedrffc814dd4003db811c4', isGroup: true, + image: null, creator: { _id: '64378abd85008f171cf2990d', firstName: 'Wilt', @@ -706,6 +2979,7 @@ const CHATS_LIST_MOCK = [ createdAt: '345678908765', messageContent: 'Hello', replyTo: null, + media: null, type: 'STRING', sender: { _id: '2', @@ -753,6 +3027,22 @@ const CHATS_LIST_MOCK = [ image: '', }, ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), }, ], }, @@ -762,15 +3052,16 @@ const CHATS_LIST_MOCK = [ request: { query: CHATS_LIST, variables: { - id: '', + id: '1', }, }, result: { data: { chatsByUserId: [ { - _id: '65844ghjefc814dd4003db811c4', + _id: '65844efc814dhjmkdftyd4003db811c4', isGroup: true, + image: null, creator: { _id: '64378abd85008f171cf2990d', firstName: 'Wilt', @@ -789,6 +3080,7 @@ const CHATS_LIST_MOCK = [ messages: [ { _id: '345678', + media: null, createdAt: '345678908765', messageContent: 'Hello', replyTo: null, @@ -839,10 +3131,27 @@ const CHATS_LIST_MOCK = [ image: '', }, ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), }, { - _id: 'ujhgtrdtyuiop', + _id: '65844ewsedrffc814dd4003db811c4', isGroup: true, + image: null, creator: { _id: '64378abd85008f171cf2990d', firstName: 'Wilt', @@ -864,6 +3173,7 @@ const CHATS_LIST_MOCK = [ createdAt: '345678908765', messageContent: 'Hello', replyTo: null, + media: null, type: 'STRING', sender: { _id: '2', @@ -911,6 +3221,22 @@ const CHATS_LIST_MOCK = [ image: '', }, ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), }, ], }, @@ -929,6 +3255,7 @@ const CHATS_LIST_MOCK = [ { _id: '65844efc814dhjmkdftyd4003db811c4', isGroup: true, + image: null, creator: { _id: '64378abd85008f171cf2990d', firstName: 'Wilt', @@ -950,6 +3277,7 @@ const CHATS_LIST_MOCK = [ createdAt: '345678908765', messageContent: 'Hello', replyTo: null, + media: null, type: 'STRING', sender: { _id: '2', @@ -997,10 +3325,27 @@ const CHATS_LIST_MOCK = [ image: '', }, ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), }, { _id: '65844ewsedrffc814dd4003db811c4', isGroup: true, + image: null, creator: { _id: '64378abd85008f171cf2990d', firstName: 'Wilt', @@ -1022,6 +3367,7 @@ const CHATS_LIST_MOCK = [ createdAt: '345678908765', messageContent: 'Hello', replyTo: null, + media: null, type: 'STRING', sender: { _id: '2', @@ -1069,6 +3415,22 @@ const CHATS_LIST_MOCK = [ image: '', }, ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), }, ], }, @@ -1087,6 +3449,7 @@ const CHATS_LIST_MOCK = [ { _id: '65844efc814dhjmkdftyd4003db811c4', isGroup: true, + image: null, creator: { _id: '64378abd85008f171cf2990d', firstName: 'Wilt', @@ -1108,6 +3471,7 @@ const CHATS_LIST_MOCK = [ createdAt: '345678908765', messageContent: 'Hello', replyTo: null, + media: null, type: 'STRING', sender: { _id: '2', @@ -1155,10 +3519,27 @@ const CHATS_LIST_MOCK = [ image: '', }, ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), }, { _id: '65844ewsedrffc814dd4003db811c4', isGroup: true, + image: null, creator: { _id: '64378abd85008f171cf2990d', firstName: 'Wilt', @@ -1180,6 +3561,7 @@ const CHATS_LIST_MOCK = [ createdAt: '345678908765', messageContent: 'Hello', replyTo: null, + media: null, type: 'STRING', sender: { _id: '2', @@ -1227,6 +3609,22 @@ const CHATS_LIST_MOCK = [ image: '', }, ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), }, ], }, @@ -1247,6 +3645,7 @@ const GROUP_CHAT_BY_ID_QUERY_MOCK = [ chatById: { _id: '65844efc814dd4003db811c4', isGroup: true, + image: null, creator: { _id: '64378abd85008f171cf2990d', firstName: 'Wilt', @@ -1268,6 +3667,7 @@ const GROUP_CHAT_BY_ID_QUERY_MOCK = [ createdAt: '345678908765', messageContent: 'Hello', replyTo: null, + media: null, type: 'STRING', sender: { _id: '2', @@ -1315,6 +3715,22 @@ const GROUP_CHAT_BY_ID_QUERY_MOCK = [ image: '', }, ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), }, }, }, @@ -1355,6 +3771,7 @@ const CREATE_CHAT_MUTATION_MOCK = [ messageContent: 'Hello', replyTo: null, type: 'STRING', + media: null, sender: { _id: '2', firstName: 'Test', @@ -1380,12 +3797,114 @@ const CREATE_CHAT_MUTATION_MOCK = [ image: '', }, ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + }), }, }, }, }, ]; +const MARK_CHAT_MESSAGES_AS_READ_MOCK = [ + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: null, + chatId: '', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: null, + chatId: '', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: null, + chatId: '', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: null, + chatId: '', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: '1', + chatId: '', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: '1', + chatId: '', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, +]; async function wait(ms = 100): Promise { await act(() => { return new Promise((resolve) => { @@ -1419,6 +3938,9 @@ describe('Testing Create Direct Chat Modal [User Portal]', () => { ...CHATS_LIST_MOCK, ...CHAT_BY_ID_QUERY_MOCK, ...CREATE_CHAT_MUTATION_MOCK, + ...MARK_CHAT_MESSAGES_AS_READ_MOCK, + ...UNREAD_CHAT_LIST_QUERY_MOCK, + ...GROUP_CHAT_BY_USER_ID_QUERY_MOCK, ]; render( @@ -1470,6 +3992,9 @@ describe('Testing Create Direct Chat Modal [User Portal]', () => { ...CHATS_LIST_MOCK, ...CHAT_BY_ID_QUERY_MOCK, ...CREATE_CHAT_MUTATION_MOCK, + ...MARK_CHAT_MESSAGES_AS_READ_MOCK, + ...UNREAD_CHAT_LIST_QUERY_MOCK, + ...GROUP_CHAT_BY_USER_ID_QUERY_MOCK, ]; render( diff --git a/src/components/UserPortal/CreateDirectChat/CreateDirectChat.tsx b/src/components/UserPortal/CreateDirectChat/CreateDirectChat.tsx index 24c853fcdd..8125b6a463 100644 --- a/src/components/UserPortal/CreateDirectChat/CreateDirectChat.tsx +++ b/src/components/UserPortal/CreateDirectChat/CreateDirectChat.tsx @@ -17,6 +17,7 @@ import { USERS_CONNECTION_LIST } from 'GraphQl/Queries/Queries'; import Loader from 'components/Loader/Loader'; import { Search } from '@mui/icons-material'; import { useParams } from 'react-router-dom'; +import { useTranslation } from 'react-i18next'; interface InterfaceCreateDirectChatProps { toggleCreateDirectChatModal: () => void; @@ -27,7 +28,7 @@ interface InterfaceCreateDirectChatProps { id: string; }> | undefined, - ) => Promise>; + ) => Promise>; } /** @@ -61,6 +62,9 @@ export default function createDirectChatModal({ createDirectChatModalisOpen, chatsListRefetch, }: InterfaceCreateDirectChatProps): JSX.Element { + const { t } = useTranslation('translation', { + keyPrefix: 'userChat', + }); const { orgId: organizationId } = useParams(); const userId: string | null = getItem('userId'); @@ -187,7 +191,7 @@ export default function createDirectChatModal({ }} data-testid="addBtn" > - Add + {t('add')} diff --git a/src/components/UserPortal/CreateGroupChat/CreateGroupChat.module.css b/src/components/UserPortal/CreateGroupChat/CreateGroupChat.module.css index 3795e402fa..77fcfaf38f 100644 --- a/src/components/UserPortal/CreateGroupChat/CreateGroupChat.module.css +++ b/src/components/UserPortal/CreateGroupChat/CreateGroupChat.module.css @@ -7,3 +7,32 @@ .modalContent { width: 530px; } + +.groupInfo { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; +} + +.groupImage { + margin-bottom: 10px; +} + +.editImgBtn { + padding: 2px 6px 6px 8px; + border-radius: 100%; + background-color: white; + border: 1px solid #959595; + color: #959595; + outline: none; + position: relative; + top: -40px; + left: 40px; +} + +.chatImage { + height: 120px; + border-radius: 100%; + width: 120px; +} diff --git a/src/components/UserPortal/CreateGroupChat/CreateGroupChat.spec.tsx b/src/components/UserPortal/CreateGroupChat/CreateGroupChat.spec.tsx index 711bb29a93..440273cbc4 100644 --- a/src/components/UserPortal/CreateGroupChat/CreateGroupChat.spec.tsx +++ b/src/components/UserPortal/CreateGroupChat/CreateGroupChat.spec.tsx @@ -5,7 +5,6 @@ import { render, screen, waitFor, - within, } from '@testing-library/react'; import { MockedProvider } from '@apollo/react-testing'; import { I18nextProvider } from 'react-i18next'; @@ -21,11 +20,16 @@ import i18nForTest from 'utils/i18nForTest'; import Chat from '../../../screens/UserPortal/Chat/Chat'; import { CREATE_CHAT, + MARK_CHAT_MESSAGES_AS_READ, MESSAGE_SENT_TO_CHAT, } from 'GraphQl/Mutations/OrganizationMutations'; -import { CHATS_LIST, CHAT_BY_ID } from 'GraphQl/Queries/PlugInQueries'; +import { + CHATS_LIST, + CHAT_BY_ID, + GROUP_CHAT_LIST, + UNREAD_CHAT_LIST, +} from 'GraphQl/Queries/PlugInQueries'; import useLocalStorage from 'utils/useLocalstorage'; -import userEvent from '@testing-library/user-event'; import { vi } from 'vitest'; /** @@ -1228,6 +1232,9 @@ const MESSAGE_SENT_TO_CHAT_MOCK = [ data: { messageSentToChat: { _id: '668ec1f1364e03ac47a151', + chatMessageBelongsTo: { + _id: '1', + }, createdAt: '2024-07-10T17:16:33.248Z', messageContent: 'Test ', type: 'STRING', @@ -1254,6 +1261,9 @@ const MESSAGE_SENT_TO_CHAT_MOCK = [ data: { messageSentToChat: { _id: '668ec1f1df364e03ac47a151', + chatMessageBelongsTo: { + _id: '1', + }, createdAt: '2024-07-10T17:16:33.248Z', messageContent: 'Test ', replyTo: null, @@ -1280,6 +1290,9 @@ const MESSAGE_SENT_TO_CHAT_MOCK = [ data: { messageSentToChat: { _id: '668ec1f13603ac4697a151', + chatMessageBelongsTo: { + _id: '1', + }, createdAt: '2024-07-10T17:16:33.248Z', messageContent: 'Test ', replyTo: null, @@ -1328,6 +1341,7 @@ const CHAT_BY_ID_QUERY_MOCK = [ createdAt: '345678908765', messageContent: 'Hello', replyTo: null, + media: null, type: 'STRING', sender: { _id: '2', @@ -1354,6 +1368,19 @@ const CHAT_BY_ID_QUERY_MOCK = [ image: '', }, ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + }), }, }, }, @@ -1388,6 +1415,7 @@ const CHAT_BY_ID_QUERY_MOCK = [ createdAt: '345678908765', messageContent: 'Hello', replyTo: null, + media: null, type: 'STRING', sender: { _id: '2', @@ -1414,6 +1442,19 @@ const CHAT_BY_ID_QUERY_MOCK = [ image: '', }, ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + }), }, }, }, @@ -1448,6 +1489,7 @@ const CHAT_BY_ID_QUERY_MOCK = [ createdAt: '345678908765', messageContent: 'Hello', replyTo: null, + media: null, type: 'STRING', sender: { _id: '2', @@ -1474,26 +1516,40 @@ const CHAT_BY_ID_QUERY_MOCK = [ image: '', }, ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + }), }, }, }, }, ]; -const CHATS_LIST_MOCK = [ +const UNREAD_CHAT_BY_USER_ID_QUERY_MOCK = [ { request: { - query: CHATS_LIST, + query: UNREAD_CHAT_LIST, variables: { id: null, }, }, result: { data: { - chatsByUserId: [ + getUnreadChatsByUserId: [ { - _id: '65844efc814dd40fgh03db811c4', + _id: '65844efc814dd40hgjfgh03db811c4', isGroup: true, + image: null, creator: { _id: '64378abd85008f171cf2990d', firstName: 'Wilt', @@ -1515,6 +1571,7 @@ const CHATS_LIST_MOCK = [ createdAt: '345678908765', messageContent: 'Hello', replyTo: null, + media: null, type: 'STRING', sender: { _id: '2', @@ -1562,10 +1619,33 @@ const CHATS_LIST_MOCK = [ image: '', }, ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), }, + ], + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + getUnreadChatsByUserId: [ { - _id: '65844efc814ddgh4003db811c4', + _id: '65844efc814dd40hgjfgh03db811c4', isGroup: true, + image: null, creator: { _id: '64378abd85008f171cf2990d', firstName: 'Wilt', @@ -1587,6 +1667,7 @@ const CHATS_LIST_MOCK = [ createdAt: '345678908765', messageContent: 'Hello', replyTo: null, + media: null, type: 'STRING', sender: { _id: '2', @@ -1634,6 +1715,14 @@ const CHATS_LIST_MOCK = [ image: '', }, ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), }, ], }, @@ -1641,17 +1730,18 @@ const CHATS_LIST_MOCK = [ }, { request: { - query: CHATS_LIST, + query: UNREAD_CHAT_LIST, variables: { - id: '', + id: null, }, }, result: { data: { - chatsByUserId: [ + getUnreadChatsByUserId: [ { - _id: '65844ghjefc814dd4003db811c4', + _id: '65844efc814dd40hgjfgh03db811c4', isGroup: true, + image: null, creator: { _id: '64378abd85008f171cf2990d', firstName: 'Wilt', @@ -1673,6 +1763,7 @@ const CHATS_LIST_MOCK = [ createdAt: '345678908765', messageContent: 'Hello', replyTo: null, + media: null, type: 'STRING', sender: { _id: '2', @@ -1720,10 +1811,33 @@ const CHATS_LIST_MOCK = [ image: '', }, ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), }, + ], + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + getUnreadChatsByUserId: [ { - _id: 'ujhgtrdtyuiop', + _id: '65844efc814dd40hgjfgh03db811c4', isGroup: true, + image: null, creator: { _id: '64378abd85008f171cf2990d', firstName: 'Wilt', @@ -1745,6 +1859,7 @@ const CHATS_LIST_MOCK = [ createdAt: '345678908765', messageContent: 'Hello', replyTo: null, + media: null, type: 'STRING', sender: { _id: '2', @@ -1792,6 +1907,14 @@ const CHATS_LIST_MOCK = [ image: '', }, ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), }, ], }, @@ -1799,17 +1922,18 @@ const CHATS_LIST_MOCK = [ }, { request: { - query: CHATS_LIST, + query: UNREAD_CHAT_LIST, variables: { - id: '1', + id: null, }, }, result: { data: { - chatsByUserId: [ + getUnreadChatsByUserId: [ { - _id: '65844efc814dhjmkdftyd4003db811c4', + _id: '65844efc814dd40hgjfgh03db811c4', isGroup: true, + image: null, creator: { _id: '64378abd85008f171cf2990d', firstName: 'Wilt', @@ -1831,6 +1955,7 @@ const CHATS_LIST_MOCK = [ createdAt: '345678908765', messageContent: 'Hello', replyTo: null, + media: null, type: 'STRING', sender: { _id: '2', @@ -1878,10 +2003,33 @@ const CHATS_LIST_MOCK = [ image: '', }, ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), }, + ], + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: { + id: '1', + }, + }, + result: { + data: { + getUnreadChatsByUserId: [ { - _id: '65844ewsedrffc814dd4003db811c4', + _id: '65844efc814dd40hgjfgh03db811c4', isGroup: true, + image: null, creator: { _id: '64378abd85008f171cf2990d', firstName: 'Wilt', @@ -1903,6 +2051,7 @@ const CHATS_LIST_MOCK = [ createdAt: '345678908765', messageContent: 'Hello', replyTo: null, + media: null, type: 'STRING', sender: { _id: '2', @@ -1950,138 +2099,3235 @@ const CHATS_LIST_MOCK = [ image: '', }, ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), }, ], }, }, }, -]; - -const GROUP_CHAT_BY_ID_QUERY_MOCK = [ { request: { - query: CHAT_BY_ID, + query: UNREAD_CHAT_LIST, variables: { - id: '', + id: '1', }, }, result: { data: { - chatById: { - _id: '65844efc814dd4003db811c4', - isGroup: true, - creator: { - _id: '64378abd85008f171cf2990d', - firstName: 'Wilt', - lastName: 'Shepherd', + getUnreadChatsByUserId: [ + { + _id: '65844efc814dd40hgjfgh03db811c4', + isGroup: true, 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: { + 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, + media: 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: '', }, - }, - ], - 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: '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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], }, }, }, -]; - -const CREATE_CHAT_MUTATION = [ { request: { - query: CREATE_CHAT, + query: UNREAD_CHAT_LIST, variables: { - organizationId: '6401ff65ce8e8406b8jygjgf07af2', - userIds: [null], - name: 'Test Group', - isGroup: true, + id: '1', }, }, result: { data: { - createChat: { - _id: '65844efc814dd4003db811c4', - isGroup: true, - creator: { - _id: '64378abd85008f171cf2990d', - firstName: 'Wilt', - lastName: 'Shepherd', + getUnreadChatsByUserId: [ + { + _id: '65844efc814dd40hgjfgh03db811c4', + isGroup: true, 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', + 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, + media: 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getUnreadChatsByUserId: [ + { + _id: '65844efc814dd40hgjfgh03db811c4', + isGroup: true, + image: null, + 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, + media: 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getUnreadChatsByUserId: [ + { + _id: '65844efc814dd40hgjfgh03db811c4', + isGroup: true, + image: null, + 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, + media: 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getUnreadChatsByUserId: [ + { + _id: '65844efc814dd40hgjfgh03db811c4', + isGroup: true, + image: null, + 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, + media: 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getUnreadChatsByUserId: [ + { + _id: '65844efc814dd40hgjfgh03db811c4', + isGroup: true, + image: null, + 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, + media: 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, +]; + +const CHATS_LIST_MOCK = [ + { + request: { + query: CHATS_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844efc814dd40hgjfgh03db811c4', + isGroup: true, + image: null, + 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, + media: 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + { + _id: '65844efc814ddgh4003db811c4', + isGroup: true, + image: null, + 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, + media: 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: '', + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844ghjefc814dd4003db811c4', + isGroup: true, + image: null, + 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, + media: 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + { + _id: '65844efc814ddgh4003db811c4', + isGroup: true, + image: null, + 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, + media: 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: 'fcfgcgchnbjhgfrftghj', + isGroup: true, + image: null, + 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, + media: 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + { + _id: '65844efc814ddgh4003db811c4', + isGroup: true, + image: null, + 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, + media: 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844efc814dd40fgh03db8gjhbhn11c4', + isGroup: true, + image: null, + 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, + media: 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + { + _id: '65844efc814ddgh4003db811c4', + isGroup: true, + image: null, + 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, + media: 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: '', + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844ghjefc814dd4003db811c4', + isGroup: true, + image: null, + 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, + media: 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + { + _id: 'ujhgtrdtyuiop', + isGroup: true, + image: null, + 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, + media: 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: '1', + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844efc814dhjmkdftyd4003db811c4', + isGroup: true, + image: null, + 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, + media: 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + { + _id: '65844ewsedrffc814dd4003db811c4', + isGroup: true, + image: null, + 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, + media: 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, +]; + +const GROUP_CHAT_LIST_QUERY_MOCK = [ + { + request: { + query: GROUP_CHAT_LIST, + variables: { + id: '', + }, + }, + result: { + data: { + getGroupChatsByUserId: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: null, + 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, + media: 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, + { + request: { + query: GROUP_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getGroupChatsByUserId: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: null, + 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, + media: 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, + { + request: { + query: GROUP_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getGroupChatsByUserId: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: null, + 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, + media: 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, + { + request: { + query: GROUP_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getGroupChatsByUserId: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: null, + 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, + media: 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, + { + request: { + query: GROUP_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getGroupChatsByUserId: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: null, + 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, + media: 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, + { + request: { + query: GROUP_CHAT_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + getGroupChatsByUserId: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: null, + 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, + media: 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, + { + request: { + query: GROUP_CHAT_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + getGroupChatsByUserId: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: null, + 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, + media: 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, + { + request: { + query: GROUP_CHAT_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + getGroupChatsByUserId: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: null, + 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, + media: 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, +]; + +const GROUP_CHAT_BY_ID_QUERY_MOCK = [ + { + request: { + query: CHAT_BY_ID, + variables: { + id: '', + }, + }, + result: { + data: { + chatById: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: null, + 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, + media: 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, +]; + +const CREATE_CHAT_MUTATION = [ + { + request: { + query: CREATE_CHAT, + variables: { + organizationId: '6401ff65ce8e8406b8jygjgf07af2', + userIds: [null], + name: 'Test Group', + isGroup: true, + image: null, + }, + }, + result: { + data: { + createChat: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: null, + 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, + media: 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, + { + request: { + query: CREATE_CHAT, + variables: { + organizationId: '6401ff65ce8e8406b8jygjgf07af2', + userIds: [null], + name: 'Test Group', + isGroup: true, + image: null, + }, + }, + result: { + data: { + createChat: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: null, + 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, + media: 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, + { + request: { + query: CREATE_CHAT, + variables: { + organizationId: '6401ff65ce8e8406b8jygjgf07af2', + userIds: [null], + name: 'Test Group', + isGroup: true, + image: null, + }, + }, + result: { + data: { + createChat: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: null, + 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, + media: 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, + { + request: { + query: CREATE_CHAT, + variables: { + organizationId: '6401ff65ce8e8406b8jygjgf07af2', + userIds: [null], + name: 'Test Group', + isGroup: true, + image: null, + }, + }, + result: { + data: { + createChat: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: null, + 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, + media: 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, + { + request: { + query: CREATE_CHAT, + variables: { + userIds: [null], + name: 'Test Group', + isGroup: true, + image: null, + }, + }, + result: { + data: { + createChat: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: null, + 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, + media: 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, + { + request: { + query: CREATE_CHAT, + variables: { + userIds: [null], + name: 'Test Group', + isGroup: true, + image: null, + }, + }, + result: { + data: { + createChat: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: null, + 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, + media: 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, + { + request: { + query: CREATE_CHAT, + variables: { + userIds: [null], + name: 'Test Group', + isGroup: true, + image: null, + }, + }, + result: { + data: { + createChat: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: null, + 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, + media: 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, + { + request: { + query: CREATE_CHAT, + variables: { + userIds: [null], + name: 'Test Group', + isGroup: true, + image: null, + }, + }, + result: { + data: { + createChat: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: null, + 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', + media: null, sender: { _id: '2', firstName: 'Test', @@ -2128,6 +5374,14 @@ const CREATE_CHAT_MUTATION = [ image: '', }, ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), }, }, }, @@ -2140,6 +5394,7 @@ const CREATE_CHAT_MUTATION = [ userIds: [null], name: 'Test Group', isGroup: true, + image: null, }, }, result: { @@ -2147,6 +5402,7 @@ const CREATE_CHAT_MUTATION = [ createChat: { _id: '65844efc814dd4003db811c4', isGroup: true, + image: null, creator: { _id: '64378abd85008f171cf2990d', firstName: 'Wilt', @@ -2168,6 +5424,7 @@ const CREATE_CHAT_MUTATION = [ createdAt: '345678908765', messageContent: 'Hello', replyTo: null, + media: null, type: 'STRING', sender: { _id: '2', @@ -2215,6 +5472,97 @@ const CREATE_CHAT_MUTATION = [ image: '', }, ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, +]; + +const MARK_CHAT_MESSAGES_AS_READ_MOCK = [ + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: null, + chatId: '', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: null, + chatId: '', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: '1', + chatId: '', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: '1', + chatId: '', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: '1', + chatId: '', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', }, }, }, @@ -2256,6 +5604,9 @@ describe('Testing Create Group Chat Modal [User Portal]', () => { ...UserConnectionListMock, ...CREATE_CHAT_MUTATION, ...CHATS_LIST_MOCK, + ...MARK_CHAT_MESSAGES_AS_READ_MOCK, + ...UNREAD_CHAT_BY_USER_ID_QUERY_MOCK, + ...GROUP_CHAT_LIST_QUERY_MOCK, ]; render( @@ -2274,7 +5625,7 @@ describe('Testing Create Group Chat Modal [User Portal]', () => { const dropdown = await screen.findByTestId('dropdown'); expect(dropdown).toBeInTheDocument(); fireEvent.click(dropdown); - const newGroupChatBtn = await screen.findByTestId('newGroupChat'); + const newGroupChatBtn = await screen.findByTestId('newDirectChat'); expect(newGroupChatBtn).toBeInTheDocument(); fireEvent.click(newGroupChatBtn); @@ -2294,6 +5645,9 @@ describe('Testing Create Group Chat Modal [User Portal]', () => { ...UserConnectionListMock, ...CREATE_CHAT_MUTATION, ...CHATS_LIST_MOCK, + ...MARK_CHAT_MESSAGES_AS_READ_MOCK, + ...UNREAD_CHAT_BY_USER_ID_QUERY_MOCK, + ...GROUP_CHAT_LIST_QUERY_MOCK, ]; render( @@ -2324,9 +5678,9 @@ describe('Testing Create Group Chat Modal [User Portal]', () => { ).toBeInTheDocument(); }); - const groupTitleInput = screen.getByLabelText( - 'Group name', - ) as HTMLInputElement; + const groupTitleInput = (await screen.findByTestId( + 'groupTitleInput', + )) as unknown as HTMLInputElement; expect(groupTitleInput).toBeInTheDocument(); @@ -2335,35 +5689,6 @@ describe('Testing Create Group Chat Modal [User Portal]', () => { 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(() => { @@ -2379,9 +5704,9 @@ describe('Testing Create Group Chat Modal [User Portal]', () => { fireEvent.click(await screen.findByTestId('createBtn')); }); - // await waitFor(() => { - // expect(createBtn).not.toBeInTheDocument(); - // }); + await waitFor(() => { + expect(createBtn).not.toBeInTheDocument(); + }); }, 3000); it('add and remove user', async () => { @@ -2395,6 +5720,9 @@ describe('Testing Create Group Chat Modal [User Portal]', () => { ...UserConnectionListMock, ...CREATE_CHAT_MUTATION, ...CHATS_LIST_MOCK, + ...MARK_CHAT_MESSAGES_AS_READ_MOCK, + ...UNREAD_CHAT_BY_USER_ID_QUERY_MOCK, + ...GROUP_CHAT_LIST_QUERY_MOCK, ]; render( diff --git a/src/components/UserPortal/CreateGroupChat/CreateGroupChat.tsx b/src/components/UserPortal/CreateGroupChat/CreateGroupChat.tsx index e293675a03..f61dcf620d 100644 --- a/src/components/UserPortal/CreateGroupChat/CreateGroupChat.tsx +++ b/src/components/UserPortal/CreateGroupChat/CreateGroupChat.tsx @@ -1,18 +1,9 @@ -import { - FormControl, - InputLabel, - MenuItem, - Paper, - Select, - TableBody, -} from '@mui/material'; -import type { SelectChangeEvent } from '@mui/material/Select'; -import React, { useEffect, useState } from 'react'; +import React, { useEffect, useRef, useState } from 'react'; +import { Paper, TableBody } from '@mui/material'; 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'; @@ -25,6 +16,11 @@ 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'; +import convertToBase64 from 'utils/convertToBase64'; +import Avatar from 'components/Avatar/Avatar'; +import { FiEdit } from 'react-icons/fi'; interface InterfaceCreateGroupChatProps { toggleCreateGroupChatModal: () => void; @@ -35,31 +31,7 @@ interface InterfaceCreateGroupChatProps { 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; - }; - }[]; + ) => Promise>; } /** @@ -94,12 +66,14 @@ export default function CreateGroupChat({ chatsListRefetch, }: InterfaceCreateGroupChatProps): JSX.Element { const userId: string | null = getItem('userId'); + const { t } = useTranslation('translation', { + keyPrefix: 'userChat', + }); const [createChat] = useMutation(CREATE_CHAT); - const [organizations, setOrganizations] = useState([]); - const [selectedOrganization, setSelectedOrganization] = useState(''); const [title, setTitle] = useState(''); + const [description, setDescription] = useState(''); const [userIds, setUserIds] = useState([]); const [addUserModalisOpen, setAddUserModalisOpen] = useState(false); @@ -111,21 +85,11 @@ export default function CreateGroupChat({ 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 }, - }, - ); + const { orgId: currentOrg } = useParams(); function reset(): void { setTitle(''); setUserIds([]); - setSelectedOrganization(''); } useEffect(() => { @@ -135,10 +99,11 @@ export default function CreateGroupChat({ async function handleCreateGroupChat(): Promise { await createChat({ variables: { - organizationId: selectedOrganization, + organizationId: currentOrg, userIds: [userId, ...userIds], name: title, isGroup: true, + image: selectedImage, }, }); chatsListRefetch(); @@ -175,13 +140,23 @@ export default function CreateGroupChat({ }); }; - useEffect(() => { - if (joinedOrganizationsData && joinedOrganizationsData.users.length > 0) { - const organizations = - joinedOrganizationsData.users[0]?.user?.joinedOrganizations || []; - setOrganizations(organizations); + const [selectedImage, setSelectedImage] = useState(null); + + const fileInputRef = useRef(null); + + const handleImageClick = (): void => { + fileInputRef?.current?.click(); + }; + + const handleImageChange = async ( + e: React.ChangeEvent, + ): Promise => { + const file = e.target.files?.[0]; + if (file) { + const base64 = await convertToBase64(file); + setSelectedImage(base64); } - }, [joinedOrganizationsData]); + }; return ( <> @@ -195,44 +170,57 @@ export default function CreateGroupChat({ New Group + +
+ {selectedImage ? ( + + ) : ( + + )} + +
- - Select Organization - - - Group name + Title { setTitle(e.target.value); }} /> + + Description + { + setDescription(e.target.value); + }} + /> + )} @@ -358,7 +346,7 @@ export default function CreateGroupChat({ onClick={handleCreateGroupChat} data-testid="createBtn" > - Create + {t('create')} diff --git a/src/components/UserPortal/UserSidebar/UserSidebar.spec.tsx b/src/components/UserPortal/UserSidebar/UserSidebar.spec.tsx index ac6465a3e6..6435353f89 100644 --- a/src/components/UserPortal/UserSidebar/UserSidebar.spec.tsx +++ b/src/components/UserPortal/UserSidebar/UserSidebar.spec.tsx @@ -426,7 +426,7 @@ describe('UserSidebar Component Tests in User Portal', () => { await wait(); }); - const expectedLinks = ['My Organizations', 'Settings', 'Chat']; + const expectedLinks = ['My Organizations', 'Settings']; expectedLinks.forEach((link) => { expect(screen.getByText(link)).toBeInTheDocument(); }); @@ -483,8 +483,8 @@ describe('UserSidebar Component Tests in User Portal', () => { renderUserSidebar('properId', link); await wait(); }); - const chatBtn = screen.getByTestId('chatBtn'); - fireEvent.click(chatBtn); + const settingsBtn = screen.getByTestId('settingsBtn'); + fireEvent.click(settingsBtn); expect(props.setHideDrawer).toHaveBeenCalledWith(true); }); diff --git a/src/components/UserPortal/UserSidebar/UserSidebar.tsx b/src/components/UserPortal/UserSidebar/UserSidebar.tsx index 5e258f8a8e..010d8d0e52 100644 --- a/src/components/UserPortal/UserSidebar/UserSidebar.tsx +++ b/src/components/UserPortal/UserSidebar/UserSidebar.tsx @@ -4,7 +4,6 @@ import { useTranslation } from 'react-i18next'; import { NavLink } from 'react-router-dom'; import OrganizationsIcon from 'assets/svgs/organizations.svg?react'; import SettingsIcon from 'assets/svgs/settings.svg?react'; -import ChatIcon from 'assets/svgs/chat.svg?react'; import TalawaLogo from 'assets/svgs/talawa.svg?react'; import styles from './UserSidebar.module.css'; @@ -109,28 +108,6 @@ const userSidebar = ({ )} - - {({ isActive }) => ( - - )} -
diff --git a/src/screens/OrganizationEvents/OrganizationEvents.tsx b/src/screens/OrganizationEvents/OrganizationEvents.tsx index 12abb3e74a..71295c1dc9 100644 --- a/src/screens/OrganizationEvents/OrganizationEvents.tsx +++ b/src/screens/OrganizationEvents/OrganizationEvents.tsx @@ -71,6 +71,7 @@ function organizationEvents(): JSX.Element { const [publicchecked, setPublicChecked] = React.useState(true); const [registrablechecked, setRegistrableChecked] = React.useState(false); + const [createChatCheck, setCreateChatCheck] = React.useState(false); const [recurrenceRuleState, setRecurrenceRuleState] = useState({ @@ -476,6 +477,19 @@ function organizationEvents(): JSX.Element { /> +
+
+ + setCreateChatCheck(!createChatCheck)} + /> +
+
{/* Recurrence Options */} {recurringchecked && ( diff --git a/src/screens/UserPortal/Chat/Chat.module.css b/src/screens/UserPortal/Chat/Chat.module.css index 5f9a672dea..aeab28f66c 100644 --- a/src/screens/UserPortal/Chat/Chat.module.css +++ b/src/screens/UserPortal/Chat/Chat.module.css @@ -1,6 +1,6 @@ .containerHeight { - padding: 1rem 1.5rem 0 calc(300px); - height: 100vh; + /* padding: 1rem 1.5rem 0 calc(300px); */ + /* height: 100vh; */ } .expand { @@ -32,7 +32,7 @@ } .containerHeight { - height: 100vh; + height: 88vh; } .mainContainer { @@ -188,8 +188,8 @@ /* For tablets */ @media (max-width: 820px) { .containerHeight { - height: 100vh; - padding: 2rem; + /* height: 100vh; */ + /* padding: 2rem; */ } .contract, @@ -216,3 +216,25 @@ .accordionBody::-webkit-scrollbar { display: none; } + +.filters { + padding: 20px 0px 0px 20px; + display: flex; + gap: 8px; +} + +.filterButton { + border-radius: 14px; + padding: 5px 10px; + background-color: white; + color: #a5a5a5; + border: none; + border: 1px solid #a5a5a5; +} + +.selectedBtn, +.filterButton:hover { + border: 1px solid #98e0b6; + background-color: #98e0b6; + color: rgb(255, 255, 255); +} diff --git a/src/screens/UserPortal/Chat/Chat.spec.tsx b/src/screens/UserPortal/Chat/Chat.spec.tsx index ec8243c823..e691e4151d 100644 --- a/src/screens/UserPortal/Chat/Chat.spec.tsx +++ b/src/screens/UserPortal/Chat/Chat.spec.tsx @@ -1,10 +1,10 @@ import React from 'react'; import { - render, + act, fireEvent, + render, screen, waitFor, - act, } from '@testing-library/react'; import { MockedProvider } from '@apollo/react-testing'; import { BrowserRouter } from 'react-router-dom'; @@ -18,8 +18,16 @@ import { USERS_CONNECTION_LIST, USER_JOINED_ORGANIZATIONS, } from 'GraphQl/Queries/Queries'; -import { MESSAGE_SENT_TO_CHAT } from 'GraphQl/Mutations/OrganizationMutations'; -import { CHATS_LIST, CHAT_BY_ID } from 'GraphQl/Queries/PlugInQueries'; +import { + MARK_CHAT_MESSAGES_AS_READ, + MESSAGE_SENT_TO_CHAT, +} from 'GraphQl/Mutations/OrganizationMutations'; +import { + CHATS_LIST, + CHAT_BY_ID, + GROUP_CHAT_LIST, + UNREAD_CHAT_LIST, +} from 'GraphQl/Queries/PlugInQueries'; import useLocalStorage from 'utils/useLocalstorage'; /** @@ -38,11 +46,6 @@ vi.mock('../../../components/UserPortal/ChatRoom/ChatRoom', () => ({ default: () =>
Mocked ChatRoom
, })); -const resizeWindow = (width: number): void => { - window.innerWidth = width; - fireEvent(window, new Event('resize')); -}; - async function wait(ms = 100): Promise { await act(() => { return new Promise((resolve) => { @@ -52,6 +55,89 @@ async function wait(ms = 100): Promise { } const { setItem } = useLocalStorage(); +const MARK_CHAT_MESSAGES_AS_READ_MOCK = [ + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: null, + chatId: '', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: null, + chatId: '', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: '1', + chatId: '', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: '1', + chatId: '', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, + { + request: { + query: MARK_CHAT_MESSAGES_AS_READ, + variables: { + userId: '1', + chatId: '', + }, + }, + result: { + data: { + markChatMessagesAsRead: { + _id: '1', + }, + }, + }, + }, +]; + const USER_JOINED_ORG_MOCK = [ { request: { @@ -828,6 +914,11 @@ const CHAT_BY_ID_QUERY_MOCK = [ image: '', }, ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + }), }, }, }, @@ -879,34 +970,71 @@ const CHAT_BY_ID_QUERY_MOCK = [ lastName: 'Talreja', email: 'disha@example.com', image: '', - appUserProfile: { - _id: '64378abd85308f171cf2993d', - adminFor: [], - isSuperAdmin: false, - createdOrganizations: [], - createdEvents: [], - eventAdmin: [], - __typename: 'AppUserProfile', - }, - __typename: 'UserData', + }, + { + _id: '2', + firstName: 'Test', + lastName: 'User', + email: 'test@example.com', + image: '', }, ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + }), }, }, }, }, { request: { - query: USERS_CONNECTION_LIST, + query: CHAT_BY_ID, variables: { - firstName_contains: '', - lastName_contains: '', + id: '', }, }, result: { data: { - users: { - user: [ + 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', @@ -915,6 +1043,7 @@ const CHAT_BY_ID_QUERY_MOCK = [ image: '', }, ], + admins: [], }, }, }, @@ -933,7 +1062,8 @@ const CHATS_LIST_MOCK = [ data: { chatsByUserId: [ { - _id: '65844efc814dd40fgh03db811c4', + _id: '65844efc814dd40sassxaasfgh03db811c4', + image: '', isGroup: true, creator: { _id: '64378abd85008f171cf2990d', @@ -1003,10 +1133,27 @@ const CHATS_LIST_MOCK = [ image: '', }, ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), }, { - _id: '65844efc814ddgh4003db811c4', + _id: '65844efc8q14ddgh4003db811c4', isGroup: true, + image: '', creator: { _id: '64378abd85008f171cf2990d', firstName: 'Wilt', @@ -1075,6 +1222,14 @@ const CHATS_LIST_MOCK = [ image: '', }, ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), }, ], }, @@ -1091,8 +1246,9 @@ const CHATS_LIST_MOCK = [ data: { chatsByUserId: [ { - _id: '65844ghjefc814dd4003db811c4', + _id: '65844efc814dd40fgh03db811c4', isGroup: true, + image: '', creator: { _id: '64378abd85008f171cf2990d', firstName: 'Wilt', @@ -1161,10 +1317,27 @@ const CHATS_LIST_MOCK = [ image: '', }, ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), }, { - _id: 'ujhgtrdtyuiop', + _id: '65844efc814ddgh4003db811c4', isGroup: true, + image: '', creator: { _id: '64378abd85008f171cf2990d', firstName: 'Wilt', @@ -1233,6 +1406,14 @@ const CHATS_LIST_MOCK = [ image: '', }, ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), }, ], }, @@ -1242,15 +1423,16 @@ const CHATS_LIST_MOCK = [ request: { query: CHATS_LIST, variables: { - id: '1', + id: null, }, }, result: { data: { chatsByUserId: [ { - _id: '65844efc814dhjmkdftyd4003db811c4', + _id: '65844efc814dd40fggfdh03db811c4', isGroup: true, + image: '', creator: { _id: '64378abd85008f171cf2990d', firstName: 'Wilt', @@ -1319,10 +1501,27 @@ const CHATS_LIST_MOCK = [ image: '', }, ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), }, { - _id: '65844ewsedrffc814dd4003db811c4', + _id: '65844efc814ddgh4003db811c4', isGroup: true, + image: '', creator: { _id: '64378abd85008f171cf2990d', firstName: 'Wilt', @@ -1391,95 +1590,2652 @@ const CHATS_LIST_MOCK = [ image: '', }, ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), }, ], }, }, }, -]; - -const GROUP_CHAT_BY_ID_QUERY_MOCK = [ { request: { - query: CHAT_BY_ID, + query: CHATS_LIST, variables: { - id: '', + id: null, }, }, 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: { + chatsByUserId: [ + { + _id: '65844efc814dd40wasxfgh03db811c4', + isGroup: true, + image: '', + 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + { + _id: '65844efc814ddgh4003db811c4', + isGroup: true, + image: '', + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: '', + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844ghjefc814dd4003db811c4', + isGroup: true, + image: '', + 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + { + _id: 'ujhgtrdtyuiop', + isGroup: true, + image: '', + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: '1', + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844efc814dhjmkdftyd4003db811c4', + isGroup: true, + image: '', + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + { + _id: '65844ewsedrffc814dd4003db811c4', + isGroup: true, + image: '', + 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: '1', + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844efc814dhjmkdftyd4003db811c4', + isGroup: true, + image: '', + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + { + _id: '65844ewsedrffc814dd4003db811c4', + isGroup: true, + image: '', + 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: '1', + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844efc814dhjmkdftyd4003db811c4', + isGroup: true, + image: '', + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + { + _id: '65844ewsedrffc814dd4003db811c4', + isGroup: true, + image: '', + 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: CHATS_LIST, + variables: { + id: '1', + }, + }, + result: { + data: { + chatsByUserId: [ + { + _id: '65844efc814dhjmkdftyd4003db811c4', + isGroup: true, + image: '', + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + { + _id: '65844ewsedrffc814dd4003db811c4', + isGroup: true, + image: '', + 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, +]; + +const GROUP_CHAT_BY_ID_QUERY_MOCK = [ + { + request: { + query: CHAT_BY_ID, + variables: { + id: '', + }, + }, + result: { + data: { + chatById: { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: '', + 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, + media: 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + }, + }, + }, +]; + +const UNREAD_CHAT_LIST_QUERY_MOCK = [ + { + request: { + query: UNREAD_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getUnreadChatsByUserId: [ + { + _id: '1', + createdAt: '2345678903456', + isGroup: false, + image: '', + 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, + media: 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + ], + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getUnreadChatsByUserId: [ + { + _id: '1', + createdAt: '2345678903456', + isGroup: false, + image: '', + 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, + media: 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + ], + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getUnreadChatsByUserId: [ + { + _id: '1', + createdAt: '2345678903456', + isGroup: false, + image: '', + 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, + media: 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + ], + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getUnreadChatsByUserId: [ + { + _id: '1', + createdAt: '2345678903456', + isGroup: false, + image: '', + 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, + media: 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + ], + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: { + id: '1', + }, + }, + result: { + data: { + getUnreadChatsByUserId: [ + { + _id: '1', + createdAt: '2345678903456', + isGroup: false, + image: '', + 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, + media: 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + ], + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: { + id: '1', + }, + }, + result: { + data: { + getUnreadChatsByUserId: [ + { + _id: '1', + createdAt: '2345678903456', + isGroup: false, + image: '', + 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, + media: 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + ], + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: { + id: '1', + }, + }, + result: { + data: { + getUnreadChatsByUserId: [ + { + _id: '1', + createdAt: '2345678903456', + isGroup: false, + image: '', + 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, + media: 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + ], + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + getUnreadChatsByUserId: [ + { + _id: '1', + createdAt: '2345678903456', + isGroup: false, + image: '', + 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, + media: 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + ], + }, + }, + }, + { + request: { + query: UNREAD_CHAT_LIST, + variables: { + id: null, + }, + }, + result: { + data: { + getUnreadChatsByUserId: [ + { + _id: '1', + createdAt: '2345678903456', + isGroup: false, + image: '', + 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, + media: 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: '', + }, + ], + admins: [], + unseenMessagesByUsers: JSON.stringify({ + '1': 0, + '2': 0, + }), + }, + ], + }, + }, + }, +]; + +const GROUP_CHAT_LIST_QUERY_MOCK = [ + { + request: { + query: GROUP_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getGroupChatsByUserId: [ + { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: '', + 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, + media: 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: GROUP_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getGroupChatsByUserId: [ + { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: '', + 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', + media: null, + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: GROUP_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getGroupChatsByUserId: [ + { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: '', + 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, + media: 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: GROUP_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getGroupChatsByUserId: [ + { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: '', + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', }, - ], - users: [ - { - _id: '1', - firstName: 'Disha', - lastName: 'Talreja', - email: 'disha@example.com', - image: '', - }, - { - _id: '2', - firstName: 'Test', - lastName: 'User', - email: 'test@example.com', - image: '', + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', + }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + type: 'STRING', + media: null, + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: GROUP_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getGroupChatsByUserId: [ + { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: '', + 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', + media: null, + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: GROUP_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getGroupChatsByUserId: [ + { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: '', + 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, + media: 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: GROUP_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getGroupChatsByUserId: [ + { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: '', + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', }, - { - _id: '3', - firstName: 'Test', - lastName: 'User1', - email: 'test1@example.com', - image: '', + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', }, - { - _id: '4', - firstName: 'Test', - lastName: 'User2', - email: 'test2@example.com', - image: '', + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + media: null, + 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], + }, + }, + }, + { + request: { + query: GROUP_CHAT_LIST, + variables: {}, + }, + result: { + data: { + getGroupChatsByUserId: [ + { + _id: '65844efc814dd4003db811c4', + isGroup: true, + image: '', + creator: { + _id: '64378abd85008f171cf2990d', + firstName: 'Wilt', + lastName: 'Shepherd', + image: null, + email: 'testsuperadmin@example.com', + createdAt: '2023-04-13T04:53:17.742Z', + __typename: 'User', }, - { - _id: '5', - firstName: 'Test', - lastName: 'User4', - email: 'test4@example.com', - image: '', + organization: { + _id: 'pw3ertyuiophgfre45678', + name: 'rtyu', }, - ], - }, + createdAt: '2345678903456', + name: 'Test Group Chat', + messages: [ + { + _id: '345678', + createdAt: '345678908765', + messageContent: 'Hello', + replyTo: null, + media: 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: '', + }, + ], + admins: [ + { + _id: '1', + firstName: 'Disha', + lastName: 'Talreja', + email: 'disha@example.com', + image: '', + }, + ], + unseenMessagesByUsers: JSON.stringify({ + '1': 1, + '2': 1, + '3': 1, + '4': 1, + '5': 1, + }), + }, + ], }, }, }, @@ -1500,18 +4256,6 @@ describe('Testing Chat Screen [User Portal]', () => { })), }); - // Define mock data outside of tests to reuse - const mock = [ - ...USER_JOINED_ORG_MOCK, - ...GROUP_CHAT_BY_ID_QUERY_MOCK, - ...MESSAGE_SENT_TO_CHAT_MOCK, - ...MESSAGE_SENT_TO_CHAT_MOCK, - ...UserConnectionListMock, - ...CHAT_BY_ID_QUERY_MOCK, - ...CHATS_LIST_MOCK, - ...UserConnectionListMock, - ]; - beforeEach(() => { setItem('userId', '1'); vi.clearAllMocks(); @@ -1523,6 +4267,20 @@ describe('Testing Chat Screen [User Portal]', () => { localStorage.clear(); }); + const mock = [ + ...USER_JOINED_ORG_MOCK, + ...GROUP_CHAT_BY_ID_QUERY_MOCK, + ...MESSAGE_SENT_TO_CHAT_MOCK, + ...MESSAGE_SENT_TO_CHAT_MOCK, + ...UserConnectionListMock, + ...CHAT_BY_ID_QUERY_MOCK, + ...CHATS_LIST_MOCK, + ...UserConnectionListMock, + ...UNREAD_CHAT_LIST_QUERY_MOCK, + ...GROUP_CHAT_LIST_QUERY_MOCK, + ...MARK_CHAT_MESSAGES_AS_READ_MOCK, + ]; + test('Screen should be rendered properly', async () => { render( @@ -1538,7 +4296,7 @@ describe('Testing Chat Screen [User Portal]', () => { await wait(); }); - it('User is able to select a contact', async () => { + test('User is able to select a contact', async () => { render( @@ -1616,11 +4374,13 @@ describe('Testing Chat Screen [User Portal]', () => { const closeButton = screen.getByRole('button', { name: /close/i }); expect(closeButton).toBeInTheDocument(); - fireEvent.click(closeButton); }); - test('sidebar', async () => { + // filter chat test + test('Testing chat filters', async () => { + setItem('userId', '1'); + render( @@ -1632,44 +4392,23 @@ describe('Testing Chat Screen [User Portal]', () => { , ); - screen.debug(); await waitFor(async () => { - const closeMenuBtn = await screen.findByTestId('closeMenu'); - expect(closeMenuBtn).toBeInTheDocument(); - if (closeMenuBtn) { - closeMenuBtn.click(); - } else { - throw new Error('Close menu button not found'); - } + expect(await screen.findByTestId('unreadChat')).toBeInTheDocument(); + }); + await act(async () => { + fireEvent.click(await screen.findByTestId('unreadChat')); }); - }); - - test('Testing sidebar when the screen size is less than or equal to 820px', async () => { - // Resize window for mobile view (<= 820px) - resizeWindow(800); - render( - - - - - - - - - , - ); + await wait(1000); - await waitFor(() => { - expect(screen.getByText('My Organizations')).toBeInTheDocument(); - expect(screen.getByText('Talawa User Portal')).toBeInTheDocument(); + await act(async () => { + fireEvent.click(await screen.findByTestId('groupChat')); }); - const openMenuBtn = await screen.findByTestId('openMenu'); - expect(openMenuBtn).toBeInTheDocument(); - fireEvent.click(openMenuBtn); + await wait(1000); - const closeMenuBtn = await screen.findByTestId('closeMenu'); - expect(closeMenuBtn).toBeInTheDocument(); + await act(async () => { + fireEvent.click(await screen.findByTestId('allChat')); + }); }); }); diff --git a/src/screens/UserPortal/Chat/Chat.tsx b/src/screens/UserPortal/Chat/Chat.tsx index 441ce7d4ba..0155f3ee0a 100644 --- a/src/screens/UserPortal/Chat/Chat.tsx +++ b/src/screens/UserPortal/Chat/Chat.tsx @@ -1,18 +1,21 @@ import React, { useEffect, useState } from 'react'; -import { useQuery } from '@apollo/client'; +import { useMutation, useQuery } from '@apollo/client'; import { useTranslation } from 'react-i18next'; import { Button, Dropdown } from 'react-bootstrap'; -import { SearchOutlined, Search } from '@mui/icons-material'; import HourglassBottomIcon from '@mui/icons-material/HourglassBottom'; import ContactCard from 'components/UserPortal/ContactCard/ContactCard'; import ChatRoom from 'components/UserPortal/ChatRoom/ChatRoom'; import useLocalStorage from 'utils/useLocalstorage'; import NewChat from 'assets/svgs/newChat.svg?react'; import styles from './Chat.module.css'; -import UserSidebar from 'components/UserPortal/UserSidebar/UserSidebar'; -import { CHATS_LIST } from 'GraphQl/Queries/PlugInQueries'; +import { + CHATS_LIST, + GROUP_CHAT_LIST, + UNREAD_CHAT_LIST, +} from 'GraphQl/Queries/PlugInQueries'; import CreateGroupChat from '../../../components/UserPortal/CreateGroupChat/CreateGroupChat'; import CreateDirectChat from 'components/UserPortal/CreateDirectChat/CreateDirectChat'; +import { MARK_CHAT_MESSAGES_AS_READ } from 'GraphQl/Mutations/OrganizationMutations'; interface InterfaceContactCardProps { id: string; @@ -21,6 +24,8 @@ interface InterfaceContactCardProps { selectedContact: string; setSelectedContact: React.Dispatch>; isGroup: boolean; + unseenMessages: number; + lastMessage: string; } /** * The `chat` component provides a user interface for interacting with contacts and chat rooms within an organization. @@ -48,15 +53,62 @@ interface InterfaceContactCardProps { * * @returns The rendered `chat` component. */ + +type DirectMessage = { + _id: string; + createdAt: Date; + sender: { + _id: string; + firstName: string; + lastName: string; + image: string; + }; + replyTo: + | { + _id: string; + createdAt: Date; + sender: { + _id: string; + firstName: string; + lastName: string; + image: string; + }; + messageContent: string; + receiver: { + _id: string; + firstName: string; + lastName: string; + }; + } + | undefined; + messageContent: string; +}; + +type Chat = { + _id: string; + isGroup: boolean; + name: string; + image: string; + messages: DirectMessage[]; + users: { + _id: string; + firstName: string; + lastName: string; + email: string; + image: string; + }[]; + unseenMessagesByUsers: string; +}; export default function chat(): JSX.Element { const { t } = useTranslation('translation', { - keyPrefix: 'chat', + keyPrefix: 'userChat', }); const { t: tCommon } = useTranslation('common'); const [hideDrawer, setHideDrawer] = useState(null); - const [chats, setChats] = useState([]); + const [chats, setChats] = useState([]); const [selectedContact, setSelectedContact] = useState(''); + const [filterType, setFilterType] = useState('all'); const { getItem } = useLocalStorage(); const userId = getItem('userId'); @@ -74,6 +126,25 @@ export default function chat(): JSX.Element { }; }, []); + React.useEffect(() => { + if (filterType === 'all') { + chatsListRefetch(); + if (chatsListData && chatsListData.chatsByUserId) { + setChats(chatsListData.chatsByUserId); + } + } else if (filterType === 'unread') { + unreadChatListRefetch(); + if (unreadChatListData && unreadChatListData.getUnreadChatsByUserId) { + setChats(unreadChatListData.getUnreadChatsByUserId); + } + } else if (filterType === 'group') { + groupChatListRefetch(); + if (groupChatListData && groupChatListData.getGroupChatsByUserId) { + setChats(groupChatListData.getGroupChatsByUserId); + } + } + }, [filterType]); + const [createDirectChatModalisOpen, setCreateDirectChatModalisOpen] = useState(false); @@ -105,60 +176,40 @@ export default function chat(): JSX.Element { }, }); + const { data: groupChatListData, refetch: groupChatListRefetch } = + useQuery(GROUP_CHAT_LIST); + + const { data: unreadChatListData, refetch: unreadChatListRefetch } = + useQuery(UNREAD_CHAT_LIST); + + const [markChatMessagesAsRead] = useMutation(MARK_CHAT_MESSAGES_AS_READ, { + variables: { + chatId: selectedContact, + userId: userId, + }, + }); + + useEffect(() => { + markChatMessagesAsRead().then(() => { + chatsListRefetch({ id: userId }); + }); + }, [selectedContact]); + React.useEffect(() => { - if (chatsListData) { + if (chatsListData && chatsListData?.chatsByUserId.length) { setChats(chatsListData.chatsByUserId); } }, [chatsListData]); - // const handleSearch = (value: string): void => { - // setFilterName(value); - - // contactRefetch(); - // }; - // const handleSearchByEnter = (e: any): void => { - // if (e.key === 'Enter') { - // const { value } = e.target; - // handleSearch(value); - // } - // }; - // const handleSearchByBtnClick = (): void => { - // const value = - // (document.getElementById('searchChats') as HTMLInputElement)?.value || ''; - // handleSearch(value); - // }; - return ( <> - {hideDrawer ? ( - - ) : ( - - )} -
-

Messages

+

{t('messages')}

- New Chat + {t('newChat')} - New Group Chat + {t('newGroupChat')} Starred Messages @@ -188,45 +239,102 @@ export default function chat(): JSX.Element {
{chatsListLoading ? (
- Loading... + {tCommon('loading')}
) : ( -
- {!!chats.length && - chats.map((chat: any) => { - const cardProps: InterfaceContactCardProps = { - id: chat._id, - title: !chat.isGroup - ? chat.users[0]?._id === userId - ? `${chat.users[1]?.firstName} ${chat.users[1]?.lastName}` - : `${chat.users[0]?.firstName} ${chat.users[0]?.lastName}` - : chat.name, - image: chat.isGroup - ? userId - ? chat.users[1]?.image - : chat.users[0]?.image - : chat.image, - setSelectedContact, - selectedContact, - isGroup: chat.isGroup, - }; - return ( - - ); - })} -
+ <> +
+ {/* three buttons to filter unread, all and group chats. All selected by default. */} + + + +
+ +
+ {!!chats.length && + chats.map((chat: Chat) => { + const cardProps: InterfaceContactCardProps = { + id: chat._id, + title: !chat.isGroup + ? chat.users[0]?._id === userId + ? `${chat.users[1]?.firstName} ${chat.users[1]?.lastName}` + : `${chat.users[0]?.firstName} ${chat.users[0]?.lastName}` + : chat.name, + image: chat.isGroup + ? chat.image + : userId + ? chat.users[1]?.image + : chat.users[0]?.image, + setSelectedContact, + selectedContact, + isGroup: chat.isGroup, + unseenMessages: JSON.parse( + chat.unseenMessagesByUsers, + )[userId], + lastMessage: + chat.messages[chat.messages.length - 1] + ?.messageContent, + }; + return ( + + ); + })} +
+ )}
- +
diff --git a/src/screens/UserPortal/Events/Events.module.css b/src/screens/UserPortal/Events/Events.module.css deleted file mode 100644 index eadbf63d0f..0000000000 --- a/src/screens/UserPortal/Events/Events.module.css +++ /dev/null @@ -1,156 +0,0 @@ -.borderNone { - border: none; -} - -.colorWhite { - color: white; -} - -.backgroundWhite { - background-color: white; -} - -.maxWidth { - max-width: 800px; -} - -.mainContainer { - margin-top: 2rem; - width: 50%; - flex-grow: 3; - max-height: 100%; - overflow: auto; -} - -.content { - height: fit-content; - min-height: calc(100% - 40px); -} -.selectType { - border-radius: 10px; -} -.dropdown__item { - text-overflow: ellipsis; - overflow: hidden; - white-space: nowrap; -} - -.gap { - gap: 20px; -} - -.paddingY { - padding: 30px 0px; -} - -.colorPrimary { - background: #31bb6b; - color: white; -} - -.eventActionsContainer { - display: flex; - flex-direction: row; - gap: 15px; -} - -.datePicker { - border-radius: 10px; - height: 40px; - text-align: center; - background-color: #f2f2f2; - border: none; - width: 100%; -} - -.modalBody { - display: flex; - flex-direction: column; - gap: 10px; -} - -.switchContainer { - display: flex; - align-items: center; -} - -.switches { - display: flex; - flex-direction: row; - gap: 20px; - flex-wrap: wrap; - margin-top: 20px; -} -.titlemodal { - color: #707070; - font-weight: 600; - font-size: 20px; - margin-bottom: 20px; - padding-bottom: 5px; - border-bottom: 3px solid #31bb6b; - width: 65%; -} - -.datediv { - display: flex; - flex-direction: row; - margin-bottom: 15px; -} - -.datebox { - width: 90%; - border-radius: 7px; - border-color: #e8e5e5; - outline: none; - box-shadow: none; - padding-top: 2px; - padding-bottom: 2px; - padding-right: 5px; - padding-left: 5px; - margin-right: 5px; - margin-left: 5px; -} - -.checkboxdiv > label { - margin-right: 50px; -} -.checkboxdiv > label > input { - margin-left: 10px; -} - -.checkboxdiv { - display: flex; -} -.checkboxdiv > div { - width: 50%; -} - -.dispflex { - display: flex; - align-items: center; -} -.dispflex > input { - border: none; - box-shadow: none; - margin-top: 5px; -} - -.greenregbtn { - margin: 1rem 0 0; - margin-top: 15px; - border: 1px solid #e8e5e5; - box-shadow: 0 2px 2px #e8e5e5; - padding: 10px 10px; - border-radius: 5px; - background-color: #31bb6b; - width: 100%; - font-size: 16px; - color: white; - outline: none; - font-weight: 600; - cursor: pointer; - transition: - transform 0.2s, - box-shadow 0.2s; - width: 100%; -} diff --git a/src/screens/UserPortal/Events/Events.spec.tsx b/src/screens/UserPortal/Events/Events.spec.tsx index 646f5052f0..0e49402019 100644 --- a/src/screens/UserPortal/Events/Events.spec.tsx +++ b/src/screens/UserPortal/Events/Events.spec.tsx @@ -98,6 +98,7 @@ const MOCKS = [ recurring: false, isPublic: true, isRegisterable: false, + createChat: false, creator: { _id: '63d649417ffe6e4d5174ea32', firstName: 'Noble', @@ -129,6 +130,7 @@ const MOCKS = [ recurring: false, isPublic: true, isRegisterable: true, + createChat: true, creator: { _id: '63d649417ffe6e4d5174ea32', firstName: 'Noble', @@ -179,6 +181,7 @@ const MOCKS = [ recurring: false, isPublic: true, isRegisterable: false, + createChat: false, creator: { _id: '63d649417ffe6e4d5174ea32', firstName: 'Noble', @@ -207,13 +210,95 @@ const MOCKS = [ variables: { title: 'testEventTitle', description: 'testEventDescription', + isPublic: true, + recurring: false, + isRegisterable: true, + organizationId: '', + startDate: dayjs(new Date()).format('YYYY-MM-DD'), + endDate: dayjs(new Date()).format('YYYY-MM-DD'), + allDay: true, location: 'testEventLocation', + startTime: null, + endTime: null, + createChat: false, + }, + }, + result: { + data: { + createEvent: { + _id: '2', + }, + }, + }, + }, + { + request: { + query: CREATE_EVENT_MUTATION, + variables: { + title: 'testEventTitle', + description: 'testEventDescription', + isPublic: true, + recurring: false, + isRegisterable: true, + organizationId: '', + startDate: dayjs(new Date()).format('YYYY-MM-DD'), + endDate: dayjs(new Date()).format('YYYY-MM-DD'), + allDay: true, + location: 'testEventLocation', + startTime: null, + endTime: null, + createChat: false, + }, + }, + result: { + data: { + createEvent: { + _id: '2', + }, + }, + }, + }, + { + request: { + query: CREATE_EVENT_MUTATION, + variables: { + title: 'testEventTitle', + description: 'testEventDescription', isPublic: true, recurring: false, isRegisterable: true, organizationId: '', startDate: dayjs(new Date()).format('YYYY-MM-DD'), endDate: dayjs(new Date()).format('YYYY-MM-DD'), + allDay: true, + location: 'testEventLocation', + startTime: null, + endTime: null, + createChat: false, + }, + }, + result: { + data: { + createEvent: { + _id: '2', + }, + }, + }, + }, + { + request: { + query: CREATE_EVENT_MUTATION, + variables: { + title: 'testEventTitle', + description: 'testEventDescription', + location: 'testEventLocation', + isPublic: true, + recurring: false, + isRegisterable: true, + createChat: false, + organizationId: '', + startDate: dayjs(new Date()).format('YYYY-MM-DD'), + endDate: dayjs(new Date()).format('YYYY-MM-DD'), allDay: false, startTime: '08:00:00', endTime: '10:00:00', @@ -233,13 +318,149 @@ const MOCKS = [ variables: { title: 'testEventTitle', description: 'testEventDescription', + isPublic: true, + recurring: false, + isRegisterable: true, + organizationId: '', + startDate: '2024-10-27', + endDate: '2024-10-27', + allDay: false, location: 'testEventLocation', + startTime: '08:00:00Z', + endTime: '10:00:00Z', + createChat: false, + }, + }, + result: { + data: { + createEvent: { + _id: '2', + }, + }, + }, + }, + { + request: { + query: CREATE_EVENT_MUTATION, + variables: { + title: 'testEventTitle', + description: 'testEventDescription', isPublic: true, recurring: false, isRegisterable: true, organizationId: '', startDate: dayjs(new Date()).format('YYYY-MM-DD'), endDate: dayjs(new Date()).format('YYYY-MM-DD'), + allDay: false, + location: 'testEventLocation', + startTime: '08:00:00Z', + endTime: '10:00:00Z', + createChat: false, + }, + }, + result: { + data: { + createEvent: { + _id: '2', + }, + }, + }, + }, + { + request: { + query: CREATE_EVENT_MUTATION, + variables: { + title: 'testEventTitle', + description: 'testEventDescription', + isPublic: true, + recurring: false, + isRegisterable: true, + organizationId: '', + startDate: dayjs(new Date()).format('YYYY-MM-DD'), + endDate: dayjs(new Date()).format('YYYY-MM-DD'), + allDay: false, + location: 'testEventLocation', + startTime: '08:00:00Z', + endTime: '10:00:00Z', + createChat: false, + }, + }, + result: { + data: { + createEvent: { + _id: '2', + }, + }, + }, + }, + { + request: { + query: CREATE_EVENT_MUTATION, + variables: { + title: 'testEventTitle', + description: 'testEventDescription', + location: 'testEventLocation', + isPublic: true, + recurring: false, + isRegisterable: true, + createChat: false, + organizationId: '', + startDate: dayjs(new Date()).format('YYYY-MM-DD'), + endDate: dayjs(new Date()).format('YYYY-MM-DD'), + allDay: false, + startTime: '08:00:00', + endTime: '10:00:00', + }, + }, + result: { + data: { + createEvent: { + _id: '2', + }, + }, + }, + }, + { + request: { + query: CREATE_EVENT_MUTATION, + variables: { + title: 'testEventTitle', + description: 'testEventDescription', + location: 'testEventLocation', + isPublic: true, + recurring: false, + isRegisterable: true, + createChat: false, + organizationId: '', + startDate: dayjs(new Date()).format('YYYY-MM-DD'), + endDate: dayjs(new Date()).format('YYYY-MM-DD'), + allDay: false, + startTime: '08:00:00', + endTime: '10:00:00', + }, + }, + result: { + data: { + createEvent: { + _id: '2', + }, + }, + }, + }, + { + request: { + query: CREATE_EVENT_MUTATION, + variables: { + title: 'testEventTitle', + description: 'testEventDescription', + location: 'testEventLocation', + isPublic: true, + recurring: false, + isRegisterable: true, + createChat: true, + organizationId: '', + startDate: dayjs(new Date()).format('YYYY-MM-DD'), + endDate: dayjs(new Date()).format('YYYY-MM-DD'), allDay: true, startTime: null, endTime: null, @@ -346,6 +567,9 @@ describe('Testing Events Screen [User Portal]', () => { userEvent.click(screen.getByTestId('recurringEventCheck')); userEvent.click(screen.getByTestId('recurringEventCheck')); + userEvent.click(screen.getByTestId('createChatCheck')); + userEvent.click(screen.getByTestId('createChatCheck')); + userEvent.click(screen.getByTestId('allDayEventCheck')); userEvent.click(screen.getByTestId('createEventBtn')); diff --git a/src/screens/UserPortal/Events/Events.tsx b/src/screens/UserPortal/Events/Events.tsx index d3fabf9469..a6862c0a73 100644 --- a/src/screens/UserPortal/Events/Events.tsx +++ b/src/screens/UserPortal/Events/Events.tsx @@ -19,7 +19,7 @@ import { toast } from 'react-toastify'; import { ViewType } from 'screens/OrganizationEvents/OrganizationEvents'; import { errorHandler } from 'utils/errorHandler'; import useLocalStorage from 'utils/useLocalstorage'; -import styles from './Events.module.css'; +import styles from './../../../style/app.module.css'; /** * Converts a time string to a Dayjs object. @@ -63,6 +63,7 @@ export default function events(): JSX.Element { const [endTime, setEndTime] = React.useState('10:00:00'); const [viewType, setViewType] = React.useState(ViewType.MONTH); const [createEventModal, setCreateEventmodalisOpen] = React.useState(false); + const [createChatCheck, setCreateChatCheck] = React.useState(false); const { orgId: organizationId } = useParams(); // Query to fetch events for the organization @@ -115,8 +116,9 @@ export default function events(): JSX.Element { endDate: dayjs(endDate).format('YYYY-MM-DD'), allDay: isAllDay, location: eventLocation, - startTime: !isAllDay ? startTime : null, - endTime: !isAllDay ? endTime : null, + startTime: !isAllDay ? startTime + 'Z' : null, + endTime: !isAllDay ? endTime + 'Z' : null, + createChat: createChatCheck, }, }); @@ -134,6 +136,7 @@ export default function events(): JSX.Element { } setCreateEventmodalisOpen(false); } catch (error: unknown) { + console.error('create event error', error); /* istanbul ignore next */ errorHandler(t, error); } @@ -236,7 +239,7 @@ export default function events(): JSX.Element {
-

{t('eventDetails')}

+

{t('eventDetails')}