-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #464 from sima-land/453-skeleton
Шаг 4 #453 Добавить компонент Skeleton
- Loading branch information
Showing
4 changed files
with
67 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { fireEvent, render } from '@testing-library/react'; | ||
import { Skeleton } from '../skeleton'; | ||
import { createRef } from 'react'; | ||
|
||
describe('Skeleton', () => { | ||
it('should handle div props', () => { | ||
const spy = jest.fn(); | ||
|
||
const { container } = render( | ||
<Skeleton id='primary' className='styled' onClick={spy}> | ||
Hello, world! | ||
</Skeleton>, | ||
); | ||
|
||
expect(container.querySelectorAll('#primary.styled')).toHaveLength(1); | ||
expect(container.querySelector('#primary.styled')?.textContent).toBe('Hello, world!'); | ||
|
||
expect(spy).toHaveBeenCalledTimes(0); | ||
fireEvent.click(container.querySelector('#primary.styled')!); | ||
expect(spy).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('should handle "rootRef"', () => { | ||
const ref = createRef<HTMLDivElement>(); | ||
|
||
render(<Skeleton rootRef={ref}>Hello, world!</Skeleton>); | ||
|
||
expect(ref.current instanceof HTMLElement).toBe(true); | ||
}); | ||
|
||
it('should handle "theme" prop', () => { | ||
const { container, rerender } = render(<Skeleton theme={undefined} />); | ||
|
||
expect(container.querySelectorAll('.theme-light')).toHaveLength(1); | ||
expect(container.querySelectorAll('.theme-dark')).toHaveLength(0); | ||
|
||
rerender(<Skeleton theme='light' />); | ||
|
||
expect(container.querySelectorAll('.theme-light')).toHaveLength(1); | ||
expect(container.querySelectorAll('.theme-dark')).toHaveLength(0); | ||
|
||
rerender(<Skeleton theme='dark' />); | ||
|
||
expect(container.querySelectorAll('.theme-light')).toHaveLength(0); | ||
expect(container.querySelectorAll('.theme-dark')).toHaveLength(1); | ||
|
||
rerender(<Skeleton theme='unset' />); | ||
|
||
expect(container.querySelectorAll('.theme-light')).toHaveLength(0); | ||
expect(container.querySelectorAll('.theme-dark')).toHaveLength(0); | ||
}); | ||
|
||
it('should handle "shining" prop', () => { | ||
const { container, rerender } = render(<Skeleton shining={undefined} />); | ||
expect(container.querySelectorAll('.shining')).toHaveLength(1); | ||
|
||
rerender(<Skeleton shining />); | ||
expect(container.querySelectorAll('.shining')).toHaveLength(1); | ||
|
||
rerender(<Skeleton shining={false} />); | ||
expect(container.querySelectorAll('.shining')).toHaveLength(0); | ||
}); | ||
}); |
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 +1,2 @@ | ||
export type { SkeletonStyle, SkeletonProps } from './types'; | ||
export { Skeleton } from './skeleton'; |
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