Skip to content

Commit

Permalink
cleanups in test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
mdshamoon committed Jan 13, 2024
1 parent e4ca874 commit 0a27d69
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const AddToMessageTemplate = ({ id, message, changeDisplay }: AddToMessag
refetchQueries: [
{
query: FILTER_TEMPLATES,
variables: setVariables({ term: '' }),
variables: setVariables({ term: '' }, 50),
},
],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ vi.mock('react-tiny-link', () => {
};
});

// mock react player
vi.mock('react-player', () => {
return {
default: () => <video></video>,
};
});

HTMLAnchorElement.prototype.click = vi.fn();

const insertedAt = '2020-06-19T18:44:02Z';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ export const ChatMessage = ({
if (testForValidUrl.test(mediaUrl)) {
const link = document.createElement('a');
link.href = mediaUrl;
console.log(mediaUrl);
link.setAttribute('download', link.href);
document.body.appendChild(link);
link.click();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { render } from '@testing-library/react';
import { MockedProvider } from '@apollo/client/testing';
import { getByText, render, screen, waitFor } from '@testing-library/react';
import { MockedProvider, wait } from '@apollo/client/testing';
import { MemoryRouter } from 'react-router';
import { vi } from 'vitest';

Expand Down Expand Up @@ -35,9 +35,11 @@ const wrapper = (

describe('<CollectionContact />', () => {
test('should render CollectionContact', async () => {
const { getByTestId } = render(wrapper);

const { getByTestId, getByText } = render(wrapper);
// loading is show initially
expect(getByTestId('loading')).toBeInTheDocument();
await waitFor(() => {
expect(getByText('Collection')).toBeInTheDocument();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ export const ExportConsulting = ({ setFilters }: ExportConsultingPropTypes) => {
<div className={styles.FormContainer}>
<Form className={styles.Form}>
{formFields.map((field) => (
<div className={styles.Field}>
<Field {...field} key={field.name} />
<div className={styles.Field} key={field.name}>
<Field {...field} />
</div>
))}

Expand Down
2 changes: 1 addition & 1 deletion src/containers/Flow/Flow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const Flow = () => {
const [isPinnedDisable, setIsPinnedDisable] = useState(false);
const [keywords, setKeywords] = useState('');
const [description, setDescription] = useState('');
const [tagId, setTagId] = useState({ id: '', label: '' });
const [tagId, setTagId] = useState(null);
const [isActive, setIsActive] = useState(true);
const [isPinned, setIsPinned] = useState(false);
const [roles, setRoles] = useState<Array<any>>([]);
Expand Down
10 changes: 9 additions & 1 deletion src/containers/Flow/FlowList/FlowList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import { fireEvent, render, screen, waitFor } from '@testing-library/react';
import { MemoryRouter } from 'react-router-dom';
import { MockedProvider } from '@apollo/client/testing';
import { vi } from 'vitest';
import { loadErrorMessages, loadDevMessages } from '@apollo/client/dev';

// Adds messages only in a dev environment
loadDevMessages();
loadErrorMessages();

import {
getFlowCountQuery,
Expand Down Expand Up @@ -135,7 +140,10 @@ describe('<FlowList />', () => {
test('should export flow to json file', async () => {
global.URL.createObjectURL = vi.fn();
render(flowList);
await waitFor(async () => await new Promise((resolve) => setTimeout(resolve, 0)));

await waitFor(() => {
const moreButton = screen.getByTestId('MoreIcon');
});
const moreButton = screen.getByTestId('MoreIcon');
fireEvent.click(moreButton);

Expand Down
1 change: 0 additions & 1 deletion src/containers/List/List.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ describe('<List /> actions', () => {
fireEvent.click(moreButton);
await waitFor(() => {
const button = queryByTestId('DeleteIcon') as HTMLButtonElement;
console.log(button);
fireEvent.click(button);
});
await waitFor(() => {
Expand Down
10 changes: 6 additions & 4 deletions src/containers/List/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -587,10 +587,12 @@ export const List = ({
horizontal: 'right',
}}
>
<MenuItem className={styles.MenuItem}> {editButton}</MenuItem>
<Divider className={styles.Divider} />
<MenuItem className={styles.MenuItem}> {deleteButton(id, labelValue)}</MenuItem>
{actionListMap(item, actionsInsideMore, true)}
<div>
<MenuItem className={styles.MenuItem}> {editButton}</MenuItem>
<Divider className={styles.Divider} />
<MenuItem className={styles.MenuItem}> {deleteButton(id, labelValue)}</MenuItem>
{actionListMap(item, actionsInsideMore, true)}
</div>
</Menu>
)}
</div>
Expand Down
8 changes: 4 additions & 4 deletions src/containers/TemplateOptions/TemplateOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export const TemplateOptions = ({

if (templateType === CALL_TO_ACTION) {
template = (
<Fragment key={index.toString()}>
<Fragment>
<div className={styles.CallToActionWrapper}>
<div>
<div className={styles.RadioStyles}>
Expand Down Expand Up @@ -286,9 +286,9 @@ export const TemplateOptions = ({
name="templateButtons"
render={(arrayHelpers: any) => (
<div className={styles.QuickReplyContainer}>
{values.templateButtons.map((row: any, index: any) =>
getButtons(row, index, arrayHelpers)
)}
{values.templateButtons.map((row: any, index: any) => (
<div key={index}> {getButtons(row, index, arrayHelpers)}</div>
))}
</div>
)}
/>
Expand Down
1 change: 1 addition & 0 deletions src/graphql/queries/Contact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export const GET_CONTACT_DETAILS = gql`
export const GET_CONTACT_HISTORY = gql`
query ContactHistory($filter: ContactsHistoryFilter, $opts: Opts) {
contactHistory(filter: $filter, opts: $opts) {
id
eventDatetime
eventLabel
eventMeta
Expand Down
14 changes: 11 additions & 3 deletions src/mocks/Flow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const getFlowQuery = {
id: '1',
name: 'Help',
isActive: true,
description: 'Help flow',
uuid: 'b050c652-65b5-4ccf-b62b-1e8b3f328676',
keywords: ['help'],
isPinned: false,
Expand Down Expand Up @@ -101,6 +102,7 @@ const filterFlowResult = {
id: '1',
ignoreKeywords: true,
isActive: true,
description: 'Help flow',
keywords: ['help', 'मदद'],
lastChangedAt: '2021-03-05T04:32:23Z',
lastPublishedAt: null,
Expand Down Expand Up @@ -180,6 +182,7 @@ export const filterFlowWithNameOrKeywordOrTagQuery = {
ignoreKeywords: true,
isActive: true,
keywords: ['help', 'मदद'],
description: 'Help flow',
lastChangedAt: '2021-03-05T04:32:23Z',
lastPublishedAt: null,
name: 'Help Workflow',
Expand Down Expand Up @@ -371,8 +374,10 @@ export const importFlow = {
result: {
data: {
importFlow: {
errors: null,
success: true,
status: {
flowName: 'flow 1',
status: 'success',
},
},
},
},
Expand Down Expand Up @@ -450,6 +455,7 @@ export const updateFlowQuery = {
isActive: true,
isPinned: false,
isBackground: false,
description: 'Help flow',
name: 'New Flow',
keywords: ['मदद'],
ignoreKeywords: false,
Expand All @@ -468,6 +474,7 @@ export const updateFlowQuery = {
id: '1',
isActive: true,
ignoreKeywords: false,
description: 'Help flow',
keywords: ['मदद'],
name: 'New Flow',
isBackground: false,
Expand Down Expand Up @@ -506,6 +513,7 @@ export const copyFlowQuery = {
isActive: true,
isPinned: false,
isBackground: false,
description: 'Help flow',
name: 'Copy of Help',
keywords: ['help', 'activity'],
ignoreKeywords: false,
Expand All @@ -524,7 +532,7 @@ export const copyFlowQuery = {
id: '1',
isActive: true,
keywords: ['help', 'activity'],

description: 'Help flow',
name: 'Copy of Help',
isBackground: false,
updatedAt: '2021-03-05T04:32:23Z',
Expand Down

0 comments on commit 0a27d69

Please sign in to comment.