-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d52ca0b
commit 9c529a4
Showing
4 changed files
with
152 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import React from 'react' | ||
import { render, cleanup } from '@testing-library/react' | ||
import '@testing-library/jest-dom/extend-expect' | ||
|
||
import Spinner, { | ||
SpinnerProps, | ||
getSize, | ||
getThickness, | ||
getGap, | ||
getSpeed, | ||
} from './index' | ||
import { AdaptProvider } from '../' | ||
import 'jest-styled-components' | ||
|
||
afterEach(cleanup) | ||
|
||
describe('Spinner component', () => { | ||
const renderComponent = (customProps?: SpinnerProps) => | ||
render( | ||
<AdaptProvider> | ||
<Spinner {...customProps} /> | ||
</AdaptProvider> | ||
) | ||
|
||
const sizes: Measure[] = ['sm', 'md', 'lg', 'xl'] | ||
const speeds: Speed[] = ['fast', 'slow', 'normal'] | ||
|
||
it('should render without crashing', () => { | ||
const { container } = renderComponent() | ||
const firstChild = container.firstChild | ||
expect(firstChild).toBeInTheDocument() | ||
}) | ||
|
||
it('should render for all sizes', () => { | ||
for (let size of sizes) { | ||
const { container } = renderComponent({ size: size }) | ||
const firstChild = container.firstChild | ||
const sizeValue = `${getSize(size)}rem` | ||
expect(firstChild).toHaveAttribute('height', sizeValue) | ||
expect(firstChild).toHaveAttribute('width', sizeValue) | ||
} | ||
}) | ||
|
||
it('should render for all thicknesses', () => { | ||
for (let size of sizes) { | ||
const { container } = renderComponent({ thickness: size }) | ||
const circleElement = container.querySelector('circle') | ||
const thicknessValue = `${getThickness(size)}` | ||
expect(circleElement).toHaveAttribute('stroke-width', thicknessValue) | ||
const radiusValue = `${14 - getThickness(size) / 2}` | ||
expect(circleElement).toHaveAttribute('r', radiusValue) | ||
} | ||
}) | ||
|
||
it('should render for all gaps', () => { | ||
for (let size of sizes) { | ||
const { container } = renderComponent({ gap: size }) | ||
const circleElement = container.querySelector('circle') | ||
const gapValue = `${Math.PI * 2 * (11 - getGap(size))}` | ||
expect(circleElement).toHaveAttribute('stroke-dasharray', gapValue) | ||
} | ||
}) | ||
|
||
it('should render for all speeds', () => { | ||
for (let speed of speeds) { | ||
const { container } = renderComponent({ speed: speed }) | ||
const firstChild = container.firstChild | ||
expect(firstChild).toHaveStyle(`animation-duration: ${getSpeed(speed)}ms`) | ||
} | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters