1+ import React from 'react'
2+ import { CircularProgress } from '../../src'
3+ import { render , screen } from '@testing-library/react'
4+
5+ describe ( 'CircularProgress Loader' , ( ) => {
6+ it ( 'Should render without crashing' , ( ) => {
7+ render ( < CircularProgress wrapperClass = "test-class" wrapperStyle = { { opacity : '1' } } /> )
8+ const loader = screen . getByTestId ( 'circular-progress-loading' )
9+ expect ( loader ) . toBeInTheDocument ( )
10+ expect ( loader ) . toHaveStyle ( 'display: flex' )
11+ expect ( loader ) . toHaveAttribute ( 'aria-label' , 'circular-progress-loading' )
12+ expect ( loader ) . toHaveAttribute ( 'aria-busy' , 'true' )
13+ expect ( loader ) . toHaveAttribute ( 'role' , 'progressbar' )
14+ expect ( loader ) . toHaveClass ( 'test-class' )
15+ expect ( loader ) . toHaveStyle ( 'opacity:1' )
16+
17+ const svg = screen . getByTestId ( 'circular-progress-svg' )
18+ expect ( svg ) . toBeInTheDocument ( )
19+ expect ( svg ) . toHaveAttribute ( 'height' , '100' )
20+ expect ( svg ) . toHaveAttribute ( 'width' , '100' )
21+ expect ( svg ) . toHaveAttribute ( 'fill' , 'none' )
22+ } )
23+
24+ it ( 'Should apply props passed externally' , ( ) => {
25+ render (
26+ < CircularProgress
27+ wrapperClass = "test-class"
28+ wrapperStyle = { { opacity : '1' } }
29+ width = "200"
30+ height = "200"
31+ ariaLabel = "test-aria-label"
32+ color = "red"
33+ secondaryColor = "blue"
34+ strokeWidth = "4"
35+ animationDuration = "2"
36+ visible = { false }
37+ />
38+ )
39+ const loader = screen . getByTestId ( 'circular-progress-loading' )
40+ expect ( loader ) . toBeInTheDocument ( )
41+ expect ( loader ) . toHaveAttribute ( 'aria-label' , 'test-aria-label' )
42+ expect ( loader ) . toHaveClass ( 'test-class' )
43+ expect ( loader ) . toHaveStyle ( 'opacity:1' )
44+ expect ( loader ) . toHaveStyle ( 'display:none' )
45+
46+ const svg = screen . getByTestId ( 'circular-progress-svg' )
47+ expect ( svg ) . toBeInTheDocument ( )
48+ expect ( svg ) . toHaveAttribute ( 'height' , '200' )
49+ expect ( svg ) . toHaveAttribute ( 'width' , '200' )
50+ expect ( svg ) . toHaveStyle ( 'animation: spin 2s linear infinite' )
51+ } )
52+
53+ it ( 'Should use default color when secondaryColor is not provided' , ( ) => {
54+ render ( < CircularProgress color = "green" /> )
55+ const svg = screen . getByTestId ( 'circular-progress-svg' )
56+ const backgroundPath = svg . querySelector ( 'path[opacity="0.5"]' )
57+ expect ( backgroundPath ) . toHaveAttribute ( 'stroke' , 'green' )
58+ } )
59+
60+ it ( 'Should use secondaryColor when provided' , ( ) => {
61+ render ( < CircularProgress color = "green" secondaryColor = "red" /> )
62+ const svg = screen . getByTestId ( 'circular-progress-svg' )
63+ const backgroundPath = svg . querySelector ( 'path[opacity="0.5"]' )
64+ expect ( backgroundPath ) . toHaveAttribute ( 'stroke' , 'red' )
65+ } )
66+
67+ it ( 'Should apply custom strokeWidth' , ( ) => {
68+ render ( < CircularProgress strokeWidth = "3" /> )
69+ const svg = screen . getByTestId ( 'circular-progress-svg' )
70+ const backgroundPath = svg . querySelector ( 'path[opacity="0.5"]' )
71+ expect ( backgroundPath ) . toHaveAttribute ( 'stroke-width' , '3' )
72+ } )
73+ } )
0 commit comments