From fc49994041c90207189aaa3ac3a162f5027c36e9 Mon Sep 17 00:00:00 2001 From: Aad1tya27 Date: Tue, 24 Dec 2024 06:05:53 +0530 Subject: [PATCH 1/6] added tests for users.tsx --- src/screens/Users/Users.test.tsx | 63 +++++++++++++------------------- src/screens/Users/Users.tsx | 42 +++++++++++++-------- 2 files changed, 52 insertions(+), 53 deletions(-) diff --git a/src/screens/Users/Users.test.tsx b/src/screens/Users/Users.test.tsx index 65558e6ea7..3e4f6983c4 100644 --- a/src/screens/Users/Users.test.tsx +++ b/src/screens/Users/Users.test.tsx @@ -30,7 +30,7 @@ const MOCK_USERS = [ lastName: 'Doe', image: null, email: 'john@example.com', - createdAt: '20/06/2022', + createdAt: '2023-04-13T04:53:17.742+00:00', registeredEvents: [], membershipRequests: [], organizationsBlockedBy: [ @@ -106,7 +106,7 @@ const MOCK_USERS = [ lastName: 'Doe', image: null, email: 'john@example.com', - createdAt: '21/06/2022', + createdAt: '2023-04-17T04:53:17.742+00:00', registeredEvents: [], membershipRequests: [], organizationsBlockedBy: [ @@ -182,7 +182,7 @@ const MOCK_USERS = [ lastName: 'Smith', image: null, email: 'jack@example.com', - createdAt: '19/06/2022', + createdAt: '2023-04-09T04:53:17.742+00:00', registeredEvents: [], membershipRequests: [], organizationsBlockedBy: [ @@ -301,6 +301,7 @@ beforeEach(() => { afterEach(() => { localStorage.clear(); + jest.clearAllMocks(); }); describe('Testing Users screen', () => { @@ -701,7 +702,7 @@ describe('Testing Users screen', () => { expect(screen.getByText('Jack Smith')).toBeInTheDocument(); }); - test('Users should be sorted and filtered correctly', async () => { + test('Users should be sorted in newest order correctly', async () => { await act(async () => { render( @@ -718,61 +719,49 @@ describe('Testing Users screen', () => { }); await wait(); - // Check if the sorting and filtering logic was applied correctly - const rows = screen.getAllByRole('row'); - - const firstRow = rows[1]; - const secondRow = rows[2]; - - expect(firstRow).toHaveTextContent('John Doe'); - expect(secondRow).toHaveTextContent('Jane Doe'); - - await wait(); - const inputText = screen.getByTestId('sortUsers'); await act(async () => { fireEvent.click(inputText); }); - const toggleText = screen.getByTestId('oldest'); - - await act(async () => { - fireEvent.click(toggleText); - fireEvent.click(inputText); - }); - const toggleTite = screen.getByTestId('newest'); await act(async () => { fireEvent.click(toggleTite); }); - // Verify the users are sorted by oldest - await wait(); + // Verify the users are sorted by newest const displayedUsers = screen.getAllByRole('row'); - expect(displayedUsers[1]).toHaveTextContent('John Doe'); // assuming User1 is the oldest - expect(displayedUsers[displayedUsers.length - 1]).toHaveTextContent( - 'Jack Smith', - ); // assuming UserN is the newest - await wait(); + expect(displayedUsers[1]).toHaveTextContent('Jane Doe'); + expect(displayedUsers[2]).toHaveTextContent('John Doe'); + }); + test('Check if pressing enter key triggers search', async () => { await act(async () => { - fireEvent.click(inputText); + render( + + + + + + + + + + , + ); }); - - const toggleOld = screen.getByTestId('oldest'); + await wait(); + const searchInput = screen.getByTestId('searchByName'); await act(async () => { - fireEvent.click(toggleOld); - fireEvent.click(inputText); + userEvent.type(searchInput, 'John'); }); - - const toggleNewest = screen.getByTestId('newest'); await act(async () => { - fireEvent.click(toggleNewest); + userEvent.type(searchInput, '{enter}'); }); }); }); diff --git a/src/screens/Users/Users.tsx b/src/screens/Users/Users.tsx index b046679a00..74656fa4c0 100644 --- a/src/screens/Users/Users.tsx +++ b/src/screens/Users/Users.tsx @@ -122,13 +122,14 @@ const Users = (): JSX.Element => { if (!usersData) { return; } - if (usersData.users.length < perPageResult) { - setHasMore(false); - } if (usersData && usersData.users) { + // console.log(sortingOption) let newDisplayedUsers = sortUsers(usersData.users, sortingOption); newDisplayedUsers = filterUsers(newDisplayedUsers, filteringOption); setDisplayedUsers(newDisplayedUsers); + if (newDisplayedUsers.length < perPageResult) { + setHasMore(false); + } } }, [usersData, sortingOption, filteringOption]); @@ -212,8 +213,7 @@ const Users = (): JSX.Element => { setIsLoadingMore(true); fetchMore({ variables: { - skip: usersData?.users.length || 0, - userType: 'ADMIN', + skip: displayedUsers.length || 0, filter: searchByName, order: sortingOption === 'newest' ? 'createdAt_DESC' : 'createdAt_ASC', }, @@ -230,17 +230,24 @@ const Users = (): JSX.Element => { if (fetchMoreResult.users.length < perPageResult) { setHasMore(false); } - return { - users: [...(prev?.users || []), ...fetchMoreResult.users], - }; + const mergedUsers = [...(prev?.users || []), ...fetchMoreResult.users]; + + const uniqueUsers = Array.from( + new Map(mergedUsers.map((user) => [user.user._id, user])).values(), + ); + + return { users: uniqueUsers }; }, }); }; const handleSorting = (option: string): void => { - setDisplayedUsers([]); + if (option === sortingOption) { + return; + } setHasMore(true); setSortingOption(option); + setDisplayedUsers([]); }; const sortUsers = ( @@ -256,19 +263,22 @@ const Users = (): JSX.Element => { new Date(a.user.createdAt).getTime(), ); return sortedUsers; - } else { - sortedUsers.sort( - (a, b) => - new Date(a.user.createdAt).getTime() - - new Date(b.user.createdAt).getTime(), - ); - return sortedUsers; } + sortedUsers.sort( + (a, b) => + new Date(a.user.createdAt).getTime() - + new Date(b.user.createdAt).getTime(), + ); + return sortedUsers; }; const handleFiltering = (option: string): void => { + if (option === filteringOption) { + return; + } setDisplayedUsers([]); setFilteringOption(option); + setHasMore(true); }; const filterUsers = ( From ceda26480e15ef584e1ca025772c763016634b50 Mon Sep 17 00:00:00 2001 From: Aad1tya27 Date: Tue, 24 Dec 2024 21:13:37 +0530 Subject: [PATCH 2/6] shifted to vitest and added some tests --- .../Users/{Users.test.tsx => Users.spec.tsx} | 198 ++++++++++++++++-- src/screens/Users/Users.tsx | 68 ++++-- 2 files changed, 225 insertions(+), 41 deletions(-) rename src/screens/Users/{Users.test.tsx => Users.spec.tsx} (77%) diff --git a/src/screens/Users/Users.test.tsx b/src/screens/Users/Users.spec.tsx similarity index 77% rename from src/screens/Users/Users.test.tsx rename to src/screens/Users/Users.spec.tsx index 3e4f6983c4..ae6ecce94f 100644 --- a/src/screens/Users/Users.test.tsx +++ b/src/screens/Users/Users.spec.tsx @@ -1,8 +1,6 @@ import React from 'react'; import { MockedProvider } from '@apollo/react-testing'; import { act, fireEvent, render, screen } from '@testing-library/react'; -import 'jest-localstorage-mock'; -import 'jest-location-mock'; import { I18nextProvider } from 'react-i18next'; import { Provider } from 'react-redux'; import { BrowserRouter } from 'react-router-dom'; @@ -14,6 +12,7 @@ import i18nForTest from 'utils/i18nForTest'; import Users from './Users'; import { EMPTY_MOCKS, MOCKS, MOCKS2 } from './UsersMocks'; import useLocalStorage from 'utils/useLocalstorage'; +import { describe, expect, it, beforeEach, afterEach, vi } from 'vitest'; import { USER_LIST, @@ -301,11 +300,11 @@ beforeEach(() => { afterEach(() => { localStorage.clear(); - jest.clearAllMocks(); + vi.restoreAllMocks(); }); describe('Testing Users screen', () => { - test('Component should be rendered properly', async () => { + it('Component should be rendered properly', async () => { render( @@ -322,7 +321,7 @@ describe('Testing Users screen', () => { expect(screen.getByTestId('testcomp')).toBeInTheDocument(); }); - test(`Component should be rendered properly when user is not superAdmin + it(`Component should be rendered properly when user is not superAdmin and or userId does not exists in localstorage`, async () => { setItem('AdminFor', ['123']); removeItem('SuperAdmin'); @@ -342,7 +341,7 @@ describe('Testing Users screen', () => { await wait(); }); - test(`Component should be rendered properly when userId does not exists in localstorage`, async () => { + it(`Component should be rendered properly when userId does not exists in localstorage`, async () => { removeItem('AdminFor'); removeItem('SuperAdmin'); await wait(); @@ -361,7 +360,7 @@ describe('Testing Users screen', () => { await wait(); }); - test('Component should be rendered properly when user is superAdmin', async () => { + it('Component should be rendered properly when user is superAdmin', async () => { render( @@ -377,7 +376,7 @@ describe('Testing Users screen', () => { await wait(); }); - test('Testing seach by name functionality', async () => { + it('Testing seach by name functionality', async () => { render( @@ -416,7 +415,7 @@ describe('Testing Users screen', () => { await wait(); }); - test('testing search not found', async () => { + it('testing search not found', async () => { await act(async () => { render( @@ -446,7 +445,7 @@ describe('Testing Users screen', () => { expect(screen.queryByText(/No User Found/i)).toBeInTheDocument(); }); - test('Testing User data is not present', async () => { + it('Testing User data is not present', async () => { render( @@ -463,7 +462,7 @@ describe('Testing Users screen', () => { expect(screen.getByText(/No User Found/i)).toBeTruthy(); }); - test('Should render warning alert when there are no organizations', async () => { + it('Should render warning alert when there are no organizations', async () => { const { container } = render( @@ -483,7 +482,7 @@ describe('Testing Users screen', () => { ); }); - test('Should not render warning alert when there are organizations present', async () => { + it('Should not render warning alert when there are organizations present', async () => { const { container } = render( @@ -504,7 +503,7 @@ describe('Testing Users screen', () => { ); }); - test('Testing filter functionality', async () => { + it('Testing filter functionality', async () => { await act(async () => { render( @@ -577,7 +576,7 @@ describe('Testing Users screen', () => { expect(searchInput).toBeInTheDocument(); }); - test('check for rerendering', async () => { + it('check for rerendering', async () => { const { rerender } = render( @@ -607,7 +606,7 @@ describe('Testing Users screen', () => { await wait(); }); - test('should set hasMore to false if users length is less than perPageResult', async () => { + it('should set hasMore to false if users length is less than perPageResult', async () => { const link = new StaticMockLink(EMPTY_MOCKS, true); render( @@ -629,7 +628,7 @@ describe('Testing Users screen', () => { expect(screen.getByText(/No User Found/i)).toBeInTheDocument(); }); - test('should filter users correctly', async () => { + it('should filter users correctly', async () => { await act(async () => { render( @@ -658,7 +657,7 @@ describe('Testing Users screen', () => { fireEvent.click(filterAdmin); }); - await wait(); + // await wait(); expect(screen.getByText('Jane Doe')).toBeInTheDocument(); await act(async () => { @@ -671,7 +670,7 @@ describe('Testing Users screen', () => { fireEvent.click(filterSuperAdmin); }); - await wait(); + // await wait(); expect(screen.getByText('John Doe')).toBeInTheDocument(); await act(async () => { @@ -683,7 +682,7 @@ describe('Testing Users screen', () => { fireEvent.click(filterUser); }); - await wait(); + // await wait(); expect(screen.getByText('Jack Smith')).toBeInTheDocument(); await act(async () => { @@ -696,13 +695,13 @@ describe('Testing Users screen', () => { fireEvent.click(filterCancel); }); - await wait(); + // await wait(); expect(screen.getByText('John Doe')).toBeInTheDocument(); expect(screen.getByText('Jane Doe')).toBeInTheDocument(); expect(screen.getByText('Jack Smith')).toBeInTheDocument(); }); - test('Users should be sorted in newest order correctly', async () => { + it('Users should be sorted in newest order correctly', async () => { await act(async () => { render( @@ -739,7 +738,7 @@ describe('Testing Users screen', () => { expect(displayedUsers[2]).toHaveTextContent('John Doe'); }); - test('Check if pressing enter key triggers search', async () => { + it('Check if pressing enter key triggers search', async () => { await act(async () => { render( @@ -764,4 +763,159 @@ describe('Testing Users screen', () => { userEvent.type(searchInput, '{enter}'); }); }); + + it('Users should be sorted in oldest order correctly', async () => { + await act(async () => { + render( + + + + + + + + + + , + ); + }); + await wait(); + + const inputText = screen.getByTestId('sortUsers'); + + await act(async () => { + fireEvent.click(inputText); + }); + + const toggleTite = screen.getByTestId('oldest'); + + await act(async () => { + fireEvent.click(toggleTite); + }); + + // Verify the users are sorted by oldest + + const displayedUsers = screen.getAllByRole('row'); + await wait(); + expect(displayedUsers[1]).toHaveTextContent('Jack Smith'); + expect(displayedUsers[2]).toHaveTextContent('John Doe'); + }); + + it('Role filter should not update if selected role is already selected', async () => { + await act(async () => { + render( + + + + + + + + + + , + ); + }); + await wait(); + + const filterButton = screen.getByTestId('filterUsers'); + + await act(async () => { + fireEvent.click(filterButton); + }); + + const filterAdmin = screen.getByTestId('admin'); + + await act(async () => { + fireEvent.click(filterAdmin); + }); + + // await wait(); + expect(screen.getByText('Jane Doe')).toBeInTheDocument(); + + await act(async () => { + fireEvent.click(filterAdmin); + }); + + // await wait(); + expect(screen.getByText('Jane Doe')).toBeInTheDocument(); + }); + + it('Sort filter should not update if selected sort is already selected', async () => { + await act(async () => { + render( + + + + + + + + + + , + ); + }); + await wait(); + + const inputText = screen.getByTestId('sortUsers'); + + await act(async () => { + fireEvent.click(inputText); + }); + + const toggleTite = screen.getByTestId('newest'); + + await act(async () => { + fireEvent.click(toggleTite); + }); + + // Verify the users are sorted by newest + + const displayedUsers = screen.getAllByRole('row'); + await wait(); + expect(displayedUsers[1]).toHaveTextContent('Jane Doe'); + expect(displayedUsers[2]).toHaveTextContent('John Doe'); + + await act(async () => { + fireEvent.click(inputText); + }); + + const toggleTite2 = screen.getByTestId('newest'); + + await act(async () => { + fireEvent.click(toggleTite2); + }); + + // Verify the users are sorted by newest + + const displayedUsers2 = screen.getAllByRole('row'); + await wait(); + expect(displayedUsers2[1]).toHaveTextContent('Jane Doe'); + expect(displayedUsers2[2]).toHaveTextContent('John Doe'); + }); + + it('Reset and Refetch function should work when we search an empty string', async () => { + render( + + + + + + + + + , + ); + + await wait(); + const searchBtn = screen.getByTestId('searchButton'); + const search1 = ''; + userEvent.type(screen.getByTestId(/searchByName/i), search1); + userEvent.click(searchBtn); + await wait(); + expect(screen.queryByText(/Jane Doe/i)).toBeInTheDocument(); + expect(screen.queryByText(/John Doe/i)).toBeInTheDocument(); + expect(screen.queryByText(/Jack Smith/i)).toBeInTheDocument(); + }); }); diff --git a/src/screens/Users/Users.tsx b/src/screens/Users/Users.tsx index 74656fa4c0..2c0b38b08e 100644 --- a/src/screens/Users/Users.tsx +++ b/src/screens/Users/Users.tsx @@ -77,15 +77,19 @@ const Users = (): JSX.Element => { const [searchByName, setSearchByName] = useState(''); const [sortingOption, setSortingOption] = useState('newest'); const [filteringOption, setFilteringOption] = useState('cancel'); + const [loadUnqUsers, setLoadUnqUsers] = useState(0); const userType = getItem('SuperAdmin') ? 'SUPERADMIN' : getItem('AdminFor') ? 'ADMIN' : 'USER'; const loggedInUserId = getItem('id'); + const [usersData, setUsersData] = useState< + { users: InterfaceQueryUserListItem[] } | undefined + >(undefined); const { - data: usersData, + data, loading: loading, fetchMore, refetch: refetchUsers, @@ -114,6 +118,12 @@ const Users = (): JSX.Element => { notifyOnNetworkStatusChange: true, }); + useEffect(() => { + if (data) { + setUsersData(data); + } + }, [data, isLoading]); + const { data: dataOrgs } = useQuery(ORGANIZATION_CONNECTION_LIST); const [displayedUsers, setDisplayedUsers] = useState(usersData?.users || []); @@ -122,15 +132,13 @@ const Users = (): JSX.Element => { if (!usersData) { return; } - if (usersData && usersData.users) { - // console.log(sortingOption) - let newDisplayedUsers = sortUsers(usersData.users, sortingOption); - newDisplayedUsers = filterUsers(newDisplayedUsers, filteringOption); - setDisplayedUsers(newDisplayedUsers); - if (newDisplayedUsers.length < perPageResult) { - setHasMore(false); - } + + if (usersData.users.length < perPageResult) { + setHasMore(false); } + let newDisplayedUsers = sortUsers(usersData.users, sortingOption); + newDisplayedUsers = filterUsers(newDisplayedUsers, filteringOption); + setDisplayedUsers(newDisplayedUsers); }, [usersData, sortingOption, filteringOption]); // To clear the search when the component is unmounted @@ -167,6 +175,12 @@ const Users = (): JSX.Element => { } }, [loading]); + useEffect(() => { + if (loadUnqUsers > 0) { + loadMoreUsers(displayedUsers.length, loadUnqUsers); + } + }, [displayedUsers]); + const handleSearch = (value: string): void => { setSearchByName(value); if (value === '') { @@ -209,11 +223,12 @@ const Users = (): JSX.Element => { setHasMore(true); }; /* istanbul ignore next */ - const loadMoreUsers = (): void => { + const loadMoreUsers = (skipValue: number, limitVal: number): void => { setIsLoadingMore(true); fetchMore({ variables: { - skip: displayedUsers.length || 0, + first: limitVal + 2 * perPageResult || perPageResult, + skip: skipValue - perPageResult >= 0 ? skipValue - perPageResult : 0, filter: searchByName, order: sortingOption === 'newest' ? 'createdAt_DESC' : 'createdAt_ASC', }, @@ -227,14 +242,25 @@ const Users = (): JSX.Element => { ) => { setIsLoadingMore(false); if (!fetchMoreResult) return prev || { users: [] }; - if (fetchMoreResult.users.length < perPageResult) { - setHasMore(false); - } + const mergedUsers = [...(prev?.users || []), ...fetchMoreResult.users]; const uniqueUsers = Array.from( new Map(mergedUsers.map((user) => [user.user._id, user])).values(), ); + if (uniqueUsers.length < mergedUsers.length) { + setLoadUnqUsers(mergedUsers.length - uniqueUsers.length); + } else setLoadUnqUsers(0); + + if (prev?.users) { + if (uniqueUsers.length - prev?.users.length < perPageResult) { + setHasMore(false); + } + } else { + if (uniqueUsers.length < perPageResult) { + setHasMore(false); + } + } return { users: uniqueUsers }; }, @@ -247,7 +273,6 @@ const Users = (): JSX.Element => { } setHasMore(true); setSortingOption(option); - setDisplayedUsers([]); }; const sortUsers = ( @@ -276,7 +301,6 @@ const Users = (): JSX.Element => { if (option === filteringOption) { return; } - setDisplayedUsers([]); setFilteringOption(option); setHasMore(true); }; @@ -362,13 +386,17 @@ const Users = (): JSX.Element => { handleSorting('newest')} + onClick={(): void => { + handleSorting('newest'); + }} data-testid="newest" > {t('Newest')} handleSorting('oldest')} + onClick={(): void => { + handleSorting('oldest'); + }} data-testid="oldest" > {t('Oldest')} @@ -454,7 +482,9 @@ const Users = (): JSX.Element => { /* istanbul ignore next */ displayedUsers.length ?? 0 } - next={loadMoreUsers} + next={() => { + loadMoreUsers(displayedUsers.length, perPageResult); + }} loader={ Date: Tue, 24 Dec 2024 23:32:44 +0530 Subject: [PATCH 3/6] added loadmoreusers function test --- src/screens/Users/Users.spec.tsx | 950 +++++++++++++++++++++++++++++++ src/screens/Users/Users.tsx | 2 +- 2 files changed, 951 insertions(+), 1 deletion(-) diff --git a/src/screens/Users/Users.spec.tsx b/src/screens/Users/Users.spec.tsx index ae6ecce94f..08b07da158 100644 --- a/src/screens/Users/Users.spec.tsx +++ b/src/screens/Users/Users.spec.tsx @@ -278,10 +278,927 @@ const MOCKS_NEW = [ }, ]; +const MOCK_USERS2 = [ + ...MOCK_USERS, + { + user: { + _id: 'user4', + firstName: 'Emma', + lastName: 'Johnson', + image: null, + email: 'emma@example.com', + createdAt: '2023-04-22T04:53:17.742+00:00', + registeredEvents: [], + membershipRequests: [], + organizationsBlockedBy: [ + { + _id: 'xyz', + name: 'ABC', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + joinedOrganizations: [ + { + _id: 'abc', + name: 'Joined Organization 1', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + }, + appUserProfile: { + _id: 'user4', + adminFor: [], + isSuperAdmin: false, + createdOrganizations: [], + createdEvents: [], + eventAdmin: [], + }, + }, + { + user: { + _id: 'user5', + firstName: 'Liam', + lastName: 'Smith', + image: null, + email: 'liam@example.com', + createdAt: '2023-04-23T04:53:17.742+00:00', + registeredEvents: [], + membershipRequests: [], + organizationsBlockedBy: [ + { + _id: 'xyz', + name: 'ABC', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + joinedOrganizations: [ + { + _id: 'abc', + name: 'Joined Organization 1', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + }, + appUserProfile: { + _id: 'user5', + adminFor: [], + isSuperAdmin: false, + createdOrganizations: [], + createdEvents: [], + eventAdmin: [], + }, + }, + { + user: { + _id: 'user6', + firstName: 'Olivia', + lastName: 'Brown', + image: null, + email: 'olivia@example.com', + createdAt: '2023-04-24T04:53:17.742+00:00', + registeredEvents: [], + membershipRequests: [], + organizationsBlockedBy: [ + { + _id: 'xyz', + name: 'ABC', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + joinedOrganizations: [ + { + _id: 'abc', + name: 'Joined Organization 1', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + }, + appUserProfile: { + _id: 'user6', + adminFor: [], + isSuperAdmin: false, + createdOrganizations: [], + createdEvents: [], + eventAdmin: [], + }, + }, + { + user: { + _id: 'user7', + firstName: 'Noah', + lastName: 'Williams', + image: null, + email: 'noah@example.com', + createdAt: '2023-04-25T04:53:17.742+00:00', + registeredEvents: [], + membershipRequests: [], + organizationsBlockedBy: [ + { + _id: 'xyz', + name: 'ABC', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + joinedOrganizations: [ + { + _id: 'abc', + name: 'Joined Organization 1', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + }, + appUserProfile: { + _id: 'user7', + adminFor: [], + isSuperAdmin: false, + createdOrganizations: [], + createdEvents: [], + eventAdmin: [], + }, + }, + { + user: { + _id: 'user8', + firstName: 'Ava', + lastName: 'Jones', + image: null, + email: 'ava@example.com', + createdAt: '2023-04-26T04:53:17.742+00:00', + registeredEvents: [], + membershipRequests: [], + organizationsBlockedBy: [ + { + _id: 'xyz', + name: 'ABC', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + joinedOrganizations: [ + { + _id: 'abc', + name: 'Joined Organization 1', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + }, + appUserProfile: { + _id: 'user8', + adminFor: [], + isSuperAdmin: false, + createdOrganizations: [], + createdEvents: [], + eventAdmin: [], + }, + }, + { + user: { + _id: 'user9', + firstName: 'Ethan', + lastName: 'Garcia', + image: null, + email: 'ethan@example.com', + createdAt: '2023-04-27T04:53:17.742+00:00', + registeredEvents: [], + membershipRequests: [], + organizationsBlockedBy: [ + { + _id: 'xyz', + name: 'ABC', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + joinedOrganizations: [ + { + _id: 'abc', + name: 'Joined Organization 1', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + }, + appUserProfile: { + _id: 'user9', + adminFor: [], + isSuperAdmin: false, + createdOrganizations: [], + createdEvents: [], + eventAdmin: [], + }, + }, + { + user: { + _id: 'user10', + firstName: 'Sophia', + lastName: 'Martinez', + image: null, + email: 'sophia@example.com', + createdAt: '2023-04-28T04:53:17.742+00:00', + registeredEvents: [], + membershipRequests: [], + organizationsBlockedBy: [ + { + _id: 'xyz', + name: 'ABC', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + joinedOrganizations: [ + { + _id: 'abc', + name: 'Joined Organization 1', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + }, + appUserProfile: { + _id: 'user10', + adminFor: [], + isSuperAdmin: false, + createdOrganizations: [], + createdEvents: [], + eventAdmin: [], + }, + }, + { + user: { + _id: 'user11', + firstName: 'Mason', + lastName: 'Davis', + image: null, + email: 'mason@example.com', + createdAt: '2023-04-29T04:53:17.742+00:00', + registeredEvents: [], + membershipRequests: [], + organizationsBlockedBy: [ + { + _id: 'xyz', + name: 'ABC', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + joinedOrganizations: [ + { + _id: 'abc', + name: 'Joined Organization 1', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + }, + appUserProfile: { + _id: 'user11', + adminFor: [], + isSuperAdmin: false, + createdOrganizations: [], + createdEvents: [], + eventAdmin: [], + }, + }, + { + user: { + _id: 'user12', + firstName: 'Isabella', + lastName: 'Rodriguez', + image: null, + email: 'isabella@example.com', + createdAt: '2023-04-30T04:53:17.742+00:00', + registeredEvents: [], + membershipRequests: [], + organizationsBlockedBy: [ + { + _id: 'xyz', + name: 'ABC', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + joinedOrganizations: [ + { + _id: 'abc', + name: 'Joined Organization 1', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + }, + appUserProfile: { + _id: 'user12', + adminFor: [], + isSuperAdmin: false, + createdOrganizations: [], + createdEvents: [], + eventAdmin: [], + }, + }, + { + user: { + _id: 'user13', + firstName: 'Logan', + lastName: 'Wilson', + image: null, + email: 'logan@example.com', + createdAt: '2023-04-08T04:53:17.742+00:00', + registeredEvents: [], + membershipRequests: [], + organizationsBlockedBy: [ + { + _id: 'xyz', + name: 'ABC', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + joinedOrganizations: [ + { + _id: 'abc', + name: 'Joined Organization 1', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + }, + appUserProfile: { + _id: 'user13', + adminFor: [], + isSuperAdmin: false, + createdOrganizations: [], + createdEvents: [], + eventAdmin: [], + }, + }, + { + user: { + _id: 'user14', + firstName: 'Mia', + lastName: 'Anderson', + image: null, + email: 'mia@example.com', + createdAt: '2023-04-07T04:53:17.742+00:00', + registeredEvents: [], + membershipRequests: [], + organizationsBlockedBy: [ + { + _id: 'xyz', + name: 'ABC', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + joinedOrganizations: [ + { + _id: 'abc', + name: 'Joined Organization 1', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + }, + appUserProfile: { + _id: 'user14', + adminFor: [], + isSuperAdmin: false, + createdOrganizations: [], + createdEvents: [], + eventAdmin: [], + }, + }, + { + user: { + _id: 'user15', + firstName: 'Lucas', + lastName: 'Thomas', + image: null, + email: 'lucas@example.com', + createdAt: '2023-04-05T04:53:17.742+00:00', + registeredEvents: [], + membershipRequests: [], + organizationsBlockedBy: [ + { + _id: 'xyz', + name: 'ABC', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + joinedOrganizations: [ + { + _id: 'abc', + name: 'Joined Organization 1', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + }, + appUserProfile: { + _id: 'user15', + adminFor: [], + isSuperAdmin: false, + createdOrganizations: [], + createdEvents: [], + eventAdmin: [], + }, + }, +]; + +const MOCKS_NEW2 = [ + { + request: { + query: USER_LIST, + variables: { + first: 12, + skip: 0, + firstName_contains: '', + lastName_contains: '', + order: 'createdAt_DESC', + }, + }, + result: { + data: { + users: MOCK_USERS2.slice(0, 12), + }, + }, + }, + { + request: { + query: ORGANIZATION_CONNECTION_LIST, + }, + result: { + data: { + organizationsConnection: [], + }, + }, + }, + { + request: { + query: USER_LIST, + variables: { + first: 24, + skip: 0, + firstName_contains: '', + lastName_contains: '', + order: 'createdAt_DESC', + filter: '', + }, + }, + result: { + data: { + users: MOCK_USERS2.slice(12, 15), + }, + }, + }, +]; + const link = new StaticMockLink(MOCKS, true); const link2 = new StaticMockLink(EMPTY_MOCKS, true); const link3 = new StaticMockLink(MOCKS2, true); const link5 = new StaticMockLink(MOCKS_NEW, true); +const link6 = new StaticMockLink(MOCKS_NEW2, true); async function wait(ms = 1000): Promise { await act(() => { @@ -918,4 +1835,37 @@ describe('Testing Users screen', () => { expect(screen.queryByText(/John Doe/i)).toBeInTheDocument(); expect(screen.queryByText(/Jack Smith/i)).toBeInTheDocument(); }); + + it('Users should be loaded on scroll using loadmoreusers function', async () => { + const { container } = render( + + + + + + + + + , + ); + + await wait(); + const users = container + .getElementsByTagName('tbody')[0] + .querySelectorAll('tr'); + console.log(users, users.length); + expect(users.length).toBe(12); + + await act(async () => { + fireEvent.scroll(window, { target: { scrollY: 1000 } }); + }); + + await wait(); + + const users2 = container + .getElementsByTagName('tbody')[0] + .querySelectorAll('tr'); + console.log(users2, users2.length); + expect(users2.length).toBe(15); + }); }); diff --git a/src/screens/Users/Users.tsx b/src/screens/Users/Users.tsx index 2c0b38b08e..b98d531ece 100644 --- a/src/screens/Users/Users.tsx +++ b/src/screens/Users/Users.tsx @@ -227,7 +227,7 @@ const Users = (): JSX.Element => { setIsLoadingMore(true); fetchMore({ variables: { - first: limitVal + 2 * perPageResult || perPageResult, + first: limitVal + perPageResult || perPageResult, skip: skipValue - perPageResult >= 0 ? skipValue - perPageResult : 0, filter: searchByName, order: sortingOption === 'newest' ? 'createdAt_DESC' : 'createdAt_ASC', From ca5919dee732b83fc7f765343bfc6a65ddd0c2bc Mon Sep 17 00:00:00 2001 From: Aad1tya27 Date: Wed, 25 Dec 2024 01:07:07 +0530 Subject: [PATCH 4/6] added test to prevent duplicate users --- src/screens/Users/Users.spec.tsx | 1195 +++--------------------------- src/screens/Users/Users.tsx | 5 +- src/screens/Users/UsersMocks.ts | 1095 +++++++++++++++++++++++++++ 3 files changed, 1207 insertions(+), 1088 deletions(-) diff --git a/src/screens/Users/Users.spec.tsx b/src/screens/Users/Users.spec.tsx index 08b07da158..e42ec48a8b 100644 --- a/src/screens/Users/Users.spec.tsx +++ b/src/screens/Users/Users.spec.tsx @@ -10,7 +10,13 @@ import { store } from 'state/store'; import { StaticMockLink } from 'utils/StaticMockLink'; import i18nForTest from 'utils/i18nForTest'; import Users from './Users'; -import { EMPTY_MOCKS, MOCKS, MOCKS2 } from './UsersMocks'; +import { + EMPTY_MOCKS, + MOCKS, + MOCKS2, + MOCK_USERS, + MOCK_USERS2, +} from './UsersMocks'; import useLocalStorage from 'utils/useLocalstorage'; import { describe, expect, it, beforeEach, afterEach, vi } from 'vitest'; @@ -21,233 +27,6 @@ import { const { setItem, removeItem } = useLocalStorage(); -const MOCK_USERS = [ - { - user: { - _id: 'user1', - firstName: 'John', - lastName: 'Doe', - image: null, - email: 'john@example.com', - createdAt: '2023-04-13T04:53:17.742+00:00', - registeredEvents: [], - membershipRequests: [], - organizationsBlockedBy: [ - { - _id: 'xyz', - name: 'ABC', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '20/06/2022', - creator: { - _id: '123', - firstName: 'John', - lastName: 'Doe', - image: null, - email: 'john@example.com', - createdAt: '20/06/2022', - }, - }, - ], - joinedOrganizations: [ - { - _id: 'abc', - name: 'Joined Organization 1', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '20/06/2022', - creator: { - _id: '123', - firstName: 'John', - lastName: 'Doe', - image: null, - email: 'john@example.com', - createdAt: '20/06/2022', - }, - }, - ], - }, - appUserProfile: { - _id: 'user1', - adminFor: [ - { - _id: '123', - }, - ], - isSuperAdmin: true, - createdOrganizations: [], - createdEvents: [], - eventAdmin: [], - }, - }, - { - user: { - _id: 'user2', - firstName: 'Jane', - lastName: 'Doe', - image: null, - email: 'john@example.com', - createdAt: '2023-04-17T04:53:17.742+00:00', - registeredEvents: [], - membershipRequests: [], - organizationsBlockedBy: [ - { - _id: '456', - name: 'ABC', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '21/06/2022', - creator: { - _id: '123', - firstName: 'John', - lastName: 'Doe', - image: null, - email: 'john@example.com', - createdAt: '21/06/2022', - }, - }, - ], - joinedOrganizations: [ - { - _id: '123', - name: 'Palisadoes', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '21/06/2022', - creator: { - _id: '123', - firstName: 'John', - lastName: 'Doe', - image: null, - email: 'john@example.com', - createdAt: '21/06/2022', - }, - }, - ], - }, - appUserProfile: { - _id: 'user2', - adminFor: [ - { - _id: '123', - }, - ], - isSuperAdmin: false, - createdOrganizations: [], - createdEvents: [], - eventAdmin: [], - }, - }, - { - user: { - _id: 'user3', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '2023-04-09T04:53:17.742+00:00', - registeredEvents: [], - membershipRequests: [], - organizationsBlockedBy: [ - { - _id: 'xyz', - name: 'ABC', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - joinedOrganizations: [ - { - _id: 'abc', - name: 'Joined Organization 1', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - }, - appUserProfile: { - _id: 'user3', - adminFor: [], - isSuperAdmin: false, - createdOrganizations: [], - createdEvents: [], - eventAdmin: [], - }, - }, -]; - const MOCKS_NEW = [ { request: { @@ -278,875 +57,55 @@ const MOCKS_NEW = [ }, ]; -const MOCK_USERS2 = [ - ...MOCK_USERS, - { - user: { - _id: 'user4', - firstName: 'Emma', - lastName: 'Johnson', - image: null, - email: 'emma@example.com', - createdAt: '2023-04-22T04:53:17.742+00:00', - registeredEvents: [], - membershipRequests: [], - organizationsBlockedBy: [ - { - _id: 'xyz', - name: 'ABC', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - joinedOrganizations: [ - { - _id: 'abc', - name: 'Joined Organization 1', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - }, - appUserProfile: { - _id: 'user4', - adminFor: [], - isSuperAdmin: false, - createdOrganizations: [], - createdEvents: [], - eventAdmin: [], - }, - }, - { - user: { - _id: 'user5', - firstName: 'Liam', - lastName: 'Smith', - image: null, - email: 'liam@example.com', - createdAt: '2023-04-23T04:53:17.742+00:00', - registeredEvents: [], - membershipRequests: [], - organizationsBlockedBy: [ - { - _id: 'xyz', - name: 'ABC', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - joinedOrganizations: [ - { - _id: 'abc', - name: 'Joined Organization 1', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - }, - appUserProfile: { - _id: 'user5', - adminFor: [], - isSuperAdmin: false, - createdOrganizations: [], - createdEvents: [], - eventAdmin: [], - }, - }, - { - user: { - _id: 'user6', - firstName: 'Olivia', - lastName: 'Brown', - image: null, - email: 'olivia@example.com', - createdAt: '2023-04-24T04:53:17.742+00:00', - registeredEvents: [], - membershipRequests: [], - organizationsBlockedBy: [ - { - _id: 'xyz', - name: 'ABC', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - joinedOrganizations: [ - { - _id: 'abc', - name: 'Joined Organization 1', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - }, - appUserProfile: { - _id: 'user6', - adminFor: [], - isSuperAdmin: false, - createdOrganizations: [], - createdEvents: [], - eventAdmin: [], - }, - }, - { - user: { - _id: 'user7', - firstName: 'Noah', - lastName: 'Williams', - image: null, - email: 'noah@example.com', - createdAt: '2023-04-25T04:53:17.742+00:00', - registeredEvents: [], - membershipRequests: [], - organizationsBlockedBy: [ - { - _id: 'xyz', - name: 'ABC', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - joinedOrganizations: [ - { - _id: 'abc', - name: 'Joined Organization 1', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - }, - appUserProfile: { - _id: 'user7', - adminFor: [], - isSuperAdmin: false, - createdOrganizations: [], - createdEvents: [], - eventAdmin: [], - }, - }, - { - user: { - _id: 'user8', - firstName: 'Ava', - lastName: 'Jones', - image: null, - email: 'ava@example.com', - createdAt: '2023-04-26T04:53:17.742+00:00', - registeredEvents: [], - membershipRequests: [], - organizationsBlockedBy: [ - { - _id: 'xyz', - name: 'ABC', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - joinedOrganizations: [ - { - _id: 'abc', - name: 'Joined Organization 1', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - }, - appUserProfile: { - _id: 'user8', - adminFor: [], - isSuperAdmin: false, - createdOrganizations: [], - createdEvents: [], - eventAdmin: [], - }, - }, - { - user: { - _id: 'user9', - firstName: 'Ethan', - lastName: 'Garcia', - image: null, - email: 'ethan@example.com', - createdAt: '2023-04-27T04:53:17.742+00:00', - registeredEvents: [], - membershipRequests: [], - organizationsBlockedBy: [ - { - _id: 'xyz', - name: 'ABC', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - joinedOrganizations: [ - { - _id: 'abc', - name: 'Joined Organization 1', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - }, - appUserProfile: { - _id: 'user9', - adminFor: [], - isSuperAdmin: false, - createdOrganizations: [], - createdEvents: [], - eventAdmin: [], - }, - }, - { - user: { - _id: 'user10', - firstName: 'Sophia', - lastName: 'Martinez', - image: null, - email: 'sophia@example.com', - createdAt: '2023-04-28T04:53:17.742+00:00', - registeredEvents: [], - membershipRequests: [], - organizationsBlockedBy: [ - { - _id: 'xyz', - name: 'ABC', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - joinedOrganizations: [ - { - _id: 'abc', - name: 'Joined Organization 1', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - }, - appUserProfile: { - _id: 'user10', - adminFor: [], - isSuperAdmin: false, - createdOrganizations: [], - createdEvents: [], - eventAdmin: [], - }, - }, - { - user: { - _id: 'user11', - firstName: 'Mason', - lastName: 'Davis', - image: null, - email: 'mason@example.com', - createdAt: '2023-04-29T04:53:17.742+00:00', - registeredEvents: [], - membershipRequests: [], - organizationsBlockedBy: [ - { - _id: 'xyz', - name: 'ABC', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - joinedOrganizations: [ - { - _id: 'abc', - name: 'Joined Organization 1', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - }, - appUserProfile: { - _id: 'user11', - adminFor: [], - isSuperAdmin: false, - createdOrganizations: [], - createdEvents: [], - eventAdmin: [], - }, - }, - { - user: { - _id: 'user12', - firstName: 'Isabella', - lastName: 'Rodriguez', - image: null, - email: 'isabella@example.com', - createdAt: '2023-04-30T04:53:17.742+00:00', - registeredEvents: [], - membershipRequests: [], - organizationsBlockedBy: [ - { - _id: 'xyz', - name: 'ABC', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - joinedOrganizations: [ - { - _id: 'abc', - name: 'Joined Organization 1', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - }, - appUserProfile: { - _id: 'user12', - adminFor: [], - isSuperAdmin: false, - createdOrganizations: [], - createdEvents: [], - eventAdmin: [], - }, - }, +const MOCKS_NEW2 = [ { - user: { - _id: 'user13', - firstName: 'Logan', - lastName: 'Wilson', - image: null, - email: 'logan@example.com', - createdAt: '2023-04-08T04:53:17.742+00:00', - registeredEvents: [], - membershipRequests: [], - organizationsBlockedBy: [ - { - _id: 'xyz', - name: 'ABC', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - joinedOrganizations: [ - { - _id: 'abc', - name: 'Joined Organization 1', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], + request: { + query: USER_LIST, + variables: { + first: 12, + skip: 0, + firstName_contains: '', + lastName_contains: '', + order: 'createdAt_DESC', + }, }, - appUserProfile: { - _id: 'user13', - adminFor: [], - isSuperAdmin: false, - createdOrganizations: [], - createdEvents: [], - eventAdmin: [], + result: { + data: { + users: MOCK_USERS2.slice(0, 12), + }, }, }, { - user: { - _id: 'user14', - firstName: 'Mia', - lastName: 'Anderson', - image: null, - email: 'mia@example.com', - createdAt: '2023-04-07T04:53:17.742+00:00', - registeredEvents: [], - membershipRequests: [], - organizationsBlockedBy: [ - { - _id: 'xyz', - name: 'ABC', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - joinedOrganizations: [ - { - _id: 'abc', - name: 'Joined Organization 1', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], + request: { + query: ORGANIZATION_CONNECTION_LIST, }, - appUserProfile: { - _id: 'user14', - adminFor: [], - isSuperAdmin: false, - createdOrganizations: [], - createdEvents: [], - eventAdmin: [], + result: { + data: { + organizationsConnection: [], + }, }, }, { - user: { - _id: 'user15', - firstName: 'Lucas', - lastName: 'Thomas', - image: null, - email: 'lucas@example.com', - createdAt: '2023-04-05T04:53:17.742+00:00', - registeredEvents: [], - membershipRequests: [], - organizationsBlockedBy: [ - { - _id: 'xyz', - name: 'ABC', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - joinedOrganizations: [ - { - _id: 'abc', - name: 'Joined Organization 1', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], + request: { + query: USER_LIST, + variables: { + first: 24, + skip: 0, + firstName_contains: '', + lastName_contains: '', + order: 'createdAt_DESC', + filter: '', + }, }, - appUserProfile: { - _id: 'user15', - adminFor: [], - isSuperAdmin: false, - createdOrganizations: [], - createdEvents: [], - eventAdmin: [], + result: { + data: { + users: MOCK_USERS2.slice(12, 15), + }, }, }, ]; -const MOCKS_NEW2 = [ +const MOCKS_NEW3 = [ { request: { query: USER_LIST, @@ -1188,7 +147,43 @@ const MOCKS_NEW2 = [ }, result: { data: { - users: MOCK_USERS2.slice(12, 15), + users: MOCK_USERS2.slice(11, 15), + }, + }, + }, + { + request: { + query: USER_LIST, + variables: { + first: 24, + skip: 0, + firstName_contains: '', + lastName_contains: '', + order: 'createdAt_DESC', + filter: '', + }, + }, + result: { + data: { + users: MOCK_USERS2.slice(11, 15), + }, + }, + }, + { + request: { + query: USER_LIST, + variables: { + first: 13, + skip: 3, + firstName_contains: '', + lastName_contains: '', + order: 'createdAt_DESC', + filter: '', + }, + }, + result: { + data: { + users: [], }, }, }, @@ -1199,6 +194,7 @@ const link2 = new StaticMockLink(EMPTY_MOCKS, true); const link3 = new StaticMockLink(MOCKS2, true); const link5 = new StaticMockLink(MOCKS_NEW, true); const link6 = new StaticMockLink(MOCKS_NEW2, true); +const link7 = new StaticMockLink(MOCKS_NEW3, true); async function wait(ms = 1000): Promise { await act(() => { @@ -1868,4 +864,35 @@ describe('Testing Users screen', () => { console.log(users2, users2.length); expect(users2.length).toBe(15); }); + + it('should not show duplicate users when scrolling by using mergedUsers and loadUnqUsers', async () => { + const { container } = render( + + + + + + + + + , + ); + + await wait(); + const users = container + .getElementsByTagName('tbody')[0] + .querySelectorAll('tr'); + expect(users.length).toBe(12); + + await act(async () => { + fireEvent.scroll(window, { target: { scrollY: 1000 } }); + }); + + await wait(); + + const users2 = container + .getElementsByTagName('tbody')[0] + .querySelectorAll('tr'); + expect(users2.length).toBe(15); + }); }); diff --git a/src/screens/Users/Users.tsx b/src/screens/Users/Users.tsx index b98d531ece..936807f1ec 100644 --- a/src/screens/Users/Users.tsx +++ b/src/screens/Users/Users.tsx @@ -252,14 +252,11 @@ const Users = (): JSX.Element => { setLoadUnqUsers(mergedUsers.length - uniqueUsers.length); } else setLoadUnqUsers(0); + // Load more users will always run after the initial request, hence prev is not going to be undefined if (prev?.users) { if (uniqueUsers.length - prev?.users.length < perPageResult) { setHasMore(false); } - } else { - if (uniqueUsers.length < perPageResult) { - setHasMore(false); - } } return { users: uniqueUsers }; diff --git a/src/screens/Users/UsersMocks.ts b/src/screens/Users/UsersMocks.ts index ff346a1c97..d4f0537e5e 100644 --- a/src/screens/Users/UsersMocks.ts +++ b/src/screens/Users/UsersMocks.ts @@ -503,3 +503,1098 @@ export const EMPTY_MOCKS = [ }, }, ]; + +export const MOCK_USERS = [ + { + user: { + _id: 'user1', + firstName: 'John', + lastName: 'Doe', + image: null, + email: 'john@example.com', + createdAt: '2023-04-13T04:53:17.742+00:00', + registeredEvents: [], + membershipRequests: [], + organizationsBlockedBy: [ + { + _id: 'xyz', + name: 'ABC', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '20/06/2022', + creator: { + _id: '123', + firstName: 'John', + lastName: 'Doe', + image: null, + email: 'john@example.com', + createdAt: '20/06/2022', + }, + }, + ], + joinedOrganizations: [ + { + _id: 'abc', + name: 'Joined Organization 1', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '20/06/2022', + creator: { + _id: '123', + firstName: 'John', + lastName: 'Doe', + image: null, + email: 'john@example.com', + createdAt: '20/06/2022', + }, + }, + ], + }, + appUserProfile: { + _id: 'user1', + adminFor: [ + { + _id: '123', + }, + ], + isSuperAdmin: true, + createdOrganizations: [], + createdEvents: [], + eventAdmin: [], + }, + }, + { + user: { + _id: 'user2', + firstName: 'Jane', + lastName: 'Doe', + image: null, + email: 'john@example.com', + createdAt: '2023-04-17T04:53:17.742+00:00', + registeredEvents: [], + membershipRequests: [], + organizationsBlockedBy: [ + { + _id: '456', + name: 'ABC', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '21/06/2022', + creator: { + _id: '123', + firstName: 'John', + lastName: 'Doe', + image: null, + email: 'john@example.com', + createdAt: '21/06/2022', + }, + }, + ], + joinedOrganizations: [ + { + _id: '123', + name: 'Palisadoes', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '21/06/2022', + creator: { + _id: '123', + firstName: 'John', + lastName: 'Doe', + image: null, + email: 'john@example.com', + createdAt: '21/06/2022', + }, + }, + ], + }, + appUserProfile: { + _id: 'user2', + adminFor: [ + { + _id: '123', + }, + ], + isSuperAdmin: false, + createdOrganizations: [], + createdEvents: [], + eventAdmin: [], + }, + }, + { + user: { + _id: 'user3', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '2023-04-09T04:53:17.742+00:00', + registeredEvents: [], + membershipRequests: [], + organizationsBlockedBy: [ + { + _id: 'xyz', + name: 'ABC', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + joinedOrganizations: [ + { + _id: 'abc', + name: 'Joined Organization 1', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + }, + appUserProfile: { + _id: 'user3', + adminFor: [], + isSuperAdmin: false, + createdOrganizations: [], + createdEvents: [], + eventAdmin: [], + }, + }, +]; + +export const MOCK_USERS2 = [ + ...MOCK_USERS, + { + user: { + _id: 'user4', + firstName: 'Emma', + lastName: 'Johnson', + image: null, + email: 'emma@example.com', + createdAt: '2023-04-22T04:53:17.742+00:00', + registeredEvents: [], + membershipRequests: [], + organizationsBlockedBy: [ + { + _id: 'xyz', + name: 'ABC', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + joinedOrganizations: [ + { + _id: 'abc', + name: 'Joined Organization 1', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + }, + appUserProfile: { + _id: 'user4', + adminFor: [], + isSuperAdmin: false, + createdOrganizations: [], + createdEvents: [], + eventAdmin: [], + }, + }, + { + user: { + _id: 'user5', + firstName: 'Liam', + lastName: 'Smith', + image: null, + email: 'liam@example.com', + createdAt: '2023-04-23T04:53:17.742+00:00', + registeredEvents: [], + membershipRequests: [], + organizationsBlockedBy: [ + { + _id: 'xyz', + name: 'ABC', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + joinedOrganizations: [ + { + _id: 'abc', + name: 'Joined Organization 1', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + }, + appUserProfile: { + _id: 'user5', + adminFor: [], + isSuperAdmin: false, + createdOrganizations: [], + createdEvents: [], + eventAdmin: [], + }, + }, + { + user: { + _id: 'user6', + firstName: 'Olivia', + lastName: 'Brown', + image: null, + email: 'olivia@example.com', + createdAt: '2023-04-24T04:53:17.742+00:00', + registeredEvents: [], + membershipRequests: [], + organizationsBlockedBy: [ + { + _id: 'xyz', + name: 'ABC', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + joinedOrganizations: [ + { + _id: 'abc', + name: 'Joined Organization 1', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + }, + appUserProfile: { + _id: 'user6', + adminFor: [], + isSuperAdmin: false, + createdOrganizations: [], + createdEvents: [], + eventAdmin: [], + }, + }, + { + user: { + _id: 'user7', + firstName: 'Noah', + lastName: 'Williams', + image: null, + email: 'noah@example.com', + createdAt: '2023-04-25T04:53:17.742+00:00', + registeredEvents: [], + membershipRequests: [], + organizationsBlockedBy: [ + { + _id: 'xyz', + name: 'ABC', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + joinedOrganizations: [ + { + _id: 'abc', + name: 'Joined Organization 1', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + }, + appUserProfile: { + _id: 'user7', + adminFor: [], + isSuperAdmin: false, + createdOrganizations: [], + createdEvents: [], + eventAdmin: [], + }, + }, + { + user: { + _id: 'user8', + firstName: 'Ava', + lastName: 'Jones', + image: null, + email: 'ava@example.com', + createdAt: '2023-04-26T04:53:17.742+00:00', + registeredEvents: [], + membershipRequests: [], + organizationsBlockedBy: [ + { + _id: 'xyz', + name: 'ABC', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + joinedOrganizations: [ + { + _id: 'abc', + name: 'Joined Organization 1', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + }, + appUserProfile: { + _id: 'user8', + adminFor: [], + isSuperAdmin: false, + createdOrganizations: [], + createdEvents: [], + eventAdmin: [], + }, + }, + { + user: { + _id: 'user9', + firstName: 'Ethan', + lastName: 'Garcia', + image: null, + email: 'ethan@example.com', + createdAt: '2023-04-27T04:53:17.742+00:00', + registeredEvents: [], + membershipRequests: [], + organizationsBlockedBy: [ + { + _id: 'xyz', + name: 'ABC', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + joinedOrganizations: [ + { + _id: 'abc', + name: 'Joined Organization 1', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + }, + appUserProfile: { + _id: 'user9', + adminFor: [], + isSuperAdmin: false, + createdOrganizations: [], + createdEvents: [], + eventAdmin: [], + }, + }, + { + user: { + _id: 'user10', + firstName: 'Sophia', + lastName: 'Martinez', + image: null, + email: 'sophia@example.com', + createdAt: '2023-04-28T04:53:17.742+00:00', + registeredEvents: [], + membershipRequests: [], + organizationsBlockedBy: [ + { + _id: 'xyz', + name: 'ABC', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + joinedOrganizations: [ + { + _id: 'abc', + name: 'Joined Organization 1', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + }, + appUserProfile: { + _id: 'user10', + adminFor: [], + isSuperAdmin: false, + createdOrganizations: [], + createdEvents: [], + eventAdmin: [], + }, + }, + { + user: { + _id: 'user11', + firstName: 'Mason', + lastName: 'Davis', + image: null, + email: 'mason@example.com', + createdAt: '2023-04-29T04:53:17.742+00:00', + registeredEvents: [], + membershipRequests: [], + organizationsBlockedBy: [ + { + _id: 'xyz', + name: 'ABC', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + joinedOrganizations: [ + { + _id: 'abc', + name: 'Joined Organization 1', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + }, + appUserProfile: { + _id: 'user11', + adminFor: [], + isSuperAdmin: false, + createdOrganizations: [], + createdEvents: [], + eventAdmin: [], + }, + }, + { + user: { + _id: 'user12', + firstName: 'Isabella', + lastName: 'Rodriguez', + image: null, + email: 'isabella@example.com', + createdAt: '2023-04-30T04:53:17.742+00:00', + registeredEvents: [], + membershipRequests: [], + organizationsBlockedBy: [ + { + _id: 'xyz', + name: 'ABC', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + joinedOrganizations: [ + { + _id: 'abc', + name: 'Joined Organization 1', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + }, + appUserProfile: { + _id: 'user12', + adminFor: [], + isSuperAdmin: false, + createdOrganizations: [], + createdEvents: [], + eventAdmin: [], + }, + }, + { + user: { + _id: 'user13', + firstName: 'Logan', + lastName: 'Wilson', + image: null, + email: 'logan@example.com', + createdAt: '2023-04-08T04:53:17.742+00:00', + registeredEvents: [], + membershipRequests: [], + organizationsBlockedBy: [ + { + _id: 'xyz', + name: 'ABC', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + joinedOrganizations: [ + { + _id: 'abc', + name: 'Joined Organization 1', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + }, + appUserProfile: { + _id: 'user13', + adminFor: [], + isSuperAdmin: false, + createdOrganizations: [], + createdEvents: [], + eventAdmin: [], + }, + }, + { + user: { + _id: 'user14', + firstName: 'Mia', + lastName: 'Anderson', + image: null, + email: 'mia@example.com', + createdAt: '2023-04-07T04:53:17.742+00:00', + registeredEvents: [], + membershipRequests: [], + organizationsBlockedBy: [ + { + _id: 'xyz', + name: 'ABC', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + joinedOrganizations: [ + { + _id: 'abc', + name: 'Joined Organization 1', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + }, + appUserProfile: { + _id: 'user14', + adminFor: [], + isSuperAdmin: false, + createdOrganizations: [], + createdEvents: [], + eventAdmin: [], + }, + }, + { + user: { + _id: 'user15', + firstName: 'Lucas', + lastName: 'Thomas', + image: null, + email: 'lucas@example.com', + createdAt: '2023-04-05T04:53:17.742+00:00', + registeredEvents: [], + membershipRequests: [], + organizationsBlockedBy: [ + { + _id: 'xyz', + name: 'ABC', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + joinedOrganizations: [ + { + _id: 'abc', + name: 'Joined Organization 1', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + }, + appUserProfile: { + _id: 'user15', + adminFor: [], + isSuperAdmin: false, + createdOrganizations: [], + createdEvents: [], + eventAdmin: [], + }, + }, +]; From 4b115c73c15de0cdda9b007929ab443fe4ad71d9 Mon Sep 17 00:00:00 2001 From: Aad1tya27 Date: Wed, 25 Dec 2024 01:16:22 +0530 Subject: [PATCH 5/6] moved mock users to test file --- src/screens/Users/Users.spec.tsx | 1105 +++++++++++++++++++++++++++++- src/screens/Users/UsersMocks.ts | 1096 ----------------------------- 2 files changed, 1096 insertions(+), 1105 deletions(-) diff --git a/src/screens/Users/Users.spec.tsx b/src/screens/Users/Users.spec.tsx index e42ec48a8b..74ff0930a9 100644 --- a/src/screens/Users/Users.spec.tsx +++ b/src/screens/Users/Users.spec.tsx @@ -10,13 +10,7 @@ import { store } from 'state/store'; import { StaticMockLink } from 'utils/StaticMockLink'; import i18nForTest from 'utils/i18nForTest'; import Users from './Users'; -import { - EMPTY_MOCKS, - MOCKS, - MOCKS2, - MOCK_USERS, - MOCK_USERS2, -} from './UsersMocks'; +import { EMPTY_MOCKS, MOCKS, MOCKS2 } from './UsersMocks'; import useLocalStorage from 'utils/useLocalstorage'; import { describe, expect, it, beforeEach, afterEach, vi } from 'vitest'; @@ -27,6 +21,1101 @@ import { const { setItem, removeItem } = useLocalStorage(); +const MOCK_USERS = [ + { + user: { + _id: 'user1', + firstName: 'John', + lastName: 'Doe', + image: null, + email: 'john@example.com', + createdAt: '2023-04-13T04:53:17.742+00:00', + registeredEvents: [], + membershipRequests: [], + organizationsBlockedBy: [ + { + _id: 'xyz', + name: 'ABC', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '20/06/2022', + creator: { + _id: '123', + firstName: 'John', + lastName: 'Doe', + image: null, + email: 'john@example.com', + createdAt: '20/06/2022', + }, + }, + ], + joinedOrganizations: [ + { + _id: 'abc', + name: 'Joined Organization 1', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '20/06/2022', + creator: { + _id: '123', + firstName: 'John', + lastName: 'Doe', + image: null, + email: 'john@example.com', + createdAt: '20/06/2022', + }, + }, + ], + }, + appUserProfile: { + _id: 'user1', + adminFor: [ + { + _id: '123', + }, + ], + isSuperAdmin: true, + createdOrganizations: [], + createdEvents: [], + eventAdmin: [], + }, + }, + { + user: { + _id: 'user2', + firstName: 'Jane', + lastName: 'Doe', + image: null, + email: 'john@example.com', + createdAt: '2023-04-17T04:53:17.742+00:00', + registeredEvents: [], + membershipRequests: [], + organizationsBlockedBy: [ + { + _id: '456', + name: 'ABC', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '21/06/2022', + creator: { + _id: '123', + firstName: 'John', + lastName: 'Doe', + image: null, + email: 'john@example.com', + createdAt: '21/06/2022', + }, + }, + ], + joinedOrganizations: [ + { + _id: '123', + name: 'Palisadoes', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '21/06/2022', + creator: { + _id: '123', + firstName: 'John', + lastName: 'Doe', + image: null, + email: 'john@example.com', + createdAt: '21/06/2022', + }, + }, + ], + }, + appUserProfile: { + _id: 'user2', + adminFor: [ + { + _id: '123', + }, + ], + isSuperAdmin: false, + createdOrganizations: [], + createdEvents: [], + eventAdmin: [], + }, + }, + { + user: { + _id: 'user3', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '2023-04-09T04:53:17.742+00:00', + registeredEvents: [], + membershipRequests: [], + organizationsBlockedBy: [ + { + _id: 'xyz', + name: 'ABC', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + joinedOrganizations: [ + { + _id: 'abc', + name: 'Joined Organization 1', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + }, + appUserProfile: { + _id: 'user3', + adminFor: [], + isSuperAdmin: false, + createdOrganizations: [], + createdEvents: [], + eventAdmin: [], + }, + }, +]; + +const MOCK_USERS2 = [ + ...MOCK_USERS, + { + user: { + _id: 'user4', + firstName: 'Emma', + lastName: 'Johnson', + image: null, + email: 'emma@example.com', + createdAt: '2023-04-22T04:53:17.742+00:00', + registeredEvents: [], + membershipRequests: [], + organizationsBlockedBy: [ + { + _id: 'xyz', + name: 'ABC', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + joinedOrganizations: [ + { + _id: 'abc', + name: 'Joined Organization 1', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + }, + appUserProfile: { + _id: 'user4', + adminFor: [], + isSuperAdmin: false, + createdOrganizations: [], + createdEvents: [], + eventAdmin: [], + }, + }, + { + user: { + _id: 'user5', + firstName: 'Liam', + lastName: 'Smith', + image: null, + email: 'liam@example.com', + createdAt: '2023-04-23T04:53:17.742+00:00', + registeredEvents: [], + membershipRequests: [], + organizationsBlockedBy: [ + { + _id: 'xyz', + name: 'ABC', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + joinedOrganizations: [ + { + _id: 'abc', + name: 'Joined Organization 1', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + }, + appUserProfile: { + _id: 'user5', + adminFor: [], + isSuperAdmin: false, + createdOrganizations: [], + createdEvents: [], + eventAdmin: [], + }, + }, + { + user: { + _id: 'user6', + firstName: 'Olivia', + lastName: 'Brown', + image: null, + email: 'olivia@example.com', + createdAt: '2023-04-24T04:53:17.742+00:00', + registeredEvents: [], + membershipRequests: [], + organizationsBlockedBy: [ + { + _id: 'xyz', + name: 'ABC', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + joinedOrganizations: [ + { + _id: 'abc', + name: 'Joined Organization 1', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + }, + appUserProfile: { + _id: 'user6', + adminFor: [], + isSuperAdmin: false, + createdOrganizations: [], + createdEvents: [], + eventAdmin: [], + }, + }, + { + user: { + _id: 'user7', + firstName: 'Noah', + lastName: 'Williams', + image: null, + email: 'noah@example.com', + createdAt: '2023-04-25T04:53:17.742+00:00', + registeredEvents: [], + membershipRequests: [], + organizationsBlockedBy: [ + { + _id: 'xyz', + name: 'ABC', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + joinedOrganizations: [ + { + _id: 'abc', + name: 'Joined Organization 1', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + }, + appUserProfile: { + _id: 'user7', + adminFor: [], + isSuperAdmin: false, + createdOrganizations: [], + createdEvents: [], + eventAdmin: [], + }, + }, + { + user: { + _id: 'user8', + firstName: 'Ava', + lastName: 'Jones', + image: null, + email: 'ava@example.com', + createdAt: '2023-04-26T04:53:17.742+00:00', + registeredEvents: [], + membershipRequests: [], + organizationsBlockedBy: [ + { + _id: 'xyz', + name: 'ABC', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + joinedOrganizations: [ + { + _id: 'abc', + name: 'Joined Organization 1', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + }, + appUserProfile: { + _id: 'user8', + adminFor: [], + isSuperAdmin: false, + createdOrganizations: [], + createdEvents: [], + eventAdmin: [], + }, + }, + { + user: { + _id: 'user9', + firstName: 'Ethan', + lastName: 'Garcia', + image: null, + email: 'ethan@example.com', + createdAt: '2023-04-27T04:53:17.742+00:00', + registeredEvents: [], + membershipRequests: [], + organizationsBlockedBy: [ + { + _id: 'xyz', + name: 'ABC', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + joinedOrganizations: [ + { + _id: 'abc', + name: 'Joined Organization 1', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + }, + appUserProfile: { + _id: 'user9', + adminFor: [], + isSuperAdmin: false, + createdOrganizations: [], + createdEvents: [], + eventAdmin: [], + }, + }, + { + user: { + _id: 'user10', + firstName: 'Sophia', + lastName: 'Martinez', + image: null, + email: 'sophia@example.com', + createdAt: '2023-04-28T04:53:17.742+00:00', + registeredEvents: [], + membershipRequests: [], + organizationsBlockedBy: [ + { + _id: 'xyz', + name: 'ABC', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + joinedOrganizations: [ + { + _id: 'abc', + name: 'Joined Organization 1', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + }, + appUserProfile: { + _id: 'user10', + adminFor: [], + isSuperAdmin: false, + createdOrganizations: [], + createdEvents: [], + eventAdmin: [], + }, + }, + { + user: { + _id: 'user11', + firstName: 'Mason', + lastName: 'Davis', + image: null, + email: 'mason@example.com', + createdAt: '2023-04-29T04:53:17.742+00:00', + registeredEvents: [], + membershipRequests: [], + organizationsBlockedBy: [ + { + _id: 'xyz', + name: 'ABC', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + joinedOrganizations: [ + { + _id: 'abc', + name: 'Joined Organization 1', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + }, + appUserProfile: { + _id: 'user11', + adminFor: [], + isSuperAdmin: false, + createdOrganizations: [], + createdEvents: [], + eventAdmin: [], + }, + }, + { + user: { + _id: 'user12', + firstName: 'Isabella', + lastName: 'Rodriguez', + image: null, + email: 'isabella@example.com', + createdAt: '2023-04-30T04:53:17.742+00:00', + registeredEvents: [], + membershipRequests: [], + organizationsBlockedBy: [ + { + _id: 'xyz', + name: 'ABC', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + joinedOrganizations: [ + { + _id: 'abc', + name: 'Joined Organization 1', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + }, + appUserProfile: { + _id: 'user12', + adminFor: [], + isSuperAdmin: false, + createdOrganizations: [], + createdEvents: [], + eventAdmin: [], + }, + }, + { + user: { + _id: 'user13', + firstName: 'Logan', + lastName: 'Wilson', + image: null, + email: 'logan@example.com', + createdAt: '2023-04-08T04:53:17.742+00:00', + registeredEvents: [], + membershipRequests: [], + organizationsBlockedBy: [ + { + _id: 'xyz', + name: 'ABC', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + joinedOrganizations: [ + { + _id: 'abc', + name: 'Joined Organization 1', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + }, + appUserProfile: { + _id: 'user13', + adminFor: [], + isSuperAdmin: false, + createdOrganizations: [], + createdEvents: [], + eventAdmin: [], + }, + }, + { + user: { + _id: 'user14', + firstName: 'Mia', + lastName: 'Anderson', + image: null, + email: 'mia@example.com', + createdAt: '2023-04-07T04:53:17.742+00:00', + registeredEvents: [], + membershipRequests: [], + organizationsBlockedBy: [ + { + _id: 'xyz', + name: 'ABC', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + joinedOrganizations: [ + { + _id: 'abc', + name: 'Joined Organization 1', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + }, + appUserProfile: { + _id: 'user14', + adminFor: [], + isSuperAdmin: false, + createdOrganizations: [], + createdEvents: [], + eventAdmin: [], + }, + }, + { + user: { + _id: 'user15', + firstName: 'Lucas', + lastName: 'Thomas', + image: null, + email: 'lucas@example.com', + createdAt: '2023-04-05T04:53:17.742+00:00', + registeredEvents: [], + membershipRequests: [], + organizationsBlockedBy: [ + { + _id: 'xyz', + name: 'ABC', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + joinedOrganizations: [ + { + _id: 'abc', + name: 'Joined Organization 1', + image: null, + address: { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', + }, + createdAt: '19/06/2022', + creator: { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', + }, + }, + ], + }, + appUserProfile: { + _id: 'user15', + adminFor: [], + isSuperAdmin: false, + createdOrganizations: [], + createdEvents: [], + eventAdmin: [], + }, + }, +]; + const MOCKS_NEW = [ { request: { @@ -849,7 +1938,6 @@ describe('Testing Users screen', () => { const users = container .getElementsByTagName('tbody')[0] .querySelectorAll('tr'); - console.log(users, users.length); expect(users.length).toBe(12); await act(async () => { @@ -861,7 +1949,6 @@ describe('Testing Users screen', () => { const users2 = container .getElementsByTagName('tbody')[0] .querySelectorAll('tr'); - console.log(users2, users2.length); expect(users2.length).toBe(15); }); diff --git a/src/screens/Users/UsersMocks.ts b/src/screens/Users/UsersMocks.ts index d4f0537e5e..f7908cf675 100644 --- a/src/screens/Users/UsersMocks.ts +++ b/src/screens/Users/UsersMocks.ts @@ -478,7 +478,6 @@ export const EMPTY_MOCKS = [ { request: { query: USER_LIST, - variables: { first: 12, skip: 0, @@ -503,1098 +502,3 @@ export const EMPTY_MOCKS = [ }, }, ]; - -export const MOCK_USERS = [ - { - user: { - _id: 'user1', - firstName: 'John', - lastName: 'Doe', - image: null, - email: 'john@example.com', - createdAt: '2023-04-13T04:53:17.742+00:00', - registeredEvents: [], - membershipRequests: [], - organizationsBlockedBy: [ - { - _id: 'xyz', - name: 'ABC', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '20/06/2022', - creator: { - _id: '123', - firstName: 'John', - lastName: 'Doe', - image: null, - email: 'john@example.com', - createdAt: '20/06/2022', - }, - }, - ], - joinedOrganizations: [ - { - _id: 'abc', - name: 'Joined Organization 1', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '20/06/2022', - creator: { - _id: '123', - firstName: 'John', - lastName: 'Doe', - image: null, - email: 'john@example.com', - createdAt: '20/06/2022', - }, - }, - ], - }, - appUserProfile: { - _id: 'user1', - adminFor: [ - { - _id: '123', - }, - ], - isSuperAdmin: true, - createdOrganizations: [], - createdEvents: [], - eventAdmin: [], - }, - }, - { - user: { - _id: 'user2', - firstName: 'Jane', - lastName: 'Doe', - image: null, - email: 'john@example.com', - createdAt: '2023-04-17T04:53:17.742+00:00', - registeredEvents: [], - membershipRequests: [], - organizationsBlockedBy: [ - { - _id: '456', - name: 'ABC', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '21/06/2022', - creator: { - _id: '123', - firstName: 'John', - lastName: 'Doe', - image: null, - email: 'john@example.com', - createdAt: '21/06/2022', - }, - }, - ], - joinedOrganizations: [ - { - _id: '123', - name: 'Palisadoes', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '21/06/2022', - creator: { - _id: '123', - firstName: 'John', - lastName: 'Doe', - image: null, - email: 'john@example.com', - createdAt: '21/06/2022', - }, - }, - ], - }, - appUserProfile: { - _id: 'user2', - adminFor: [ - { - _id: '123', - }, - ], - isSuperAdmin: false, - createdOrganizations: [], - createdEvents: [], - eventAdmin: [], - }, - }, - { - user: { - _id: 'user3', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '2023-04-09T04:53:17.742+00:00', - registeredEvents: [], - membershipRequests: [], - organizationsBlockedBy: [ - { - _id: 'xyz', - name: 'ABC', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - joinedOrganizations: [ - { - _id: 'abc', - name: 'Joined Organization 1', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - }, - appUserProfile: { - _id: 'user3', - adminFor: [], - isSuperAdmin: false, - createdOrganizations: [], - createdEvents: [], - eventAdmin: [], - }, - }, -]; - -export const MOCK_USERS2 = [ - ...MOCK_USERS, - { - user: { - _id: 'user4', - firstName: 'Emma', - lastName: 'Johnson', - image: null, - email: 'emma@example.com', - createdAt: '2023-04-22T04:53:17.742+00:00', - registeredEvents: [], - membershipRequests: [], - organizationsBlockedBy: [ - { - _id: 'xyz', - name: 'ABC', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - joinedOrganizations: [ - { - _id: 'abc', - name: 'Joined Organization 1', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - }, - appUserProfile: { - _id: 'user4', - adminFor: [], - isSuperAdmin: false, - createdOrganizations: [], - createdEvents: [], - eventAdmin: [], - }, - }, - { - user: { - _id: 'user5', - firstName: 'Liam', - lastName: 'Smith', - image: null, - email: 'liam@example.com', - createdAt: '2023-04-23T04:53:17.742+00:00', - registeredEvents: [], - membershipRequests: [], - organizationsBlockedBy: [ - { - _id: 'xyz', - name: 'ABC', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - joinedOrganizations: [ - { - _id: 'abc', - name: 'Joined Organization 1', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - }, - appUserProfile: { - _id: 'user5', - adminFor: [], - isSuperAdmin: false, - createdOrganizations: [], - createdEvents: [], - eventAdmin: [], - }, - }, - { - user: { - _id: 'user6', - firstName: 'Olivia', - lastName: 'Brown', - image: null, - email: 'olivia@example.com', - createdAt: '2023-04-24T04:53:17.742+00:00', - registeredEvents: [], - membershipRequests: [], - organizationsBlockedBy: [ - { - _id: 'xyz', - name: 'ABC', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - joinedOrganizations: [ - { - _id: 'abc', - name: 'Joined Organization 1', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - }, - appUserProfile: { - _id: 'user6', - adminFor: [], - isSuperAdmin: false, - createdOrganizations: [], - createdEvents: [], - eventAdmin: [], - }, - }, - { - user: { - _id: 'user7', - firstName: 'Noah', - lastName: 'Williams', - image: null, - email: 'noah@example.com', - createdAt: '2023-04-25T04:53:17.742+00:00', - registeredEvents: [], - membershipRequests: [], - organizationsBlockedBy: [ - { - _id: 'xyz', - name: 'ABC', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - joinedOrganizations: [ - { - _id: 'abc', - name: 'Joined Organization 1', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - }, - appUserProfile: { - _id: 'user7', - adminFor: [], - isSuperAdmin: false, - createdOrganizations: [], - createdEvents: [], - eventAdmin: [], - }, - }, - { - user: { - _id: 'user8', - firstName: 'Ava', - lastName: 'Jones', - image: null, - email: 'ava@example.com', - createdAt: '2023-04-26T04:53:17.742+00:00', - registeredEvents: [], - membershipRequests: [], - organizationsBlockedBy: [ - { - _id: 'xyz', - name: 'ABC', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - joinedOrganizations: [ - { - _id: 'abc', - name: 'Joined Organization 1', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - }, - appUserProfile: { - _id: 'user8', - adminFor: [], - isSuperAdmin: false, - createdOrganizations: [], - createdEvents: [], - eventAdmin: [], - }, - }, - { - user: { - _id: 'user9', - firstName: 'Ethan', - lastName: 'Garcia', - image: null, - email: 'ethan@example.com', - createdAt: '2023-04-27T04:53:17.742+00:00', - registeredEvents: [], - membershipRequests: [], - organizationsBlockedBy: [ - { - _id: 'xyz', - name: 'ABC', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - joinedOrganizations: [ - { - _id: 'abc', - name: 'Joined Organization 1', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - }, - appUserProfile: { - _id: 'user9', - adminFor: [], - isSuperAdmin: false, - createdOrganizations: [], - createdEvents: [], - eventAdmin: [], - }, - }, - { - user: { - _id: 'user10', - firstName: 'Sophia', - lastName: 'Martinez', - image: null, - email: 'sophia@example.com', - createdAt: '2023-04-28T04:53:17.742+00:00', - registeredEvents: [], - membershipRequests: [], - organizationsBlockedBy: [ - { - _id: 'xyz', - name: 'ABC', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - joinedOrganizations: [ - { - _id: 'abc', - name: 'Joined Organization 1', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - }, - appUserProfile: { - _id: 'user10', - adminFor: [], - isSuperAdmin: false, - createdOrganizations: [], - createdEvents: [], - eventAdmin: [], - }, - }, - { - user: { - _id: 'user11', - firstName: 'Mason', - lastName: 'Davis', - image: null, - email: 'mason@example.com', - createdAt: '2023-04-29T04:53:17.742+00:00', - registeredEvents: [], - membershipRequests: [], - organizationsBlockedBy: [ - { - _id: 'xyz', - name: 'ABC', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - joinedOrganizations: [ - { - _id: 'abc', - name: 'Joined Organization 1', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - }, - appUserProfile: { - _id: 'user11', - adminFor: [], - isSuperAdmin: false, - createdOrganizations: [], - createdEvents: [], - eventAdmin: [], - }, - }, - { - user: { - _id: 'user12', - firstName: 'Isabella', - lastName: 'Rodriguez', - image: null, - email: 'isabella@example.com', - createdAt: '2023-04-30T04:53:17.742+00:00', - registeredEvents: [], - membershipRequests: [], - organizationsBlockedBy: [ - { - _id: 'xyz', - name: 'ABC', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - joinedOrganizations: [ - { - _id: 'abc', - name: 'Joined Organization 1', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - }, - appUserProfile: { - _id: 'user12', - adminFor: [], - isSuperAdmin: false, - createdOrganizations: [], - createdEvents: [], - eventAdmin: [], - }, - }, - { - user: { - _id: 'user13', - firstName: 'Logan', - lastName: 'Wilson', - image: null, - email: 'logan@example.com', - createdAt: '2023-04-08T04:53:17.742+00:00', - registeredEvents: [], - membershipRequests: [], - organizationsBlockedBy: [ - { - _id: 'xyz', - name: 'ABC', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - joinedOrganizations: [ - { - _id: 'abc', - name: 'Joined Organization 1', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - }, - appUserProfile: { - _id: 'user13', - adminFor: [], - isSuperAdmin: false, - createdOrganizations: [], - createdEvents: [], - eventAdmin: [], - }, - }, - { - user: { - _id: 'user14', - firstName: 'Mia', - lastName: 'Anderson', - image: null, - email: 'mia@example.com', - createdAt: '2023-04-07T04:53:17.742+00:00', - registeredEvents: [], - membershipRequests: [], - organizationsBlockedBy: [ - { - _id: 'xyz', - name: 'ABC', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - joinedOrganizations: [ - { - _id: 'abc', - name: 'Joined Organization 1', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - }, - appUserProfile: { - _id: 'user14', - adminFor: [], - isSuperAdmin: false, - createdOrganizations: [], - createdEvents: [], - eventAdmin: [], - }, - }, - { - user: { - _id: 'user15', - firstName: 'Lucas', - lastName: 'Thomas', - image: null, - email: 'lucas@example.com', - createdAt: '2023-04-05T04:53:17.742+00:00', - registeredEvents: [], - membershipRequests: [], - organizationsBlockedBy: [ - { - _id: 'xyz', - name: 'ABC', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - joinedOrganizations: [ - { - _id: 'abc', - name: 'Joined Organization 1', - image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, - createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, - }, - ], - }, - appUserProfile: { - _id: 'user15', - adminFor: [], - isSuperAdmin: false, - createdOrganizations: [], - createdEvents: [], - eventAdmin: [], - }, - }, -]; From 32c45a31a51d415077ca1c1ab37a79c9c8c7896d Mon Sep 17 00:00:00 2001 From: Aad1tya27 Date: Wed, 25 Dec 2024 01:31:11 +0530 Subject: [PATCH 6/6] got rid of redundant code --- src/screens/Users/Users.spec.tsx | 584 ++++--------------------------- 1 file changed, 76 insertions(+), 508 deletions(-) diff --git a/src/screens/Users/Users.spec.tsx b/src/screens/Users/Users.spec.tsx index 74ff0930a9..1457bec5b8 100644 --- a/src/screens/Users/Users.spec.tsx +++ b/src/screens/Users/Users.spec.tsx @@ -21,6 +21,26 @@ import { const { setItem, removeItem } = useLocalStorage(); +const createAddress = { + city: 'Kingston', + countryCode: 'JM', + dependentLocality: 'Sample Dependent Locality', + line1: '123 Jamaica Street', + line2: 'Apartment 456', + postalCode: 'JM12345', + sortingCode: 'ABC-123', + state: 'Kingston Parish', +}; + +const createCreator = { + _id: '123', + firstName: 'Jack', + lastName: 'Smith', + image: null, + email: 'jack@example.com', + createdAt: '19/06/2022', +}; + const MOCK_USERS = [ { user: { @@ -37,16 +57,7 @@ const MOCK_USERS = [ _id: 'xyz', name: 'ABC', image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, + address: createAddress, createdAt: '20/06/2022', creator: { _id: '123', @@ -63,16 +74,7 @@ const MOCK_USERS = [ _id: 'abc', name: 'Joined Organization 1', image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, + address: createAddress, createdAt: '20/06/2022', creator: { _id: '123', @@ -113,16 +115,7 @@ const MOCK_USERS = [ _id: '456', name: 'ABC', image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, + address: createAddress, createdAt: '21/06/2022', creator: { _id: '123', @@ -139,16 +132,7 @@ const MOCK_USERS = [ _id: '123', name: 'Palisadoes', image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, + address: createAddress, createdAt: '21/06/2022', creator: { _id: '123', @@ -189,25 +173,9 @@ const MOCK_USERS = [ _id: 'xyz', name: 'ABC', image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, + address: createAddress, createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, + creator: createCreator, }, ], joinedOrganizations: [ @@ -215,25 +183,9 @@ const MOCK_USERS = [ _id: 'abc', name: 'Joined Organization 1', image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, + address: createAddress, createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, + creator: createCreator, }, ], }, @@ -265,25 +217,9 @@ const MOCK_USERS2 = [ _id: 'xyz', name: 'ABC', image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, + address: createAddress, createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, + creator: createCreator, }, ], joinedOrganizations: [ @@ -291,25 +227,9 @@ const MOCK_USERS2 = [ _id: 'abc', name: 'Joined Organization 1', image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, + address: createAddress, createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, + creator: createCreator, }, ], }, @@ -337,25 +257,9 @@ const MOCK_USERS2 = [ _id: 'xyz', name: 'ABC', image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, + address: createAddress, createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, + creator: createCreator, }, ], joinedOrganizations: [ @@ -363,25 +267,9 @@ const MOCK_USERS2 = [ _id: 'abc', name: 'Joined Organization 1', image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, + address: createAddress, createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, + creator: createCreator, }, ], }, @@ -409,25 +297,9 @@ const MOCK_USERS2 = [ _id: 'xyz', name: 'ABC', image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, + address: createAddress, createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, + creator: createCreator, }, ], joinedOrganizations: [ @@ -435,25 +307,9 @@ const MOCK_USERS2 = [ _id: 'abc', name: 'Joined Organization 1', image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, + address: createAddress, createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, + creator: createCreator, }, ], }, @@ -481,25 +337,9 @@ const MOCK_USERS2 = [ _id: 'xyz', name: 'ABC', image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, + address: createAddress, createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, + creator: createCreator, }, ], joinedOrganizations: [ @@ -507,25 +347,9 @@ const MOCK_USERS2 = [ _id: 'abc', name: 'Joined Organization 1', image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, + address: createAddress, createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, + creator: createCreator, }, ], }, @@ -553,25 +377,9 @@ const MOCK_USERS2 = [ _id: 'xyz', name: 'ABC', image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, + address: createAddress, createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, + creator: createCreator, }, ], joinedOrganizations: [ @@ -579,25 +387,9 @@ const MOCK_USERS2 = [ _id: 'abc', name: 'Joined Organization 1', image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, + address: createAddress, createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, + creator: createCreator, }, ], }, @@ -625,25 +417,9 @@ const MOCK_USERS2 = [ _id: 'xyz', name: 'ABC', image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, + address: createAddress, createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, + creator: createCreator, }, ], joinedOrganizations: [ @@ -651,25 +427,9 @@ const MOCK_USERS2 = [ _id: 'abc', name: 'Joined Organization 1', image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, + address: createAddress, createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, + creator: createCreator, }, ], }, @@ -697,25 +457,9 @@ const MOCK_USERS2 = [ _id: 'xyz', name: 'ABC', image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, + address: createAddress, createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, + creator: createCreator, }, ], joinedOrganizations: [ @@ -723,25 +467,9 @@ const MOCK_USERS2 = [ _id: 'abc', name: 'Joined Organization 1', image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, + address: createAddress, createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, + creator: createCreator, }, ], }, @@ -769,25 +497,9 @@ const MOCK_USERS2 = [ _id: 'xyz', name: 'ABC', image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, + address: createAddress, createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, + creator: createCreator, }, ], joinedOrganizations: [ @@ -795,25 +507,9 @@ const MOCK_USERS2 = [ _id: 'abc', name: 'Joined Organization 1', image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, + address: createAddress, createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, + creator: createCreator, }, ], }, @@ -841,25 +537,9 @@ const MOCK_USERS2 = [ _id: 'xyz', name: 'ABC', image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, + address: createAddress, createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, + creator: createCreator, }, ], joinedOrganizations: [ @@ -867,25 +547,9 @@ const MOCK_USERS2 = [ _id: 'abc', name: 'Joined Organization 1', image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, + address: createAddress, createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, + creator: createCreator, }, ], }, @@ -913,25 +577,9 @@ const MOCK_USERS2 = [ _id: 'xyz', name: 'ABC', image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, + address: createAddress, createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, + creator: createCreator, }, ], joinedOrganizations: [ @@ -939,25 +587,9 @@ const MOCK_USERS2 = [ _id: 'abc', name: 'Joined Organization 1', image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, + address: createAddress, createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, + creator: createCreator, }, ], }, @@ -985,25 +617,9 @@ const MOCK_USERS2 = [ _id: 'xyz', name: 'ABC', image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, + address: createAddress, createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, + creator: createCreator, }, ], joinedOrganizations: [ @@ -1011,25 +627,9 @@ const MOCK_USERS2 = [ _id: 'abc', name: 'Joined Organization 1', image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, + address: createAddress, createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, + creator: createCreator, }, ], }, @@ -1057,25 +657,9 @@ const MOCK_USERS2 = [ _id: 'xyz', name: 'ABC', image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, + address: createAddress, createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, + creator: createCreator, }, ], joinedOrganizations: [ @@ -1083,25 +667,9 @@ const MOCK_USERS2 = [ _id: 'abc', name: 'Joined Organization 1', image: null, - address: { - city: 'Kingston', - countryCode: 'JM', - dependentLocality: 'Sample Dependent Locality', - line1: '123 Jamaica Street', - line2: 'Apartment 456', - postalCode: 'JM12345', - sortingCode: 'ABC-123', - state: 'Kingston Parish', - }, + address: createAddress, createdAt: '19/06/2022', - creator: { - _id: '123', - firstName: 'Jack', - lastName: 'Smith', - image: null, - email: 'jack@example.com', - createdAt: '19/06/2022', - }, + creator: createCreator, }, ], },