From 8234779fb6ca4110f17f3cfb3b1ff35129f4f67b Mon Sep 17 00:00:00 2001 From: Akhilender Date: Mon, 6 Nov 2023 19:37:11 +0530 Subject: [PATCH 1/8] test: Achieve 100% Test Coverage and Fix Uncovered Lines - Improved the test coverage for the Loader component, addressing the previously uncovered lines and ensuring that all tests pass successfully. - Added a test to ensure that the component renders correctly with a custom 'sm' size. I verified that both the spinner-wrapper and spinner elements are present and that the correct class is applied. - Added a test to ensure that the component renders correctly with a 'lg' size. I verified that the spinner element has the appropriate class. - Added a test to ensure that the component renders correctly with an 'xl' size. I verified that the spinner element has the correct class. With these new tests, I now have 100% test coverage, and there are no more uncovered lines. The Loader component is thoroughly tested for different size scenarios, and all tests pass successfully. Signed-off-by: Akhilender --- src/components/Loader/Loader.test.tsx | 31 +++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/components/Loader/Loader.test.tsx b/src/components/Loader/Loader.test.tsx index c182c73f4f..a40774cb63 100644 --- a/src/components/Loader/Loader.test.tsx +++ b/src/components/Loader/Loader.test.tsx @@ -15,4 +15,35 @@ describe('Testing Loader component', () => { expect(screen.getByTestId('spinner-wrapper')).toBeInTheDocument(); expect(screen.getByTestId('spinner')).toBeInTheDocument(); }); + + test('Component should render on custom sizes', () => { + render( + + + + ); + + expect(screen.getByTestId('spinner-wrapper')).toBeInTheDocument(); + expect(screen.getByTestId('spinner')).toBeInTheDocument(); + expect(screen.getByTestId('spinner')).toHaveClass( + '_spinnerSm_1vy2z_21 spinner-border text-primary' + ); + }); + + test('Component should render with large size', () => { + render(); + const spinner = screen.getByTestId('spinner'); + expect(spinner).toHaveClass( + '_spinnerLg_1vy2z_15 spinner-border text-primary' + ); + }); + + test('renders with extra-large size', () => { + render(); + const spinner = screen.getByTestId('spinner'); + + expect(spinner).toHaveClass( + '_spinnerXl_1vy2z_9 spinner-border text-primary' + ); + }); }); From 24a0c083a697baa502d4a43f2ac01512780e61a0 Mon Sep 17 00:00:00 2001 From: Akhilender Date: Tue, 7 Nov 2023 15:43:02 +0530 Subject: [PATCH 2/8] Fixed linting in Loader component Signed-off-by: Akhilender --- src/components/Loader/Loader.test.tsx | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/components/Loader/Loader.test.tsx b/src/components/Loader/Loader.test.tsx index a40774cb63..50ca448b48 100644 --- a/src/components/Loader/Loader.test.tsx +++ b/src/components/Loader/Loader.test.tsx @@ -23,25 +23,39 @@ describe('Testing Loader component', () => { ); + const spinner = screen.getByTestId('spinner'); expect(screen.getByTestId('spinner-wrapper')).toBeInTheDocument(); - expect(screen.getByTestId('spinner')).toBeInTheDocument(); - expect(screen.getByTestId('spinner')).toHaveClass( + expect(spinner).toBeInTheDocument(); + expect(spinner).toHaveClass( '_spinnerSm_1vy2z_21 spinner-border text-primary' ); }); test('Component should render with large size', () => { - render(); + render( + + + + ); + const spinner = screen.getByTestId('spinner'); + expect(screen.getByTestId('spinner-wrapper')).toBeInTheDocument(); + expect(spinner).toBeInTheDocument(); expect(spinner).toHaveClass( '_spinnerLg_1vy2z_15 spinner-border text-primary' ); }); test('renders with extra-large size', () => { - render(); - const spinner = screen.getByTestId('spinner'); + render( + + + + ); + const spinner = screen.getByTestId('spinner'); + expect(screen.getByTestId('spinner-wrapper')).toBeInTheDocument(); + expect(spinner).toBeInTheDocument(); expect(spinner).toHaveClass( '_spinnerXl_1vy2z_9 spinner-border text-primary' ); From c90868d1383e433116dd38cbb2da03e3555f8fb1 Mon Sep 17 00:00:00 2001 From: Akhilender Date: Sat, 11 Nov 2023 18:28:34 +0530 Subject: [PATCH 3/8] Test: Increasing the test level - Trying to meet the code coverage level for Loader component. Signed-off-by: Akhilender --- src/components/Loader/Loader.test.tsx | 35 +++------------------------ 1 file changed, 3 insertions(+), 32 deletions(-) diff --git a/src/components/Loader/Loader.test.tsx b/src/components/Loader/Loader.test.tsx index 50ca448b48..923c2fc6b8 100644 --- a/src/components/Loader/Loader.test.tsx +++ b/src/components/Loader/Loader.test.tsx @@ -1,27 +1,17 @@ import React from 'react'; import { render, screen } from '@testing-library/react'; -import { BrowserRouter } from 'react-router-dom'; - import Loader from './Loader'; describe('Testing Loader component', () => { test('Component should be rendered properly', () => { - render( - - - - ); + render(); expect(screen.getByTestId('spinner-wrapper')).toBeInTheDocument(); expect(screen.getByTestId('spinner')).toBeInTheDocument(); }); test('Component should render on custom sizes', () => { - render( - - - - ); + render(); const spinner = screen.getByTestId('spinner'); expect(screen.getByTestId('spinner-wrapper')).toBeInTheDocument(); @@ -32,11 +22,7 @@ describe('Testing Loader component', () => { }); test('Component should render with large size', () => { - render( - - - - ); + render(); const spinner = screen.getByTestId('spinner'); expect(screen.getByTestId('spinner-wrapper')).toBeInTheDocument(); @@ -45,19 +31,4 @@ describe('Testing Loader component', () => { '_spinnerLg_1vy2z_15 spinner-border text-primary' ); }); - - test('renders with extra-large size', () => { - render( - - - - ); - - const spinner = screen.getByTestId('spinner'); - expect(screen.getByTestId('spinner-wrapper')).toBeInTheDocument(); - expect(spinner).toBeInTheDocument(); - expect(spinner).toHaveClass( - '_spinnerXl_1vy2z_9 spinner-border text-primary' - ); - }); }); From 7c4f03edbcf4182e4e159fbfa2f6a71b651acb31 Mon Sep 17 00:00:00 2001 From: Akhilender Date: Sat, 11 Nov 2023 18:42:42 +0530 Subject: [PATCH 4/8] Fixed Linting Signed-off-by: Akhilender From 93b7572a74072cfbc87bbe7052aaf45c77cc7626 Mon Sep 17 00:00:00 2001 From: Akhilender Date: Sat, 11 Nov 2023 19:05:40 +0530 Subject: [PATCH 5/8] fix: Linting Signed-off-by: Akhilender --- src/components/Loader/Loader.test.tsx | 30 +++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/components/Loader/Loader.test.tsx b/src/components/Loader/Loader.test.tsx index 923c2fc6b8..6d2930bedc 100644 --- a/src/components/Loader/Loader.test.tsx +++ b/src/components/Loader/Loader.test.tsx @@ -1,34 +1,34 @@ -import React from 'react'; -import { render, screen } from '@testing-library/react'; -import Loader from './Loader'; +import React from "react"; +import { render, screen } from "@testing-library/react"; +import Loader from "./Loader"; -describe('Testing Loader component', () => { - test('Component should be rendered properly', () => { +describe("Testing Loader component", () => { + test("Component should be rendered properly", () => { render(); - expect(screen.getByTestId('spinner-wrapper')).toBeInTheDocument(); - expect(screen.getByTestId('spinner')).toBeInTheDocument(); + expect(screen.getByTestId("spinner-wrapper")).toBeInTheDocument(); + expect(screen.getByTestId("spinner")).toBeInTheDocument(); }); - test('Component should render on custom sizes', () => { + test("Component should render on custom sizes", () => { render(); - const spinner = screen.getByTestId('spinner'); - expect(screen.getByTestId('spinner-wrapper')).toBeInTheDocument(); + const spinner = screen.getByTestId("spinner"); + expect(screen.getByTestId("spinner-wrapper")).toBeInTheDocument(); expect(spinner).toBeInTheDocument(); expect(spinner).toHaveClass( - '_spinnerSm_1vy2z_21 spinner-border text-primary' + "_spinnerSm_1vy2z_21 spinner-border text-primary" ); }); - test('Component should render with large size', () => { + test("Component should render with large size", () => { render(); - const spinner = screen.getByTestId('spinner'); - expect(screen.getByTestId('spinner-wrapper')).toBeInTheDocument(); + const spinner = screen.getByTestId("spinner"); + expect(screen.getByTestId("spinner-wrapper")).toBeInTheDocument(); expect(spinner).toBeInTheDocument(); expect(spinner).toHaveClass( - '_spinnerLg_1vy2z_15 spinner-border text-primary' + "_spinnerLg_1vy2z_15 spinner-border text-primary" ); }); }); From 9c7c6fbc2e05e3741d24255ccbb629caaa69d37a Mon Sep 17 00:00:00 2001 From: Akhilender Date: Sat, 11 Nov 2023 19:20:25 +0530 Subject: [PATCH 6/8] Improving test coverage for Loader Component - Fixed lint errors Signed-off-by: Akhilender --- src/components/Loader/Loader.test.tsx | 32 +++++++++++---------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/src/components/Loader/Loader.test.tsx b/src/components/Loader/Loader.test.tsx index 6d2930bedc..5664235c35 100644 --- a/src/components/Loader/Loader.test.tsx +++ b/src/components/Loader/Loader.test.tsx @@ -1,34 +1,28 @@ -import React from "react"; -import { render, screen } from "@testing-library/react"; -import Loader from "./Loader"; +import React from 'react'; +import { render, screen } from '@testing-library/react'; +import Loader from './Loader'; -describe("Testing Loader component", () => { - test("Component should be rendered properly", () => { +describe('Testing Loader component', () => { + test('Component should be rendered properly', () => { render(); - expect(screen.getByTestId("spinner-wrapper")).toBeInTheDocument(); - expect(screen.getByTestId("spinner")).toBeInTheDocument(); + expect(screen.getByTestId('spinner-wrapper')).toBeInTheDocument(); + expect(screen.getByTestId('spinner')).toBeInTheDocument(); }); - test("Component should render on custom sizes", () => { + test('Component should render on custom sizes', () => { render(); - const spinner = screen.getByTestId("spinner"); - expect(screen.getByTestId("spinner-wrapper")).toBeInTheDocument(); - expect(spinner).toBeInTheDocument(); - expect(spinner).toHaveClass( - "_spinnerSm_1vy2z_21 spinner-border text-primary" + expect(screen.getByTestId('spinner')).toHaveClass( + '_spinnerSm_1vy2z_21 spinner-border text-primary' ); }); - test("Component should render with large size", () => { + test('Component should render with large size', () => { render(); - const spinner = screen.getByTestId("spinner"); - expect(screen.getByTestId("spinner-wrapper")).toBeInTheDocument(); - expect(spinner).toBeInTheDocument(); - expect(spinner).toHaveClass( - "_spinnerLg_1vy2z_15 spinner-border text-primary" + expect(screen.getByTestId('spinner')).toHaveClass( + '_spinnerLg_1vy2z_15 spinner-border text-primary' ); }); }); From 69ebdd1618426d42a3c3fc1ac6f6bbca0dd6cfcb Mon Sep 17 00:00:00 2001 From: Akhilender Date: Sat, 11 Nov 2023 19:37:15 +0530 Subject: [PATCH 7/8] test: Improving the tests on the Loader Component - Added a new aspect in the test-case1 Signed-off-by: Akhilender --- src/components/Loader/Loader.test.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/Loader/Loader.test.tsx b/src/components/Loader/Loader.test.tsx index 5664235c35..36f07477eb 100644 --- a/src/components/Loader/Loader.test.tsx +++ b/src/components/Loader/Loader.test.tsx @@ -6,8 +6,10 @@ describe('Testing Loader component', () => { test('Component should be rendered properly', () => { render(); - expect(screen.getByTestId('spinner-wrapper')).toBeInTheDocument(); + const spinnerWrapper = screen.getByTestId('spinner-wrapper'); + expect(spinnerWrapper).toBeInTheDocument(); expect(screen.getByTestId('spinner')).toBeInTheDocument(); + expect(spinnerWrapper).toHaveClass('_spinner_wrapper_1vy2z_1'); }); test('Component should render on custom sizes', () => { From 09f89c89bf8cdfd2eae4e328e6f92c1552a6291b Mon Sep 17 00:00:00 2001 From: Akhilender Date: Tue, 14 Nov 2023 14:35:07 +0530 Subject: [PATCH 8/8] Fixed: Removed runtime-generated classes from testing - Eliminated all checks for classes associated with bootstrap components assigned at runtime. - Recognized that validating classes assigned during runtime is inappropriate. Signed-off-by: Akhilender --- src/components/Loader/Loader.test.tsx | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/components/Loader/Loader.test.tsx b/src/components/Loader/Loader.test.tsx index 36f07477eb..c512b480e3 100644 --- a/src/components/Loader/Loader.test.tsx +++ b/src/components/Loader/Loader.test.tsx @@ -6,25 +6,21 @@ describe('Testing Loader component', () => { test('Component should be rendered properly', () => { render(); - const spinnerWrapper = screen.getByTestId('spinner-wrapper'); - expect(spinnerWrapper).toBeInTheDocument(); + expect(screen.getByTestId('spinner-wrapper')).toBeInTheDocument(); expect(screen.getByTestId('spinner')).toBeInTheDocument(); - expect(spinnerWrapper).toHaveClass('_spinner_wrapper_1vy2z_1'); }); test('Component should render on custom sizes', () => { render(); - expect(screen.getByTestId('spinner')).toHaveClass( - '_spinnerSm_1vy2z_21 spinner-border text-primary' - ); + expect(screen.getByTestId('spinner-wrapper')).toBeInTheDocument(); + expect(screen.getByTestId('spinner')).toBeInTheDocument(); }); test('Component should render with large size', () => { render(); - expect(screen.getByTestId('spinner')).toHaveClass( - '_spinnerLg_1vy2z_15 spinner-border text-primary' - ); + expect(screen.getByTestId('spinner-wrapper')).toBeInTheDocument(); + expect(screen.getByTestId('spinner')).toBeInTheDocument(); }); });