Skip to content

Commit

Permalink
updated test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
akanshaaa19 committed Oct 28, 2024
1 parent 3089248 commit 0b71bc6
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 8 deletions.
51 changes: 49 additions & 2 deletions src/containers/Flow/FlowList/FlowList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from 'mocks/Flow';
import { getOrganizationQuery } from 'mocks/Organization';
import testJSON from 'mocks/ImportFlow.json';
import { setUserSession } from 'services/AuthService';
import { setOrganizationServices, setUserSession } from 'services/AuthService';
import { FlowList } from './FlowList';
import { Flow } from '../Flow';
import { getFilterTagQuery } from 'mocks/Tag';
Expand Down Expand Up @@ -67,7 +67,8 @@ vi.mock('react-router-dom', async () => {
};
});

setUserSession(JSON.stringify({ roles: ['Admin'] }));
setUserSession(JSON.stringify({ roles: [{ id: '1', label: 'Admin' }] }));
setOrganizationServices('{"__typename":"OrganizationServicesResult","rolesAndPermission":true}');

describe('<FlowList />', () => {
test('should render Flow', async () => {
Expand Down Expand Up @@ -172,6 +173,26 @@ describe('<FlowList />', () => {
fireEvent.click(exportButton[0]);
});
});

test('should create from scratch ', async () => {
render(flowList);

await waitFor(() => {
expect(screen.getByText('Flows')).toBeInTheDocument();
});

fireEvent.click(screen.getByTestId('newItemButton'));

await waitFor(() => {
expect(screen.getByText('Create flow')).toBeInTheDocument();
});

fireEvent.click(screen.getByTestId('middle-button'));

await waitFor(() => {
expect(mockedUsedNavigate).toHaveBeenCalled();
});
});
});

describe('Template flows', () => {
Expand Down Expand Up @@ -225,4 +246,30 @@ describe('Template flows', () => {
expect(mockedUsedNavigate).toHaveBeenCalled();
});
});

test('click on Use it for templates', async () => {
render(flowList);

await waitFor(() => {
expect(screen.getByText('Flows')).toBeInTheDocument();
});

fireEvent.click(screen.getByTestId('newItemButton'));

await waitFor(() => {
expect(screen.getByText('Create flow')).toBeInTheDocument();
});

fireEvent.click(screen.getByTestId('ok-button'));

await waitFor(() => {
expect(screen.getByText('Template Flows')).toBeInTheDocument();
});

fireEvent.click(screen.getAllByTestId('copyTemplate')[0]);

await waitFor(() => {
expect(mockedUsedNavigate).toHaveBeenCalled();
});
});
});
2 changes: 1 addition & 1 deletion src/containers/Flow/FlowList/FlowList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export const FlowList = () => {
},
{
label: 'Use it',
icon: <DuplicateIcon />,
icon: <DuplicateIcon data-testid="copyTemplate" />,
parameter: 'id',
insideMore: false,
dialog: (id: any) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ const createUserMockData = new Array(5).fill(null).map((val, idx) => {
return {
id: `${index}`,
name: `NGO Main Account${index}`,
phone: `91987654321${index}`,
phone: `9198765432${index}`,
accessRoles: [{ label: roles[idx] }],
groups: [],
contact: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ const staffManagement = (
);

test('StaffManagementList is rendered correctly', async () => {
setUserSession(JSON.stringify({ organization: { id: '1' }, roles: ['Manager'] }));
setUserSession(
JSON.stringify({ organization: { id: '1' }, roles: [{ id: '1', label: 'Manager' }] })
);
render(staffManagement);

await waitFor(() => {
Expand Down
1 change: 1 addition & 0 deletions src/containers/Ticket/TicketList/TicketList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ test('should load the ticket list', async () => {
expect(getByTestId('loading')).toBeInTheDocument();
await waitFor(() => {
expect(getByText('Tickets')).toBeInTheDocument();
expect(getByText('field name')).toBeInTheDocument();
});
});

Expand Down
46 changes: 43 additions & 3 deletions src/mocks/Ticket.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const ticketListQuery = {
contact: {
id: '1',
name: 'NGO support',
fields: null,
fields: '{}',
maskedPhone: '9194*****449',
},
id: '1',
Expand All @@ -73,11 +73,11 @@ export const ticketListQuery = {
contact: {
id: '2',
name: null,
fields: null,
fields: '{"name":{"value":"field name"}}',
maskedPhone: '9194*****449',
},
id: '2',
messageNumber: 23,
messageNumber: null,
insertedAt: '2021-06-16T09:00:00.000Z',
remarks: 'This issue is resolved',
status: 'open',
Expand All @@ -88,6 +88,46 @@ export const ticketListQuery = {
name: 'Glific user',
},
},
{
body: '',
contact: {
id: '3',
name: null,
fields: '{}',
maskedPhone: '9194*****449',
},
id: '3',
messageNumber: 23,
insertedAt: '2021-06-16T09:00:00.000Z',
remarks: 'This issue is resolved',
status: 'open',
topic: 'General',
updatedAt: '2021-06-16T09:00:00.000Z',
user: {
id: '1',
name: null,
},
},
{
body: '',
contact: {
id: '3',
name: null,
fields: '{}',
maskedPhone: null,
},
id: '4',
messageNumber: 23,
insertedAt: '2021-06-16T09:00:00.000Z',
remarks: 'This issue is resolved',
status: 'open',
topic: 'General',
updatedAt: '2021-06-16T09:00:00.000Z',
user: {
id: '1',
name: null,
},
},
],
},
},
Expand Down

0 comments on commit 0b71bc6

Please sign in to comment.