From c3c538f89622e98bf4fba0b23fcf52f477dfc672 Mon Sep 17 00:00:00 2001 From: mdshamoon Date: Wed, 3 Mar 2021 15:24:42 +0530 Subject: [PATCH] added test cases --- .../UI/ColorPicker/ColorPicker.test.tsx | 6 +++-- .../WalletBalance/WalletBalance.test.tsx | 23 +++++++++++++++++++ .../WalletBalance/WalletBalance.tsx | 1 + .../WebhookLogsList/WebhookLogsList.test.tsx | 3 ++- .../WebhookLogsList/WebhookLogsList.tsx | 7 +++++- src/mocks/Organization.tsx | 14 +++++++++++ 6 files changed, 50 insertions(+), 4 deletions(-) diff --git a/src/components/UI/ColorPicker/ColorPicker.test.tsx b/src/components/UI/ColorPicker/ColorPicker.test.tsx index b291417be..3540e88a0 100644 --- a/src/components/UI/ColorPicker/ColorPicker.test.tsx +++ b/src/components/UI/ColorPicker/ColorPicker.test.tsx @@ -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 = ; @@ -39,7 +41,7 @@ describe('', () => { }); describe('Test choose color', () => { - it('chose color', async () => { + it('choose color', async () => { const { findByTestId } = render(wrapper); const container = await findByTestId('ChooseColor'); fireEvent.click(container); diff --git a/src/containers/WalletBalance/WalletBalance.test.tsx b/src/containers/WalletBalance/WalletBalance.test.tsx index 0e26738e3..9c9a1ba66 100644 --- a/src/containers/WalletBalance/WalletBalance.test.tsx +++ b/src/containers/WalletBalance/WalletBalance.test.tsx @@ -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, @@ -52,3 +53,25 @@ describe('', () => { }); }); }); + +describe('', () => { + const mocks = [...errorBalanceQuery, ...walletBalanceSubscription]; + + test('Query fetches error', async () => { + render( + + + + ); + + // 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'); + }); + }); +}); diff --git a/src/containers/WalletBalance/WalletBalance.tsx b/src/containers/WalletBalance/WalletBalance.tsx index 5fdcf93ff..d032b8512 100644 --- a/src/containers/WalletBalance/WalletBalance.tsx +++ b/src/containers/WalletBalance/WalletBalance.tsx @@ -118,6 +118,7 @@ export const WalletBalance: React.FC = ({ fullOpen }) => { return gupshupSettings(fullOpen); }; + console.log(error); if (error) { errorBody(); } diff --git a/src/containers/WebhookLogs/WebhookLogsList/WebhookLogsList.test.tsx b/src/containers/WebhookLogs/WebhookLogsList/WebhookLogsList.test.tsx index ee13d4a05..1a2871b5d 100644 --- a/src/containers/WebhookLogs/WebhookLogsList/WebhookLogsList.test.tsx +++ b/src/containers/WebhookLogs/WebhookLogsList/WebhookLogsList.test.tsx @@ -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(() => { diff --git a/src/containers/WebhookLogs/WebhookLogsList/WebhookLogsList.tsx b/src/containers/WebhookLogs/WebhookLogsList/WebhookLogsList.tsx index a7f624b8f..f83c4f0ca 100644 --- a/src/containers/WebhookLogs/WebhookLogsList/WebhookLogsList.tsx +++ b/src/containers/WebhookLogs/WebhookLogsList/WebhookLogsList.tsx @@ -19,6 +19,7 @@ const getTime = (time: string) => (
{moment(time).format('DD-MM-YYYY hh:mm')}
); +/* istanbul ignore next */ const getStatus = (status: string) => { let showStatus; switch (status) { @@ -172,7 +173,11 @@ export const WebhookLogsList: React.SFC = () => {
{JSON.stringify(text ? JSON.parse(text) : '', null, 2)}
- copyToClipboard(text)} aria-hidden="true"> + copyToClipboard(text)} + aria-hidden="true" + data-testid="copyToClipboard" + > copy Copy text diff --git a/src/mocks/Organization.tsx b/src/mocks/Organization.tsx index d11a17aab..195a95e40 100644 --- a/src/mocks/Organization.tsx +++ b/src/mocks/Organization.tsx @@ -490,3 +490,17 @@ export const walletBalanceHighQuery = [ }, }, ]; + +export const errorBalanceQuery = [ + { + request: { + query: BSPBALANCE, + variables: { organizationId: null }, + }, + result: { + error: { + message: 'Not able to fetch data', + }, + }, + }, +];