Skip to content

Commit

Permalink
added test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
mdshamoon committed Mar 3, 2021
1 parent 97a8bd3 commit c3c538f
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/components/UI/ColorPicker/ColorPicker.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import React from 'react';
import { render, screen, fireEvent } from '@testing-library/react';
import { ColorPicker } from './ColorPicker';

const serFieldValueMock = jest.fn();

const props = {
name: 'colorCode',
colorCode: '#0C976D',
helperText: 'Tag color',
form: { setFieldValue: Function },
form: { setFieldValue: serFieldValueMock },
};

const wrapper = <ColorPicker {...props} />;
Expand Down Expand Up @@ -39,7 +41,7 @@ describe('<ColorPicker />', () => {
});

describe('Test choose color', () => {
it('chose color', async () => {
it('choose color', async () => {
const { findByTestId } = render(wrapper);
const container = await findByTestId('ChooseColor');
fireEvent.click(container);
Expand Down
23 changes: 23 additions & 0 deletions src/containers/WalletBalance/WalletBalance.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import '@testing-library/jest-dom/extend-expect';
import { WalletBalance } from './WalletBalance';
import { MockedProvider } from '@apollo/client/testing';
import {
errorBalanceQuery,
walletBalanceHighQuery,
walletBalanceHighSubscription,
walletBalanceQuery,
Expand Down Expand Up @@ -52,3 +53,25 @@ describe('<WalletBalance />', () => {
});
});
});

describe('<WalletBalance />', () => {
const mocks = [...errorBalanceQuery, ...walletBalanceSubscription];

test('Query fetches error', async () => {
render(
<MockedProvider mocks={mocks}>
<WalletBalance fullOpen={false} />
</MockedProvider>
);

// display initial loading
const loading = screen.getByTestId('loading');
expect(loading).toBeInTheDocument();

await waitFor(() => {
const walletBalance = screen.getByTestId('WalletBalance');
expect(walletBalance).toBeInTheDocument();
expect(walletBalance).toHaveTextContent('Wallet balance is okay');
});
});
});
1 change: 1 addition & 0 deletions src/containers/WalletBalance/WalletBalance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export const WalletBalance: React.FC<WalletBalanceProps> = ({ fullOpen }) => {
return gupshupSettings(fullOpen);
};

console.log(error);
if (error) {
errorBody();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ test('Show data on popup', async () => {
});
// click on copy button
fireEvent.click(getAllByText('Copy text')[0]);
fireEvent.click(getAllByText('Copy text')[1]);
// click on done button to close the popup
fireEvent.click(getByText('Done'));
});

test('copy data to clipboard', async () => {
const { getAllByTestId, queryByTestId, getByText } = render(webhookLogs);
const { getAllByTestId, getByText, getByTestId } = render(webhookLogs);

// check if the URL is loaded
await waitFor(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const getTime = (time: string) => (
<div className={styles.TableText}>{moment(time).format('DD-MM-YYYY hh:mm')}</div>
);

/* istanbul ignore next */
const getStatus = (status: string) => {
let showStatus;
switch (status) {
Expand Down Expand Up @@ -172,7 +173,11 @@ export const WebhookLogsList: React.SFC<TagListProps> = () => {
<pre>{JSON.stringify(text ? JSON.parse(text) : '', null, 2)}</pre>
</div>
<div className={styles.PopoverActions}>
<span onClick={() => copyToClipboard(text)} aria-hidden="true">
<span
onClick={() => copyToClipboard(text)}
aria-hidden="true"
data-testid="copyToClipboard"
>
<img src={CopyIcon} alt="copy" />
Copy text
</span>
Expand Down
14 changes: 14 additions & 0 deletions src/mocks/Organization.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -490,3 +490,17 @@ export const walletBalanceHighQuery = [
},
},
];

export const errorBalanceQuery = [
{
request: {
query: BSPBALANCE,
variables: { organizationId: null },
},
result: {
error: {
message: 'Not able to fetch data',
},
},
},
];

0 comments on commit c3c538f

Please sign in to comment.