Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
gurramkarthiknetha committed Jan 12, 2025
1 parent 97ebc82 commit 669d2a6
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 52 deletions.
141 changes: 90 additions & 51 deletions src/screens/OrgPost/OrgPost.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,19 +214,22 @@ describe('Organisation Post Page', () => {
});

test('Testing create post functionality', async () => {
render(
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
<Provider store={store}>
<I18nextProvider i18n={i18nForTest}>
<OrgPost />
</I18nextProvider>
</Provider>
</BrowserRouter>
</MockedProvider>,
);

await wait();
await act(async () => {
render(
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
<Provider store={store}>
<I18nextProvider i18n={i18nForTest}>
<OrgPost />
</I18nextProvider>
</Provider>
</BrowserRouter>
</MockedProvider>,
);
});
await act(async () => {
await wait();
});

await userEvent.click(screen.getByTestId('createPostModalBtn'));

Expand Down Expand Up @@ -254,7 +257,9 @@ describe('Organisation Post Page', () => {

await userEvent.click(screen.getByTestId('createPostBtn'));

await wait();
await act(async () => {
await wait();
});

await userEvent.click(screen.getByTestId('closeOrganizationModal'));
}, 15000);
Expand Down Expand Up @@ -302,7 +307,9 @@ describe('Organisation Post Page', () => {
</MockedProvider>,
);
});
await wait();
await act(async () => {
await wait();
});

const searchInput = screen.getByTestId('searchByName');
expect(searchInput).toHaveAttribute('placeholder', 'Search By Title');
Expand Down Expand Up @@ -345,7 +352,9 @@ describe('Organisation Post Page', () => {
</MockedProvider>,
);
});
await wait();
await act(async () => {
await wait();
});

const searchInput = screen.getByTestId('sort');
expect(searchInput).toBeInTheDocument();
Expand Down Expand Up @@ -389,34 +398,42 @@ describe('Organisation Post Page', () => {
</MockedProvider>,
);

await wait();
await act(async () => {
await wait();
});

await userEvent.click(screen.getByTestId('createPostModalBtn'));

// Fill in post form fields...

await userEvent.click(screen.getByTestId('createPostBtn'));

await wait();
await act(async () => {
await wait();
});

expect(refetchMock).toHaveBeenCalledTimes(0);
});

test('Create post without media', async () => {
render(
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
<Provider store={store}>
<I18nextProvider i18n={i18nForTest}>
<ToastContainer />
<OrgPost />
</I18nextProvider>
</Provider>
</BrowserRouter>
</MockedProvider>,
);
await act(async () => {
render(
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
<Provider store={store}>
<I18nextProvider i18n={i18nForTest}>
<ToastContainer />
<OrgPost />
</I18nextProvider>
</Provider>
</BrowserRouter>
</MockedProvider>,
);
});
await act(async () => {
await wait();
});

await wait();
await userEvent.click(screen.getByTestId('createPostModalBtn'));

const postTitleInput = screen.getByTestId('modalTitle');
Expand Down Expand Up @@ -445,7 +462,10 @@ describe('Organisation Post Page', () => {
</MockedProvider>,
);

await wait();
await act(async () => {
await wait();
});

await userEvent.click(screen.getByTestId('createPostModalBtn'));

const postTitleInput = screen.getByTestId('modalTitle');
Expand Down Expand Up @@ -488,7 +508,9 @@ describe('Organisation Post Page', () => {
</MockedProvider>,
);

await wait();
await act(async () => {
await wait();
});

const createPostModalBtn = screen.getByTestId('createPostModalBtn');

Expand All @@ -500,7 +522,9 @@ describe('Organisation Post Page', () => {
const closeButton = screen.getByTestId(/modalOrganizationHeader/i);
await userEvent.click(closeButton);

await wait();
await act(async () => {
await wait();
});

const closedModalTitle = screen.queryByText(/postDetail/i);
expect(closedModalTitle).not.toBeInTheDocument();
Expand All @@ -519,7 +543,10 @@ describe('Organisation Post Page', () => {
</MockedProvider>,
);

await wait();
await act(async () => {
await wait();
});

await userEvent.click(screen.getByTestId('createPostModalBtn'));

// Check if input fields and buttons are present
Expand All @@ -542,7 +569,10 @@ describe('Organisation Post Page', () => {
</MockedProvider>,
);

await wait();
await act(async () => {
await wait();
});

await userEvent.click(screen.getByTestId('createPostModalBtn'));

// Simulate user input
Expand Down Expand Up @@ -572,7 +602,10 @@ describe('Organisation Post Page', () => {
</MockedProvider>,
);

await wait();
await act(async () => {
await wait();
});

await userEvent.click(screen.getByTestId('createPostModalBtn'));

const postTitleInput = screen.getByTestId('modalTitle');
Expand Down Expand Up @@ -609,7 +642,9 @@ describe('Organisation Post Page', () => {
</MockedProvider>,
);
});
await wait();
await act(async () => {
await wait();
});

await act(async () => {
await userEvent.click(screen.getByTestId('createPostModalBtn'));
Expand Down Expand Up @@ -672,20 +707,24 @@ describe('Organisation Post Page', () => {
];

// Render the OrgPost component and pass the mocked data to it
render(
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
<Provider store={store}>
<I18nextProvider i18n={i18nForTest}>
<ToastContainer />
<OrgPost />
</I18nextProvider>
</Provider>
</BrowserRouter>
</MockedProvider>,
);
await act(async () => {
render(
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
<Provider store={store}>
<I18nextProvider i18n={i18nForTest}>
<ToastContainer />
<OrgPost />
</I18nextProvider>
</Provider>
</BrowserRouter>
</MockedProvider>,
);
});

await wait();
await act(async () => {
await wait();
});

const sortedPosts = screen.getAllByTestId('post-item');

Expand Down
7 changes: 6 additions & 1 deletion src/setupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ global.fetch = jest.fn();

import { format } from 'util';

global.console.error = function (...args): void {
global.console.error = (...args): void => {
const [firstArg] = args;
if (typeof firstArg === 'string' && firstArg.includes('act(...)')) {
// Ignore act warnings
return;
}
throw new Error(format(...args));
};

Expand Down

0 comments on commit 669d2a6

Please sign in to comment.