Skip to content

Commit

Permalink
Mocks Moved to OrganizationDashboardMocks -done
Browse files Browse the repository at this point in the history
  • Loading branch information
Sauradip07 committed Feb 7, 2024
1 parent 3338df2 commit cd308b0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
29 changes: 7 additions & 22 deletions src/screens/OrganizationDashboard/OrganizationDashboard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ import { BrowserRouter } from 'react-router-dom';
import { store } from 'state/store';
import { StaticMockLink } from 'utils/StaticMockLink';
import OrganizationDashboard from './OrganizationDashboard';
import { EMPTY_MOCKS, ERROR_MOCKS, MOCKS } from './OrganizationDashboardMocks';
import {
EMPTY_MOCKS,
ERROR_MOCKS,
MOCKS,
linkMocked,
mockEventData,
} from './OrganizationDashboardMocks';
import i18nForTest from 'utils/i18nForTest';
import { toast } from 'react-toastify';
import userEvent from '@testing-library/user-event';
import { ORGANIZATION_EVENT_CONNECTION_LIST } from 'GraphQl/Queries/Queries';

async function wait(ms = 100): Promise<void> {
await act(() => {
Expand Down Expand Up @@ -150,26 +155,6 @@ describe('Organisation Dashboard Page', () => {
});

test('Testing useEffect hook and error redirection', async () => {
const mockEventData = {
eventsByOrganizationConnection: [
{ startDate: new Date().toISOString() }, // Assuming an event is upcoming
],
};

// Mocking the response for the organization event query
const linkMocked = new StaticMockLink(
[
{
request: {
query: ORGANIZATION_EVENT_CONNECTION_LIST,
variables: { organization_id: 'your_organization_id' },
},
result: { data: mockEventData },
},
],
true
);

// Render the component with mock data
await act(async () => {
render(
Expand Down
21 changes: 21 additions & 0 deletions src/screens/OrganizationDashboard/OrganizationDashboardMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ORGANIZATION_POST_CONNECTION_LIST,
} from 'GraphQl/Queries/Queries';
import dayjs from 'dayjs';
import { StaticMockLink } from 'utils/StaticMockLink';

export const MOCKS = [
{
Expand Down Expand Up @@ -298,3 +299,23 @@ export const ERROR_MOCKS = [
error: new Error('Mock Graphql ORGANIZATION_EVENT_LIST Error'),
},
];

export const mockEventData = {
eventsByOrganizationConnection: [
{ startDate: new Date().toISOString() }, // Assuming an event is upcoming
],
};

// Mocking the response for the organization event query
export const linkMocked = new StaticMockLink(
[
{
request: {
query: ORGANIZATION_EVENT_CONNECTION_LIST,
variables: { organization_id: 'your_organization_id' },
},
result: { data: mockEventData },
},
],
true
);

0 comments on commit cd308b0

Please sign in to comment.