diff --git a/src/screens/Users/Organization.mocks.ts b/src/screens/Users/Organization.mocks.ts
new file mode 100644
index 0000000000..d32dc9fd7b
--- /dev/null
+++ b/src/screens/Users/Organization.mocks.ts
@@ -0,0 +1,370 @@
+interface InterfaceAddress {
+ city: string;
+ countryCode: string;
+ dependentLocality: string;
+ line1: string;
+ line2: string;
+ postalCode: string;
+ sortingCode: string;
+ state: string;
+}
+
+interface InterfaceCreator {
+ _id: string;
+ firstName: string;
+ lastName: string;
+ image: string | null;
+ email: string;
+ createdAt: string;
+}
+
+interface InterfaceOrganization {
+ _id: string;
+ name: string;
+ image: string | null;
+ address: InterfaceAddress;
+ createdAt: string;
+ creator: InterfaceCreator;
+}
+
+interface InterfaceUser {
+ _id: string;
+ firstName: string;
+ lastName: string;
+ image: string | null;
+ email: string;
+ createdAt: string;
+ registeredEvents: [];
+ membershipRequests: [];
+ organizationsBlockedBy: InterfaceOrganization[];
+ joinedOrganizations: InterfaceOrganization[];
+}
+
+interface InterfaceAppUserProfile {
+ _id: string;
+ adminFor: { _id: string }[];
+ isSuperAdmin: boolean;
+ createdOrganizations: [];
+ createdEvents: [];
+ eventAdmin: [];
+}
+
+interface InterfaceMockUser {
+ user: InterfaceUser;
+ appUserProfile: InterfaceAppUserProfile;
+}
+
+export 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',
+};
+
+export const createCreator = {
+ _id: '123',
+ firstName: 'Jack',
+ lastName: 'Smith',
+ image: null,
+ email: 'jack@example.com',
+ createdAt: '19/06/2022',
+};
+
+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: createAddress,
+ 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: createAddress,
+ 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: 'jane@example.com',
+ createdAt: '2023-04-17T04:53:17.742+00:00',
+ registeredEvents: [],
+ membershipRequests: [],
+ organizationsBlockedBy: [
+ {
+ _id: '456',
+ name: 'ABC',
+ image: null,
+ address: createAddress,
+ 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: createAddress,
+ 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: createAddress,
+ createdAt: '19/06/2022',
+ creator: createCreator,
+ },
+ ],
+ joinedOrganizations: [
+ {
+ _id: 'abc',
+ name: 'Joined Organization 1',
+ image: null,
+ address: createAddress,
+ createdAt: '19/06/2022',
+ creator: createCreator,
+ },
+ ],
+ },
+ appUserProfile: {
+ _id: 'user3',
+ adminFor: [],
+ isSuperAdmin: false,
+ createdOrganizations: [],
+ createdEvents: [],
+ eventAdmin: [],
+ },
+ },
+];
+
+export const generateMockUser = (
+ id: string,
+ firstName: string,
+ lastName: string,
+ email: string,
+ createdAt: string,
+ isSuperAdmin = false,
+): InterfaceMockUser => ({
+ user: {
+ _id: id,
+ firstName,
+ lastName,
+ image: null,
+ email,
+ createdAt,
+ registeredEvents: [],
+ membershipRequests: [],
+ organizationsBlockedBy: [
+ {
+ _id: 'xyz',
+ name: 'ABC',
+ image: null,
+ address: createAddress,
+ createdAt: '19/06/2022',
+ creator: createCreator,
+ },
+ ],
+ joinedOrganizations: [
+ {
+ _id: 'abc',
+ name: 'Joined Organization 1',
+ image: null,
+ address: createAddress,
+ createdAt: '19/06/2022',
+ creator: createCreator,
+ },
+ ],
+ },
+ appUserProfile: {
+ _id: id,
+ adminFor: isSuperAdmin ? [{ _id: '123' }] : [],
+ isSuperAdmin,
+ createdOrganizations: [],
+ createdEvents: [],
+ eventAdmin: [],
+ },
+});
+
+export const MOCK_USERS2 = [
+ ...MOCK_USERS,
+ generateMockUser(
+ 'user4',
+ 'Emma',
+ 'Johnson',
+ 'emma@example.com',
+ '2023-04-22T04:53:17.742+00:00',
+ ),
+ generateMockUser(
+ 'user5',
+ 'Liam',
+ 'Smith',
+ 'liam@example.com',
+ '2023-04-23T04:53:17.742+00:00',
+ ),
+ generateMockUser(
+ 'user6',
+ 'Olivia',
+ 'Brown',
+ 'olivia@example.com',
+ '2023-04-24T04:53:17.742+00:00',
+ ),
+ generateMockUser(
+ 'user7',
+ 'Noah',
+ 'Williams',
+ 'noah@example.com',
+ '2023-04-25T04:53:17.742+00:00',
+ ),
+ generateMockUser(
+ 'user8',
+ 'Ava',
+ 'Jones',
+ 'ava@example.com',
+ '2023-04-26T04:53:17.742+00:00',
+ ),
+ generateMockUser(
+ 'user9',
+ 'Ethan',
+ 'Garcia',
+ 'ethan@example.com',
+ '2023-04-27T04:53:17.742+00:00',
+ ),
+ generateMockUser(
+ 'user10',
+ 'Sophia',
+ 'Martinez',
+ 'sophia@example.com',
+ '2023-04-28T04:53:17.742+00:00',
+ ),
+ generateMockUser(
+ 'user11',
+ 'Mason',
+ 'Davis',
+ 'mason@example.com',
+ '2023-04-29T04:53:17.742+00:00',
+ ),
+ generateMockUser(
+ 'user12',
+ 'Isabella',
+ 'Rodriguez',
+ 'isabella@example.com',
+ '2023-04-30T04:53:17.742+00:00',
+ ),
+ generateMockUser(
+ 'user13',
+ 'Logan',
+ 'Wilson',
+ 'logan@example.com',
+ '2023-04-08T04:53:17.742+00:00',
+ ),
+ generateMockUser(
+ 'user14',
+ 'Mia',
+ 'Anderson',
+ 'mia@example.com',
+ '2023-04-07T04:53:17.742+00:00',
+ ),
+ generateMockUser(
+ 'user15',
+ 'Lucas',
+ 'Thomas',
+ 'lucas@example.com',
+ '2023-04-05T04:53:17.742+00:00',
+ ),
+];
diff --git a/src/screens/Users/UsersMocks.ts b/src/screens/Users/User.mocks.ts
similarity index 96%
rename from src/screens/Users/UsersMocks.ts
rename to src/screens/Users/User.mocks.ts
index f7908cf675..c1a9035550 100644
--- a/src/screens/Users/UsersMocks.ts
+++ b/src/screens/Users/User.mocks.ts
@@ -41,7 +41,7 @@ export const MOCKS = [
lastName: 'Doe',
image: null,
email: 'john@example.com',
- createdAt: '20/06/2022',
+ createdAt: '2022-06-20T00:00:00.000Z',
registeredEvents: [],
membershipRequests: [],
organizationsBlockedBy: [
@@ -116,7 +116,7 @@ export const MOCKS = [
firstName: 'Jane',
lastName: 'Doe',
image: null,
- email: 'john@example.com',
+ email: 'jane@example.com',
createdAt: '20/06/2022',
registeredEvents: [],
membershipRequests: [],
@@ -351,7 +351,7 @@ export const MOCKS2 = [
firstName: 'Jane',
lastName: 'Doe',
image: null,
- email: 'john@example.com',
+ email: 'jane@example.com',
createdAt: '20/06/2022',
registeredEvents: [],
membershipRequests: [],
@@ -473,32 +473,3 @@ export const MOCKS2 = [
},
},
];
-
-export const EMPTY_MOCKS = [
- {
- request: {
- query: USER_LIST,
- variables: {
- first: 12,
- skip: 0,
- firstName_contains: '',
- lastName_contains: '',
- },
- },
- result: {
- data: {
- users: [],
- },
- },
- },
- {
- request: {
- query: ORGANIZATION_CONNECTION_LIST,
- },
- result: {
- data: {
- organizationsConnection: [],
- },
- },
- },
-];
diff --git a/src/screens/Users/Users.spec.tsx b/src/screens/Users/Users.spec.tsx
index 1457bec5b8..6d2349de97 100644
--- a/src/screens/Users/Users.spec.tsx
+++ b/src/screens/Users/Users.spec.tsx
@@ -10,842 +10,22 @@ 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_NEW,
+ MOCKS_NEW2,
+ MOCKS_NEW3,
+ MOCKS_NEW_2,
+} from './UsersMocks.mocks';
+import { generateMockUser } from './Organization.mocks';
+import { MOCKS, MOCKS2 } from './User.mocks';
import useLocalStorage from 'utils/useLocalstorage';
import { describe, expect, it, beforeEach, afterEach, vi } from 'vitest';
-import {
- USER_LIST,
- ORGANIZATION_CONNECTION_LIST,
-} from 'GraphQl/Queries/Queries';
+import { USER_LIST } from 'GraphQl/Queries/Queries';
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: {
- _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: createAddress,
- 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: createAddress,
- 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: createAddress,
- 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: createAddress,
- 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: createAddress,
- createdAt: '19/06/2022',
- creator: createCreator,
- },
- ],
- joinedOrganizations: [
- {
- _id: 'abc',
- name: 'Joined Organization 1',
- image: null,
- address: createAddress,
- createdAt: '19/06/2022',
- creator: createCreator,
- },
- ],
- },
- 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: createAddress,
- createdAt: '19/06/2022',
- creator: createCreator,
- },
- ],
- joinedOrganizations: [
- {
- _id: 'abc',
- name: 'Joined Organization 1',
- image: null,
- address: createAddress,
- createdAt: '19/06/2022',
- creator: createCreator,
- },
- ],
- },
- 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: createAddress,
- createdAt: '19/06/2022',
- creator: createCreator,
- },
- ],
- joinedOrganizations: [
- {
- _id: 'abc',
- name: 'Joined Organization 1',
- image: null,
- address: createAddress,
- createdAt: '19/06/2022',
- creator: createCreator,
- },
- ],
- },
- 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: createAddress,
- createdAt: '19/06/2022',
- creator: createCreator,
- },
- ],
- joinedOrganizations: [
- {
- _id: 'abc',
- name: 'Joined Organization 1',
- image: null,
- address: createAddress,
- createdAt: '19/06/2022',
- creator: createCreator,
- },
- ],
- },
- 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: createAddress,
- createdAt: '19/06/2022',
- creator: createCreator,
- },
- ],
- joinedOrganizations: [
- {
- _id: 'abc',
- name: 'Joined Organization 1',
- image: null,
- address: createAddress,
- createdAt: '19/06/2022',
- creator: createCreator,
- },
- ],
- },
- 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: createAddress,
- createdAt: '19/06/2022',
- creator: createCreator,
- },
- ],
- joinedOrganizations: [
- {
- _id: 'abc',
- name: 'Joined Organization 1',
- image: null,
- address: createAddress,
- createdAt: '19/06/2022',
- creator: createCreator,
- },
- ],
- },
- 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: createAddress,
- createdAt: '19/06/2022',
- creator: createCreator,
- },
- ],
- joinedOrganizations: [
- {
- _id: 'abc',
- name: 'Joined Organization 1',
- image: null,
- address: createAddress,
- createdAt: '19/06/2022',
- creator: createCreator,
- },
- ],
- },
- 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: createAddress,
- createdAt: '19/06/2022',
- creator: createCreator,
- },
- ],
- joinedOrganizations: [
- {
- _id: 'abc',
- name: 'Joined Organization 1',
- image: null,
- address: createAddress,
- createdAt: '19/06/2022',
- creator: createCreator,
- },
- ],
- },
- 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: createAddress,
- createdAt: '19/06/2022',
- creator: createCreator,
- },
- ],
- joinedOrganizations: [
- {
- _id: 'abc',
- name: 'Joined Organization 1',
- image: null,
- address: createAddress,
- createdAt: '19/06/2022',
- creator: createCreator,
- },
- ],
- },
- 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: createAddress,
- createdAt: '19/06/2022',
- creator: createCreator,
- },
- ],
- joinedOrganizations: [
- {
- _id: 'abc',
- name: 'Joined Organization 1',
- image: null,
- address: createAddress,
- createdAt: '19/06/2022',
- creator: createCreator,
- },
- ],
- },
- 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: createAddress,
- createdAt: '19/06/2022',
- creator: createCreator,
- },
- ],
- joinedOrganizations: [
- {
- _id: 'abc',
- name: 'Joined Organization 1',
- image: null,
- address: createAddress,
- createdAt: '19/06/2022',
- creator: createCreator,
- },
- ],
- },
- 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: createAddress,
- createdAt: '19/06/2022',
- creator: createCreator,
- },
- ],
- joinedOrganizations: [
- {
- _id: 'abc',
- name: 'Joined Organization 1',
- image: null,
- address: createAddress,
- createdAt: '19/06/2022',
- creator: createCreator,
- },
- ],
- },
- 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: createAddress,
- createdAt: '19/06/2022',
- creator: createCreator,
- },
- ],
- joinedOrganizations: [
- {
- _id: 'abc',
- name: 'Joined Organization 1',
- image: null,
- address: createAddress,
- createdAt: '19/06/2022',
- creator: createCreator,
- },
- ],
- },
- appUserProfile: {
- _id: 'user15',
- adminFor: [],
- isSuperAdmin: false,
- createdOrganizations: [],
- createdEvents: [],
- eventAdmin: [],
- },
- },
-];
-
-const MOCKS_NEW = [
- {
- request: {
- query: USER_LIST,
- variables: {
- first: 12,
- skip: 0,
- firstName_contains: '',
- lastName_contains: '',
- order: 'createdAt_DESC',
- },
- },
- result: {
- data: {
- users: MOCK_USERS,
- },
- },
- },
- {
- request: {
- query: ORGANIZATION_CONNECTION_LIST,
- },
- result: {
- data: {
- organizationsConnection: [],
- },
- },
- },
-];
-
-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 MOCKS_NEW3 = [
- {
- 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(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: [],
- },
- },
- },
-];
-
const link = new StaticMockLink(MOCKS, true);
const link2 = new StaticMockLink(EMPTY_MOCKS, true);
const link3 = new StaticMockLink(MOCKS2, true);
@@ -1550,4 +730,142 @@ describe('Testing Users screen', () => {
.querySelectorAll('tr');
expect(users2.length).toBe(15);
});
+
+ it('should render "No results found" message with search query when search returns no users and isLoading is false', async () => {
+ render(
+
+
+
+
+
+
+
+
+ ,
+ );
+
+ await wait();
+
+ const searchBtn = screen.getByTestId('searchButton');
+ const searchInput = screen.getByTestId(/searchByName/i);
+
+ await act(async () => {
+ userEvent.clear(searchInput);
+ userEvent.type(searchInput, 'NonexistentName');
+ userEvent.click(searchBtn);
+ });
+
+ const noResultsMessage = screen.getByText(/No results found for/i);
+ expect(noResultsMessage).toBeInTheDocument();
+ expect(noResultsMessage).toHaveTextContent('NonexistentName');
+ });
+
+ describe('Testing sorting and loadMoreUsers functionality', () => {
+ it('should set the correct order variable and update hasMore', async () => {
+ render(
+
+
+
+
+
+
+ ,
+ );
+
+ const sortDropdown = await screen.findByTestId('sortUsers');
+ fireEvent.click(sortDropdown);
+
+ const newestOption = screen.getByTestId('newest');
+ fireEvent.click(newestOption);
+
+ expect(screen.getByTestId('sortUsers')).toHaveTextContent('newest');
+
+ const rowsNewest = await screen.findAllByRole('row');
+ expect(rowsNewest.length).toBeGreaterThan(0);
+
+ fireEvent.click(sortDropdown);
+ const oldestOption = screen.getByTestId('oldest');
+ fireEvent.click(oldestOption);
+
+ expect(screen.getByTestId('sortUsers')).toHaveTextContent('oldest');
+
+ const rowsOldest = await screen.findAllByRole('row');
+ expect(rowsOldest.length).toBeGreaterThan(0);
+ });
+
+ it('should load more users and merge them correctly', async () => {
+ render(
+
+
+
+
+
+
+ ,
+ );
+
+ await wait();
+ let rows = screen.getAllByRole('row');
+ expect(rows.length).toBe(4);
+
+ await act(async () => {
+ fireEvent.scroll(window, { target: { scrollY: 1000 } });
+ });
+
+ await wait();
+ rows = screen.getAllByRole('row');
+ expect(rows.length).toBe(4);
+ });
+ });
+
+ describe('generateMockUser', () => {
+ it('should set adminFor with an entry when isSuperAdmin is true', () => {
+ const mockUser = generateMockUser(
+ 'user1',
+ 'John',
+ 'Doe',
+ 'john@example.com',
+ '2023-04-13T04:53:17.742+00:00',
+ true, // isSuperAdmin
+ );
+
+ expect(mockUser.appUserProfile.adminFor).toEqual([{ _id: '123' }]);
+ expect(mockUser.appUserProfile.isSuperAdmin).toBe(true);
+ });
+
+ it('should set adminFor as an empty array when isSuperAdmin is false', () => {
+ const mockUser = generateMockUser(
+ 'user2',
+ 'Jane',
+ 'Doe',
+ 'jane@example.com',
+ '2023-04-17T04:53:17.742+00:00',
+ false, // isSuperAdmin
+ );
+
+ expect(mockUser.appUserProfile.adminFor).toEqual([]);
+ expect(mockUser.appUserProfile.isSuperAdmin).toBe(false);
+ });
+ });
});
diff --git a/src/screens/Users/Users.tsx b/src/screens/Users/Users.tsx
index ef9f001f4d..95c2116c4c 100644
--- a/src/screens/Users/Users.tsx
+++ b/src/screens/Users/Users.tsx
@@ -211,7 +211,6 @@ const Users = (): JSX.Element => {
const inputValue = inputElement?.value || '';
handleSearch(inputValue);
};
- /* istanbul ignore next */
const resetAndRefetch = (): void => {
refetchUsers({
first: perPageResult,
@@ -222,7 +221,6 @@ const Users = (): JSX.Element => {
});
setHasMore(true);
};
- /* istanbul ignore next */
const loadMoreUsers = (skipValue: number, limitVal: number): void => {
setIsLoadingMore(true);
fetchMore({
@@ -430,10 +428,7 @@ const Users = (): JSX.Element => {
/>
)}
{
loadMoreUsers(displayedUsers.length, perPageResult);
}}
@@ -474,7 +469,7 @@ const Users = (): JSX.Element => {
index={index}
resetAndRefetch={resetAndRefetch}
user={user}
- loggedInUserId={loggedInUserId ? loggedInUserId : ''}
+ loggedInUserId={loggedInUserId}
/>
);
},
diff --git a/src/screens/Users/UsersMocks.mocks.ts b/src/screens/Users/UsersMocks.mocks.ts
new file mode 100644
index 0000000000..54fae95442
--- /dev/null
+++ b/src/screens/Users/UsersMocks.mocks.ts
@@ -0,0 +1,244 @@
+import {
+ ORGANIZATION_CONNECTION_LIST,
+ USER_LIST,
+} from 'GraphQl/Queries/Queries';
+
+import { MOCK_USERS, MOCK_USERS2 } from './Organization.mocks';
+
+export const EMPTY_MOCKS = [
+ {
+ request: {
+ query: USER_LIST,
+ variables: {
+ first: 12,
+ skip: 0,
+ firstName_contains: '',
+ lastName_contains: '',
+ },
+ },
+ result: {
+ data: {
+ users: [],
+ },
+ },
+ },
+ {
+ request: {
+ query: ORGANIZATION_CONNECTION_LIST,
+ },
+ result: {
+ data: {
+ organizationsConnection: [],
+ },
+ },
+ },
+];
+
+export const MOCKS_NEW_2 = [
+ {
+ request: {
+ query: USER_LIST,
+ variables: {
+ first: 12,
+ skip: 0,
+ firstName_contains: '',
+ lastName_contains: '',
+ order: 'createdAt_DESC',
+ },
+ },
+ result: {
+ data: {
+ users: MOCK_USERS.slice(0, 12),
+ },
+ },
+ },
+ {
+ request: {
+ query: USER_LIST,
+ variables: {
+ first: 24,
+ skip: 0,
+ firstName_contains: '',
+ lastName_contains: '',
+ order: 'createdAt_DESC',
+ },
+ },
+ result: {
+ data: {
+ users: MOCK_USERS.slice(12, 24),
+ },
+ },
+ },
+ {
+ request: {
+ query: ORGANIZATION_CONNECTION_LIST,
+ },
+ result: {
+ data: {
+ organizationsConnection: [],
+ },
+ },
+ },
+];
+
+export const MOCKS_NEW = [
+ {
+ request: {
+ query: USER_LIST,
+ variables: {
+ first: 12,
+ skip: 0,
+ firstName_contains: '',
+ lastName_contains: '',
+ order: 'createdAt_DESC',
+ },
+ },
+ result: {
+ data: {
+ users: MOCK_USERS,
+ },
+ },
+ },
+ {
+ request: {
+ query: ORGANIZATION_CONNECTION_LIST,
+ },
+ result: {
+ data: {
+ organizationsConnection: [],
+ },
+ },
+ },
+];
+
+export 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),
+ },
+ },
+ },
+];
+
+export const MOCKS_NEW3 = [
+ {
+ 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(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: [],
+ },
+ },
+ },
+];