Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better test coverage for src/screens/Requests/Requests.tsx #1163

Merged
merged 2 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
31 changes: 30 additions & 1 deletion src/screens/Requests/Requests.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@ import { store } from 'state/store';
import { StaticMockLink } from 'utils/StaticMockLink';
import i18nForTest from 'utils/i18nForTest';
import Requests from './Requests';
import { EMPTY_ORG_MOCKS, MOCKS, ORG_LIST_MOCK } from './RequestsMocks';
import {
EMPTY_ORG_MOCKS,
EMPTY_REQUEST_MOCKS,
MOCKS,
ORG_LIST_MOCK,
} from './RequestsMocks';

const link = new StaticMockLink(MOCKS, true);
const link2 = new StaticMockLink(EMPTY_ORG_MOCKS, true);
const link3 = new StaticMockLink(ORG_LIST_MOCK, true);
const link4 = new StaticMockLink(EMPTY_REQUEST_MOCKS, true);

async function wait(ms = 100): Promise<void> {
await act(() => {
Expand Down Expand Up @@ -91,6 +97,29 @@ describe('Testing Request screen', () => {
await wait();
});

test('Testing empty user requests', async () => {
render(
<MockedProvider addTypename={false} link={link4}>
<BrowserRouter>
<Provider store={store}>
<I18nextProvider i18n={i18nForTest}>
<Requests />
</I18nextProvider>
</Provider>
</BrowserRouter>
</MockedProvider>
);

const searchInput = screen.getByTestId('searchByName');
userEvent.type(searchInput, 'l');

const notFoundDiv = await screen.findByTestId('searchAndNotFound');

expect(notFoundDiv).toBeInTheDocument();

await wait();
});

test('Testing accept user functionality', async () => {
render(
<MockedProvider addTypename={false} link={link3}>
Expand Down
2 changes: 1 addition & 1 deletion src/screens/Requests/Requests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ const Requests = (): JSX.Element => {
{isLoading == false &&
usersData?.users.length === 0 &&
searchByName.length > 0 ? (
<div className={styles.notFound}>
<div className={styles.notFound} data-testid="searchAndNotFound">
<h4>
{t('noResultsFoundFor')} &quot;{searchByName}&quot;
</h4>
Expand Down
92 changes: 92 additions & 0 deletions src/screens/Requests/RequestsMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,98 @@ export const MOCKS = [
},
];

export const EMPTY_REQUEST_MOCKS = [
{
request: {
query: USER_ORGANIZATION_LIST,
variables: { id: localStorage.getItem('id') },
},
result: {
data: {
user: {
_id: '123',
userType: 'SUPERADMIN',
firstName: 'John',
lastName: 'Doe',
image: '',
email: '[email protected]',
adminFor: {
_id: 1,
name: 'Akatsuki',
image: '',
},
},
},
},
},
{
request: {
query: USER_LIST_REQUEST,
variables: {
adminApproved: false,
first: 12,
firstName_contains: '',
lastName_contains: '',
skip: 0,
userType: 'ADMIN',
},
notifyOnNetworkStatusChange: true,
},
result: {
data: {
users: [],
},
},
},
{
request: {
query: USER_LIST_REQUEST,
variables: {
adminApproved: false,
first: 12,
firstName_contains: 'l',
lastName_contains: '',
skip: 0,
userType: 'ADMIN',
},
notifyOnNetworkStatusChange: true,
},
result: {
data: {
users: [],
},
},
},
{
request: {
query: ACCEPT_ADMIN_MUTATION,
variables: {
id: '123',
userType: 'ADMIN',
},
},
result: {
data: {
acceptAdmin: true,
},
},
},
{
request: {
query: REJECT_ADMIN_MUTATION,
variables: {
id: '123',
userType: 'ADMIN',
},
},
result: {
data: {
rejectAdmin: true,
},
},
},
];

export const EMPTY_ORG_MOCKS = [
{
request: {
Expand Down
Loading