Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/2051/circular progress zero #2058

Merged
merged 8 commits into from
Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"publish:all:beta": "yarn publish:all --npm-tag=beta",
"start": "yarn docs",
"start:button": "yarn workspace @pluralsight/ps-design-system-button run storybook",
"start:circularprogress": "yarn workspace @pluralsight/ps-design-system-circularprogress run storybook",
Rykus0 marked this conversation as resolved.
Show resolved Hide resolved
"test": "jest",
"test:ci": "jest --ci"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ exports[`Storyshots Components/CircularProgress Animation 1`] = `
cy="24"
r={22}
strokeDasharray="138.23007675795088 138.23007675795088"
strokeDashoffset={103.67255756846316}
strokeDashoffset={138.23007675795088}
/>
</svg>
</div>
Expand Down Expand Up @@ -118,7 +118,7 @@ exports[`Storyshots Components/CircularProgress Values And Sizes 1`] = `
cy="24"
r={22}
strokeDasharray="138.23007675795088 138.23007675795088"
strokeDashoffset={103.67255756846316}
strokeDashoffset={138.23007675795088}
/>
</svg>
</div>
Expand Down Expand Up @@ -146,7 +146,7 @@ exports[`Storyshots Components/CircularProgress Values And Sizes 1`] = `
cy="24"
r={22}
strokeDasharray="138.23007675795088 138.23007675795088"
strokeDashoffset={103.67255756846316}
strokeDashoffset={138.23007675795088}
/>
</svg>
</div>
Expand Down
25 changes: 23 additions & 2 deletions packages/circularprogress/src/react/__specs__/index.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { convertStoriesToJestCases } from '@pluralsight/ps-design-system-util'
import { axe } from 'jest-axe'
import React from 'react'
import { render } from '@testing-library/react'
import { render, screen } from '@testing-library/react'

import CircularProgress from '../index'
import CircularProgress, { circumference } from '../index'
import * as stories from '../__stories__/index.story'

describe('CircularProgress', () => {
Expand Down Expand Up @@ -38,6 +38,27 @@ describe('CircularProgress', () => {
)
})

it('displays zero correctly', () => {
render(
<CircularProgress
value={0}
aria-label="0% complete"
data-testid="zero-test"
/>
)

// Get the SVG path to test
const el = screen
.getByTestId('zero-test')
.querySelector('.psds-circularprogress__fg')

// Get the attribute value to test
Rykus0 marked this conversation as resolved.
Show resolved Hide resolved
const dashoffset = el?.getAttribute('stroke-dashoffset') ?? ''

// Test the values after type conversion
expect(parseFloat(dashoffset)).toEqual(circumference)
})

describe.each(cases)('%s story', (_name, Story) => {
it('has no axe-core violations', async () => {
const { container } = render(<Story {...Story.args} />)
Expand Down
4 changes: 2 additions & 2 deletions packages/circularprogress/src/react/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import '../css/index.css'
import * as vars from '../vars/index'

const radius = vars.style.width / 2 - vars.style.strokeWidth / 2
const circumference = 2 * Math.PI * radius
export const circumference = 2 * Math.PI * radius

interface CircularProgressProps extends React.HTMLAttributes<HTMLDivElement> {
size?: ValueOf<typeof vars.sizes>
Expand Down Expand Up @@ -45,7 +45,7 @@ const CircularProgress = React.forwardRef<
const themeName = useTheme()

const dashOffset =
((100 - (value || defaultIndeterminateValue)) / 100) * circumference
((100 - (value ?? defaultIndeterminateValue)) / 100) * circumference
const busy = value
? value === 100
? 'false'
Expand Down