From 4f636f4170ef1437b5caf7a29983fadb3a067dd1 Mon Sep 17 00:00:00 2001 From: MahtabBukhari Date: Tue, 22 Oct 2024 13:57:49 +0500 Subject: [PATCH] fix(stats): fixed eslint and unit tests --- src/components/Stats/__tests__/index.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/components/Stats/__tests__/index.tsx b/src/components/Stats/__tests__/index.tsx index 192c89836..270d928dd 100644 --- a/src/components/Stats/__tests__/index.tsx +++ b/src/components/Stats/__tests__/index.tsx @@ -1,6 +1,6 @@ /* eslint-disable padding-line-between-statements */ import '@testing-library/jest-dom' -import { fireEvent, render, screen, waitFor } from '@testing-library/react' +import { render, screen, waitFor } from '@testing-library/react' import React from 'react' import { ProcessingResponse, getTotalProcessing } from '~/network/fetchSourcesData' import { Stats } from '..' @@ -37,7 +37,7 @@ const mockedUseUserStore = useUserStore as jest.MockedFunction { totalProcessing: 0, } + // Now, simulate a response where totalProcessing is not present or is 0 mockedGetTotalProcessing.mockResolvedValueOnce(mockResponse) + // Re-render the component to reflect the new mock response render() + // The button should not be visible since totalProcessing is equal to 0 const viewContent = screen.queryByTestId('view-content') expect(viewContent).toBeNull() @@ -156,12 +159,15 @@ describe('Component Test Stats', () => { totalProcessing: 100, } + // Mocking a response where totalProcessing is present and greater than 0 mockedGetTotalProcessing.mockResolvedValueOnce(mockResponse2) render() + // Wait for the component to finish loading await screen.findByTestId('view-content') + // The button should be visible since totalProcessing is present and greater than 0 const button = screen.getByText('100') expect(button).toBeInTheDocument() })