From 5cdcb5f82f60470417bea9fe721c3d9ffe0f264e Mon Sep 17 00:00:00 2001 From: yaswanth-deriv Date: Fri, 22 Mar 2024 09:42:58 +0400 Subject: [PATCH 1/2] test: added test cases for loader component --- .../Loader/__test__/Loader.spec.tsx | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/components/Loader/__test__/Loader.spec.tsx diff --git a/src/components/Loader/__test__/Loader.spec.tsx b/src/components/Loader/__test__/Loader.spec.tsx new file mode 100644 index 00000000..ba194733 --- /dev/null +++ b/src/components/Loader/__test__/Loader.spec.tsx @@ -0,0 +1,39 @@ +import React from 'react'; +import { render } from '@testing-library/react'; +import { Loader } from '..'; + +describe('Loader component', () => { + it('renders with default props', () => { + const { getByTestId } = render(); + const loader = getByTestId('dt_derivs-loader'); + console.log(loader,"loader") + expect(loader).toBeInTheDocument(); + expect(loader).toHaveClass('derivs-loader'); + expect(loader).toHaveClass('derivs-loader--fullscreen'); + const loaderElements = loader.querySelectorAll('.derivs-loader__element'); + loaderElements.forEach(element => { + expect(element).toHaveStyle({ backgroundColor: '#85ACB0' }); + }); + }); + + it('renders with custom color', () => { + const { getByTestId } = render(); + const loader = getByTestId('dt_derivs-loader'); + const loaderElements = loader.querySelectorAll('.derivs-loader__element'); + loaderElements.forEach(element => { + expect(element).toHaveStyle({ backgroundColor: '#FF0000' }); + }); + }); + + it('renders without full screen class when isFullScreen is false', () => { + const { getByTestId } = render(); + const loader = getByTestId('dt_derivs-loader'); + expect(loader).not.toHaveClass('derivs-loader--fullscreen'); + }); + + it('renders with custom className', () => { + const { getByTestId } = render(); + const loader = getByTestId('dt_derivs-loader'); + expect(loader).toHaveClass('custom-loader'); + }); +}); From 62d9d5ceaa71bf2819d82b59f709a7c66c643281 Mon Sep 17 00:00:00 2001 From: yaswanth-deriv Date: Fri, 22 Mar 2024 13:24:02 +0400 Subject: [PATCH 2/2] test: removed console statement --- src/components/Loader/__test__/Loader.spec.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/Loader/__test__/Loader.spec.tsx b/src/components/Loader/__test__/Loader.spec.tsx index ba194733..b7708490 100644 --- a/src/components/Loader/__test__/Loader.spec.tsx +++ b/src/components/Loader/__test__/Loader.spec.tsx @@ -6,7 +6,6 @@ describe('Loader component', () => { it('renders with default props', () => { const { getByTestId } = render(); const loader = getByTestId('dt_derivs-loader'); - console.log(loader,"loader") expect(loader).toBeInTheDocument(); expect(loader).toHaveClass('derivs-loader'); expect(loader).toHaveClass('derivs-loader--fullscreen');