Skip to content

Commit

Permalink
fixed test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
mdshamoon committed Mar 14, 2024
1 parent 82d392f commit 2904d21
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 21 deletions.
9 changes: 6 additions & 3 deletions src/containers/Collection/Collection.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { getOrganizationLanguagesQuery, getOrganizationQuery } from 'mocks/Organ
import * as FormLayout from 'containers/Form/FormLayout';
import { Collection } from './Collection';
import { getRoleNamesMock } from 'containers/StaffManagement/StaffManagement.test.helper';
import { MemoryRouter } from 'react-router';

const mocks = [
getRoleNamesMock,
Expand All @@ -31,9 +32,11 @@ vi.mock('react-router-dom', async () => {
});

const wrapper = (
<MockedProvider mocks={mocks} addTypename={false}>
<Collection />
</MockedProvider>
<MemoryRouter>
<MockedProvider mocks={mocks} addTypename={false}>
<Collection />
</MockedProvider>
</MemoryRouter>
);

describe('<Collection />', () => {
Expand Down
9 changes: 6 additions & 3 deletions src/containers/ContactField/ContactField.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ import { MockedProvider } from '@apollo/client/testing';

import { setUserSession } from 'services/AuthService';
import { ContactField } from './ContactField';
import { MemoryRouter } from 'react-router';

setUserSession(JSON.stringify({ organization: { id: '1' }, roles: ['Admin'] }));

const wrapper = (
<MockedProvider mocks={[]} addTypename={false}>
<ContactField setOpenDialog={vi.fn()} />
</MockedProvider>
<MemoryRouter>
<MockedProvider mocks={[]} addTypename={false}>
<ContactField setOpenDialog={vi.fn()} />
</MockedProvider>
</MemoryRouter>
);

test('it renders contact form successfully', async () => {
Expand Down
17 changes: 11 additions & 6 deletions src/containers/Extensions/Extensions.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from 'mocks/Extension';
import { setUserSession } from 'services/AuthService';
import { Extensions } from './Extensions';
import { MemoryRouter } from 'react-router';

vi.mock('react-router-dom', async () => {
return {
Expand All @@ -26,9 +27,11 @@ const props = {
};

const wrapper = (
<MockedProvider mocks={createMocks} addTypename={false}>
<Extensions {...props} />
</MockedProvider>
<MemoryRouter>
<MockedProvider mocks={createMocks} addTypename={false}>
<Extensions {...props} />
</MockedProvider>
</MemoryRouter>
);
test('it should render form correctly', async () => {
render(wrapper);
Expand Down Expand Up @@ -65,9 +68,11 @@ test('it should render form correctly', async () => {

test('it should render filled form with extension details', async () => {
render(
<MockedProvider mocks={updateMocks} addTypename={false}>
<Extensions {...props} />
</MockedProvider>
<MemoryRouter>
<MockedProvider mocks={updateMocks} addTypename={false}>
<Extensions {...props} />
</MockedProvider>
</MemoryRouter>
);
await waitFor(() => {});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { MockedProvider } from '@apollo/client/testing';
import { setUserSession } from 'services/AuthService';
import { organizationCustomerMock } from 'mocks/Billing';
import { OrganizationCustomer } from './OrganizationCustomer';
import { MemoryRouter } from 'react-router';

const mocks = [...organizationCustomerMock];

Expand All @@ -17,9 +18,11 @@ setUserSession(JSON.stringify({ organization: { id: '1' }, roles: ['Glific_admin

test('it renders organization-customer component successfully without form data', async () => {
const app = (
<MockedProvider mocks={mocks} addTypename={false}>
<OrganizationCustomer openDialog />
</MockedProvider>
<MemoryRouter>
<MockedProvider mocks={mocks} addTypename={false}>
<OrganizationCustomer openDialog />
</MockedProvider>
</MemoryRouter>
);
render(app);
await waitFor(async () => await new Promise((resolve) => setTimeout(resolve, 0)));
Expand All @@ -42,9 +45,11 @@ test('it renders organization-customer component successfully without form data'

test('it renders organization-customer component successfully with form data', async () => {
render(
<MockedProvider mocks={mocks} addTypename={false}>
<OrganizationCustomer openDialog />
</MockedProvider>
<MemoryRouter>
<MockedProvider mocks={mocks} addTypename={false}>
<OrganizationCustomer openDialog />
</MockedProvider>
</MemoryRouter>
);
await waitFor(async () => await new Promise((resolve) => setTimeout(resolve, 0)));

Expand Down
9 changes: 6 additions & 3 deletions src/containers/Ticket/Ticket.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { getTicketQuery } from 'mocks/Ticket';
import { getUsersQuery } from 'mocks/User';
import { getRoleNamesMock } from 'containers/StaffManagement/StaffManagement.test.helper';
import { getOrganizationLanguagesQuery } from 'mocks/Organization';
import { MemoryRouter } from 'react-router';

afterEach(cleanup);

Expand All @@ -17,9 +18,11 @@ const mocks = [getTicketQuery, getUsersQuery, getRoleNamesMock, getOrganizationL
test('Render component correctly with the values', async () => {
const setOpenDialogMock = vi.fn();
render(
<MockedProvider mocks={mocks}>
<Ticket selectedTicket={'1'} setOpenDialog={setOpenDialogMock} />
</MockedProvider>
<MemoryRouter>
<MockedProvider mocks={mocks}>
<Ticket selectedTicket={'1'} setOpenDialog={setOpenDialogMock} />
</MockedProvider>
</MemoryRouter>
);

expect(screen.getByText('Loading...')).toBeInTheDocument();
Expand Down

0 comments on commit 2904d21

Please sign in to comment.