-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! Feat(web-react): React version of Skeleton component #DS-1625
- Loading branch information
Řehořková Kateřina
committed
Jan 29, 2025
1 parent
ed0feea
commit 0199341
Showing
5 changed files
with
79 additions
and
136 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
'use client'; | ||
|
||
import React from 'react'; | ||
import { useStyleProps } from '../../hooks'; | ||
import { SpiritSkeletonItemProps } from '../../types'; | ||
import { useSkeletonItemStyleProps } from './useSkeletonItemStyleProps'; | ||
|
||
const SkeletonItem = (props: SpiritSkeletonItemProps): React.ReactElement => { | ||
const { skeletonItemStyleProps, classProps } = useSkeletonItemStyleProps(props); | ||
const { skeletonItemStyleProps, classProps, props: modifiedProps } = useSkeletonItemStyleProps(props); | ||
const { props: otherProps } = useStyleProps(modifiedProps); | ||
|
||
return <div className={classProps} aria-hidden="true" style={{ ...skeletonItemStyleProps }} />; | ||
return <div {...otherProps} className={classProps} aria-hidden="true" style={{ ...skeletonItemStyleProps }} />; | ||
}; | ||
|
||
export default SkeletonItem; |
59 changes: 21 additions & 38 deletions
59
packages/web-react/src/components/Skeleton/__tests__/SkeletonHeading.test.tsx
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 |
---|---|---|
@@ -1,68 +1,51 @@ | ||
import '@testing-library/jest-dom'; | ||
import { render } from '@testing-library/react'; | ||
import { screen, render } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests'; | ||
import SkeletonHeading from '../SkeletonHeading'; | ||
|
||
jest.mock('../../../hooks/useIcon'); | ||
|
||
describe('SkeletonHeading', () => { | ||
classNamePrefixProviderTest(SkeletonHeading, 'Skeleton'); | ||
|
||
stylePropsTest(SkeletonHeading); | ||
|
||
restPropsTest(SkeletonHeading, 'div'); | ||
|
||
it('should have default classname', () => { | ||
const { container } = render(<SkeletonHeading />); | ||
|
||
const element = container.querySelector('div'); | ||
expect(element).toHaveClass('Skeleton--heading'); | ||
beforeEach(() => { | ||
render(<SkeletonHeading data-testid="SkeletonHeading" />); | ||
}); | ||
|
||
it('should render default size class when size is not provided', () => { | ||
const { container } = render(<SkeletonHeading lines={2} />); | ||
|
||
const element = container.querySelector('div'); | ||
expect(element).toHaveClass('Skeleton--medium'); | ||
it('should have default classname', () => { | ||
expect(screen.getByTestId('SkeletonHeading')).toHaveClass('Skeleton--heading'); | ||
}); | ||
|
||
it('should render custom size class when size is provided', () => { | ||
const { container } = render(<SkeletonHeading lines={2} size="large" />); | ||
|
||
const element = container.querySelector('div'); | ||
expect(element).toHaveClass('Skeleton--large'); | ||
it('should render default size class when size is not provided', () => { | ||
expect(screen.getByTestId('SkeletonHeading')).toHaveClass('Skeleton--medium'); | ||
}); | ||
|
||
it('should render with aria-live attribute set to polite by default', () => { | ||
const { container } = render(<SkeletonHeading lines={2} />); | ||
|
||
const element = container.querySelector('div'); | ||
expect(element).toHaveAttribute('aria-live', 'polite'); | ||
expect(screen.getByTestId('SkeletonHeading')).toHaveAttribute('aria-live', 'polite'); | ||
}); | ||
|
||
it('should render with aria-busy attribute set to true by default', () => { | ||
const { container } = render(<SkeletonHeading lines={2} />); | ||
|
||
const element = container.querySelector('div'); | ||
expect(element).toHaveAttribute('aria-busy', 'true'); | ||
expect(screen.getByTestId('SkeletonHeading')).toHaveAttribute('aria-busy', 'true'); | ||
}); | ||
|
||
it('should render 1 text children by default', () => { | ||
const { container } = render(<SkeletonHeading />); | ||
|
||
const parentElement = container.querySelector('div'); | ||
const childDivElements = parentElement?.querySelectorAll('div'); | ||
|
||
expect(childDivElements?.length).toBe(1); | ||
it('should render 1 text child by default', () => { | ||
expect(screen.getByTestId('SkeletonHeading').children).toHaveLength(1); | ||
}); | ||
|
||
it('should render custom text children when lines is provided', () => { | ||
const { container } = render(<SkeletonHeading lines={3} />); | ||
describe('with custom props', () => { | ||
beforeEach(() => { | ||
render(<SkeletonHeading data-testid="SkeletonHeadingCustom" lines={3} size="large" />); | ||
}); | ||
|
||
const parentElement = container.querySelector('div'); | ||
const childDivElements = parentElement?.querySelectorAll('div'); | ||
it('should render custom size class when size is provided', () => { | ||
expect(screen.getByTestId('SkeletonHeadingCustom')).toHaveClass('Skeleton--large'); | ||
}); | ||
|
||
expect(childDivElements?.length).toBe(3); | ||
it('should render custom text children when lines is provided', () => { | ||
expect(screen.getByTestId('SkeletonHeadingCustom').children).toHaveLength(3); | ||
}); | ||
}); | ||
}); |
54 changes: 24 additions & 30 deletions
54
packages/web-react/src/components/Skeleton/__tests__/SkeletonItem.test.tsx
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
32 changes: 10 additions & 22 deletions
32
packages/web-react/src/components/Skeleton/__tests__/SkeletonShape.test.tsx
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 |
---|---|---|
@@ -1,45 +1,33 @@ | ||
import '@testing-library/jest-dom'; | ||
import { render } from '@testing-library/react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests'; | ||
import SkeletonShape from '../SkeletonShape'; | ||
|
||
jest.mock('../../../hooks/useIcon'); | ||
|
||
describe('SkeletonShape', () => { | ||
classNamePrefixProviderTest(SkeletonShape, 'Skeleton'); | ||
|
||
stylePropsTest(SkeletonShape); | ||
|
||
restPropsTest(SkeletonShape, 'div'); | ||
|
||
it('should have default classname', () => { | ||
const { container } = render(<SkeletonShape width={100} height={100} />); | ||
beforeEach(() => { | ||
render(<SkeletonShape width={100} height={100} data-testid="SkeletonShape" />); | ||
}); | ||
|
||
const element = container.querySelector('div'); | ||
expect(element).toHaveClass('Skeleton--shape'); | ||
it('should have default classname', () => { | ||
expect(screen.getByTestId('SkeletonShape')).toHaveClass('Skeleton--shape'); | ||
}); | ||
|
||
it('should render with aria-live attribute set to polite by default', () => { | ||
const { container } = render(<SkeletonShape width={100} height={100} />); | ||
|
||
const element = container.querySelector('div'); | ||
expect(element).toHaveAttribute('aria-live', 'polite'); | ||
expect(screen.getByTestId('SkeletonShape')).toHaveAttribute('aria-live', 'polite'); | ||
}); | ||
|
||
it('should render with aria-busy attribute set to true by default', () => { | ||
const { container } = render(<SkeletonShape width={100} height={100} />); | ||
|
||
const element = container.querySelector('div'); | ||
expect(element).toHaveAttribute('aria-busy', 'true'); | ||
expect(screen.getByTestId('SkeletonShape')).toHaveAttribute('aria-busy', 'true'); | ||
}); | ||
|
||
it('should render 1 text children by default', () => { | ||
const { container } = render(<SkeletonShape width={100} height={100} />); | ||
|
||
const parentElement = container.querySelector('div'); | ||
const childDivElements = parentElement?.querySelectorAll('div'); | ||
|
||
expect(childDivElements?.length).toBe(1); | ||
it('should render 1 text child by default', () => { | ||
expect(screen.getByTestId('SkeletonShape').children).toHaveLength(1); | ||
}); | ||
}); |
64 changes: 20 additions & 44 deletions
64
packages/web-react/src/components/Skeleton/__tests__/SkeletonText.test.tsx
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 |
---|---|---|
@@ -1,75 +1,51 @@ | ||
import '@testing-library/jest-dom'; | ||
import { render } from '@testing-library/react'; | ||
import { screen, render } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests'; | ||
import SkeletonText from '../SkeletonText'; | ||
|
||
jest.mock('../../../hooks/useIcon'); | ||
|
||
describe('SkeletonText', () => { | ||
classNamePrefixProviderTest(SkeletonText, 'Skeleton'); | ||
|
||
stylePropsTest(SkeletonText); | ||
|
||
restPropsTest(SkeletonText, 'div'); | ||
|
||
it('should have default classname', () => { | ||
const { container } = render(<SkeletonText />); | ||
|
||
const element = container.querySelector('div'); | ||
expect(element).toHaveClass('Skeleton--text'); | ||
beforeEach(() => { | ||
render(<SkeletonText data-testid="SkeletonText" />); | ||
}); | ||
|
||
it('should use default elementType when elementType is not provided', () => { | ||
const { container } = render(<SkeletonText />); | ||
|
||
const element = container.querySelector('div'); | ||
expect(element).toBeInTheDocument(); | ||
it('should have default classname', () => { | ||
expect(screen.getByTestId('SkeletonText')).toHaveClass('Skeleton--text'); | ||
}); | ||
|
||
it('should render default size class when size is not provided', () => { | ||
const { container } = render(<SkeletonText lines={2} />); | ||
|
||
const element = container.querySelector('div'); | ||
expect(element).toHaveClass('Skeleton--medium'); | ||
}); | ||
|
||
it('should render custom size class when size is provided', () => { | ||
const { container } = render(<SkeletonText lines={2} size="large" />); | ||
|
||
const element = container.querySelector('div'); | ||
expect(element).toHaveClass('Skeleton--large'); | ||
expect(screen.getByTestId('SkeletonText')).toHaveClass('Skeleton--medium'); | ||
}); | ||
|
||
it('should render with aria-live attribute set to polite by default', () => { | ||
const { container } = render(<SkeletonText lines={2} />); | ||
|
||
const element = container.querySelector('div'); | ||
expect(element).toHaveAttribute('aria-live', 'polite'); | ||
expect(screen.getByTestId('SkeletonText')).toHaveAttribute('aria-live', 'polite'); | ||
}); | ||
|
||
it('should render with aria-busy attribute set to true by default', () => { | ||
const { container } = render(<SkeletonText lines={2} />); | ||
|
||
const element = container.querySelector('div'); | ||
expect(element).toHaveAttribute('aria-busy', 'true'); | ||
expect(screen.getByTestId('SkeletonText')).toHaveAttribute('aria-busy', 'true'); | ||
}); | ||
|
||
it('should render 1 text children by default', () => { | ||
const { container } = render(<SkeletonText />); | ||
|
||
const parentElement = container.querySelector('div'); | ||
const childDivElements = parentElement?.querySelectorAll('div'); | ||
|
||
expect(childDivElements?.length).toBe(1); | ||
it('should render 1 text child by default', () => { | ||
expect(screen.getByTestId('SkeletonText').children).toHaveLength(1); | ||
}); | ||
|
||
it('should render custom text children when lines is provided', () => { | ||
const { container } = render(<SkeletonText lines={3} />); | ||
describe('with custom props', () => { | ||
beforeEach(() => { | ||
render(<SkeletonText data-testid="SkeletonTextCustom" lines={3} size="large" />); | ||
}); | ||
|
||
const parentElement = container.querySelector('div'); | ||
const childDivElements = parentElement?.querySelectorAll('div'); | ||
it('should render custom size class when size is provided', () => { | ||
expect(screen.getByTestId('SkeletonTextCustom')).toHaveClass('Skeleton--large'); | ||
}); | ||
|
||
expect(childDivElements?.length).toBe(3); | ||
it('should render custom text children when lines is provided', () => { | ||
expect(screen.getByTestId('SkeletonTextCustom').children).toHaveLength(3); | ||
}); | ||
}); | ||
}); |