WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

> **default**(): `Element`

Defined in: [src/screens/OrgList/OrgList.tsx:104](https://github.com/PalisadoesFoundation/talawa-admin/blob/main/src/screens/OrgList/OrgList.tsx#L104)
Defined in: [src/screens/OrgList/OrgList.tsx:107](https://github.com/PalisadoesFoundation/talawa-admin/blob/main/src/screens/OrgList/OrgList.tsx#L107)

## Returns

Expand Down
149 changes: 135 additions & 14 deletions src/screens/OrgList/OrgList.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ import { StaticMockLink } from 'utils/StaticMockLink';
import i18nForTest from 'utils/i18nForTest';
import OrgList from './OrgList';
import { MOCKS, MOCKS_ADMIN, MOCKS_EMPTY } from './OrgListMocks';
import { ORGANIZATION_LIST, CURRENT_USER } from 'GraphQl/Queries/Queries';
import {
ORGANIZATION_FILTER_LIST,
CURRENT_USER,
} from 'GraphQl/Queries/Queries';
import { GET_USER_NOTIFICATIONS } from 'GraphQl/Queries/NotificationQueries';
import useLocalStorage from 'utils/useLocalstorage';
import { vi } from 'vitest';
Expand Down Expand Up @@ -122,7 +125,7 @@ const renderWithMocks = (mocks: MockedResponse[]) => {
const createOrgMock = (organizations: unknown[]) => {
const orgListMock = {
request: {
query: ORGANIZATION_LIST,
query: ORGANIZATION_FILTER_LIST,
variables: { filter: '' },
},
result: {
Expand All @@ -134,7 +137,7 @@ const createOrgMock = (organizations: unknown[]) => {

// Filter out any ORGANIZATION_LIST mocks from MOCKS to avoid conflicts
const mocksWithoutOrgList = MOCKS.filter(
(mock) => mock.request.query !== ORGANIZATION_LIST,
(mock) => mock.request.query !== ORGANIZATION_FILTER_LIST,
);

return [orgListMock, ...mocksWithoutOrgList];
Expand Down Expand Up @@ -402,7 +405,7 @@ const mockConfigurations = {
...MOCKS,
{
request: {
query: ORGANIZATION_LIST,
query: ORGANIZATION_FILTER_LIST,
variables: { filter: '' },
},
result: {
Expand All @@ -413,7 +416,7 @@ const mockConfigurations = {
},
{
request: {
query: ORGANIZATION_LIST,
query: ORGANIZATION_FILTER_LIST,
variables: { filter: 'Dog' },
},
result: {
Expand Down Expand Up @@ -487,7 +490,7 @@ const mockConfigurations = {
},
{
request: {
query: ORGANIZATION_LIST,
query: ORGANIZATION_FILTER_LIST,
variables: { filter: '' },
},
result: {
Expand All @@ -501,7 +504,7 @@ const mockConfigurations = {
...MOCKS,
{
request: {
query: ORGANIZATION_LIST,
query: ORGANIZATION_FILTER_LIST,
variables: { filter: '' },
},
result: {
Expand Down Expand Up @@ -881,7 +884,7 @@ describe('Advanced Component Functionality Tests', () => {
...MOCKS,
{
request: {
query: ORGANIZATION_LIST,
query: ORGANIZATION_FILTER_LIST,
variables: { filter: '' },
},
result: {
Expand Down Expand Up @@ -1225,7 +1228,7 @@ describe('Advanced Component Functionality Tests', () => {
...MOCKS,
{
request: {
query: ORGANIZATION_LIST,
query: ORGANIZATION_FILTER_LIST,
variables: { filter: '' },
},
result: {
Expand Down Expand Up @@ -1319,7 +1322,7 @@ describe('Advanced Component Functionality Tests', () => {
...MOCKS,
{
request: {
query: ORGANIZATION_LIST,
query: ORGANIZATION_FILTER_LIST,
variables: { filter: '' },
},
result: {
Expand All @@ -1330,7 +1333,7 @@ describe('Advanced Component Functionality Tests', () => {
},
{
request: {
query: ORGANIZATION_LIST,
query: ORGANIZATION_FILTER_LIST,
variables: { filter: 'NonexistentOrg' },
},
result: {
Expand Down Expand Up @@ -1511,7 +1514,7 @@ describe('Advanced Component Functionality Tests', () => {
const errorMocks = [
{
request: {
query: ORGANIZATION_LIST,
query: ORGANIZATION_FILTER_LIST,
variables: {
id: '123',
filter: '',
Expand Down Expand Up @@ -1626,7 +1629,7 @@ describe('Advanced Component Functionality Tests', () => {
},
{
request: {
query: ORGANIZATION_LIST,
query: ORGANIZATION_FILTER_LIST,
variables: { filter: '' },
},
result: {
Expand Down Expand Up @@ -1727,7 +1730,7 @@ describe('Advanced Component Functionality Tests', () => {
},
{
request: {
query: ORGANIZATION_LIST,
query: ORGANIZATION_FILTER_LIST,
variables: { filter: '' },
},
result: {
Expand Down Expand Up @@ -2129,4 +2132,122 @@ describe('Advanced Component Functionality Tests', () => {
// If modal doesn't appear, test still passes
}
});

test('Testing organization creation when CREATE_ORGANIZATION_MUTATION returns null data', async () => {
setItem('id', '123');
setItem('role', 'administrator');

// Mock with null data response
const mockWithNullData = [
...MOCKS,
{
request: {
query: ORGANIZATION_FILTER_LIST,
variables: { filter: '' },
},
result: {
data: {
organizations: mockOrgData.singleOrg,
},
},
},
{
request: {
query: CREATE_ORGANIZATION_MUTATION_PG,
variables: {
name: 'Test Organization',
description: 'Test Description',
addressLine1: '123 Test St',
addressLine2: '',
city: 'Test City',
countryCode: 'af',
postalCode: '12345',
state: 'Test State',
avatar: null,
},
},
result: {
data: null,
},
},
{
request: {
query: CREATE_ORGANIZATION_MEMBERSHIP_MUTATION_PG,
variables: {
memberId: '123',
organizationId: undefined,
role: 'administrator',
},
},
result: {
data: {
createOrganizationMembership: {
id: 'membership-id',
},
},
},
},
];

render(
<MockedProvider mocks={mockWithNullData}>
<BrowserRouter>
<Provider store={store}>
<I18nextProvider i18n={i18nForTest}>
<ThemeProvider theme={createTheme()}>
<OrgList />
</ThemeProvider>
</I18nextProvider>
</Provider>
</BrowserRouter>
</MockedProvider>,
);

await wait();

// Open organization creation modal
await userEvent.click(screen.getByTestId('createOrganizationBtn'));

// Fill form
await userEvent.type(
screen.getByTestId('modalOrganizationName'),
'Test Organization',
);
await userEvent.type(
screen.getByTestId('modalOrganizationDescription'),
'Test Description',
);
await userEvent.type(
screen.getByTestId('modalOrganizationAddressLine1'),
'123 Test St',
);
await userEvent.type(
screen.getByTestId('modalOrganizationCity'),
'Test City',
);
await userEvent.type(
screen.getByTestId('modalOrganizationState'),
'Test State',
);
await userEvent.type(
screen.getByTestId('modalOrganizationPostalCode'),
'12345',
);
await userEvent.selectOptions(
screen.getByTestId('modalOrganizationCountryCode'),
'Afghanistan',
);

// Submit form
await userEvent.click(screen.getByTestId('submitOrganizationForm'));

// Wait for form submission to complete
await wait();

// Verify that toast.success was NOT called since data is null
expect(mockToast.success).not.toHaveBeenCalled();

// Verify that the modal should still be open since the success path wasn't taken
expect(screen.getByTestId('modalOrganizationHeader')).toBeInTheDocument();
});
});
7 changes: 5 additions & 2 deletions src/screens/OrgList/OrgList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ import {
CREATE_ORGANIZATION_MUTATION_PG,
CREATE_ORGANIZATION_MEMBERSHIP_MUTATION_PG,
} from 'GraphQl/Mutations/mutations';
import { ORGANIZATION_LIST, CURRENT_USER } from 'GraphQl/Queries/Queries';
import {
CURRENT_USER,
ORGANIZATION_FILTER_LIST,
} from 'GraphQl/Queries/Queries';

import PaginationList from 'components/Pagination/PaginationList/PaginationList';
import { useTranslation } from 'react-i18next';
Expand Down Expand Up @@ -176,7 +179,7 @@ function orgList(): JSX.Element {
data: allOrganizationsData,
loading: loadingAll,
refetch: refetchOrgs,
} = useQuery(ORGANIZATION_LIST, {
} = useQuery(ORGANIZATION_FILTER_LIST, {
variables: { filter: filterName },
fetchPolicy: 'network-only',
errorPolicy: 'all',
Expand Down
Loading