Skip to content

Commit

Permalink
fixed OrgListCard tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JamarTG committed Nov 14, 2023
1 parent 6a0491e commit 3e9039c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 20 deletions.
62 changes: 44 additions & 18 deletions src/components/OrgListCard/OrgListCard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,24 @@ import type { InterfaceOrgListCardProps } from './OrgListCard';
import OrgListCard from './OrgListCard';
import userEvent from '@testing-library/user-event';
import { BrowserRouter } from 'react-router-dom';
import { IS_SAMPLE_ORGANIZATION_QUERY } from 'GraphQl/Queries/Queries';
import { StaticMockLink } from 'utils/StaticMockLink';
import { MockedProvider } from '@apollo/react-testing';

const MOCKS = [
{
request: {
query: IS_SAMPLE_ORGANIZATION_QUERY,
},
result: {
data: {
isSampleOrganization: true,
},
},
},
];

const link = new StaticMockLink(MOCKS, true);

const props: InterfaceOrgListCardProps = {
data: {
Expand Down Expand Up @@ -38,11 +56,13 @@ describe('Testing the Super Dash List', () => {
localStorage.setItem('id', '123'); // Means the user is an admin

render(
<BrowserRouter>
<I18nextProvider i18n={i18nForTest}>
<OrgListCard {...props} />
</I18nextProvider>
</BrowserRouter>
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
<I18nextProvider i18n={i18nForTest}>
<OrgListCard {...props} />
</I18nextProvider>
</BrowserRouter>
</MockedProvider>
);
expect(screen.getByAltText(/Dogs Care image/i)).toBeInTheDocument();
expect(screen.getByText('Admins:')).toBeInTheDocument();
Expand All @@ -56,11 +76,13 @@ describe('Testing the Super Dash List', () => {
window.location.assign('/orgdash');

render(
<BrowserRouter>
<I18nextProvider i18n={i18nForTest}>
<OrgListCard {...props} />
</I18nextProvider>
</BrowserRouter>
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
<I18nextProvider i18n={i18nForTest}>
<OrgListCard {...props} />
</I18nextProvider>
</BrowserRouter>
</MockedProvider>
);

expect(window.location).toBeAt('/orgdash');
Expand All @@ -72,20 +94,24 @@ describe('Testing the Super Dash List', () => {
...{ data: { ...props.data, ...{ image: null } } },
};
render(
<I18nextProvider i18n={i18nForTest}>
<OrgListCard {...imageNullProps} />
</I18nextProvider>
<MockedProvider addTypename={false} link={link}>
<I18nextProvider i18n={i18nForTest}>
<OrgListCard {...imageNullProps} />
</I18nextProvider>
</MockedProvider>
);
expect(screen.getByTestId(/emptyContainerForImage/i)).toBeInTheDocument();
});

test('Testing if user is redirected to orgDash screen', () => {
render(
<BrowserRouter>
<I18nextProvider i18n={i18nForTest}>
<OrgListCard {...props} />
</I18nextProvider>
</BrowserRouter>
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
<I18nextProvider i18n={i18nForTest}>
<OrgListCard {...props} />
</I18nextProvider>
</BrowserRouter>
</MockedProvider>
);
userEvent.click(screen.getByTestId('manageBtn'));
expect(window.location).toBeAt('/orgdash/id=xyz');
Expand Down
11 changes: 9 additions & 2 deletions src/screens/OrgList/OrgList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function orgList(): JSX.Element {
toast.success(t('successMessage'));
window.location.reload();
})
.catch((error: any) => {
.catch(() => {
toast.error(t('sampleOrgDuplicate'));
});
};
Expand Down Expand Up @@ -413,7 +413,7 @@ function orgList(): JSX.Element {
))}
</>
) : userData && userData.user.userType == 'SUPERADMIN' ? (
orgsData?.organizationsConnection.map((item, index) => {
orgsData?.organizationsConnection.map((item) => {
return (
<div key={item._id} className={styles.itemCard}>
<OrgListCard data={item} />
Expand Down Expand Up @@ -610,6 +610,13 @@ function orgList(): JSX.Element {
}}
></i>
</a>
<Button
variant="secondary"
onClick={(): void => toggleModal()}
data-testid="closeOrganizationModal"
>
{t('cancel')}
</Button>
</div>
<h4 className={styles.titlemodaldialog}>
{t('manageFeaturesInfo')}
Expand Down

0 comments on commit 3e9039c

Please sign in to comment.