|
| 1 | +import { baseTheme } from '@vibrant-ui/theme'; |
| 2 | +import type { ReactRenderer } from '@vibrant-ui/utils/testing-web'; |
| 3 | +import { createReactRenderer } from '@vibrant-ui/utils/testing-web'; |
| 4 | +import { Skeleton } from './Skeleton'; |
| 5 | + |
| 6 | +describe('<Skeleton />', () => { |
| 7 | + const { render } = createReactRenderer(); |
| 8 | + let renderer: ReactRenderer; |
| 9 | + let element: HTMLElement; |
| 10 | + |
| 11 | + describe('when basic Skeleton is rendered', () => { |
| 12 | + beforeEach(async () => { |
| 13 | + renderer = render(<Skeleton data-testid="skeleton" width={100} height={50} rounded="md" />); |
| 14 | + |
| 15 | + element = await renderer.findByTestId('skeleton'); |
| 16 | + }); |
| 17 | + |
| 18 | + it('should have correct dimensions and styles', () => { |
| 19 | + expect(element).toHaveStyleRule('width', '100px'); |
| 20 | + expect(element).toHaveStyleRule('height', '50px'); |
| 21 | + expect(element).toHaveStyleRule('background-color', baseTheme.colors.light.overlay); |
| 22 | + }); |
| 23 | + |
| 24 | + it('match snapshot', () => { |
| 25 | + expect(renderer.container).toMatchSnapshot(); |
| 26 | + }); |
| 27 | + }); |
| 28 | + |
| 29 | + describe('when Skeleton.Text is rendered', () => { |
| 30 | + beforeEach(async () => { |
| 31 | + renderer = render(<Skeleton.Text data-testid="skeleton-text" lines={3} typography="body1" />); |
| 32 | + }); |
| 33 | + |
| 34 | + it('should render correct number of lines', async () => { |
| 35 | + const lines = await renderer.findAllByRole('generic'); |
| 36 | + // VStack + (3 lines * 2 components per line) |
| 37 | + |
| 38 | + expect(lines.length).toBeGreaterThan(3); |
| 39 | + }); |
| 40 | + |
| 41 | + it('match snapshot', () => { |
| 42 | + expect(renderer.container).toMatchSnapshot(); |
| 43 | + }); |
| 44 | + }); |
| 45 | + |
| 46 | + describe('when Skeleton.Avatar is rendered', () => { |
| 47 | + beforeEach(async () => { |
| 48 | + renderer = render(<Skeleton.Avatar data-testid="skeleton-avatar" size="md" />); |
| 49 | + }); |
| 50 | + |
| 51 | + it('match snapshot', () => { |
| 52 | + expect(renderer.container).toMatchSnapshot(); |
| 53 | + }); |
| 54 | + }); |
| 55 | + |
| 56 | + describe('when Skeleton.Button is rendered', () => { |
| 57 | + beforeEach(async () => { |
| 58 | + renderer = render(<Skeleton.Button data-testid="skeleton-button" size="md" />); |
| 59 | + }); |
| 60 | + |
| 61 | + it('match snapshot', () => { |
| 62 | + expect(renderer.container).toMatchSnapshot(); |
| 63 | + }); |
| 64 | + }); |
| 65 | + |
| 66 | + describe('when Skeleton.Image is rendered', () => { |
| 67 | + beforeEach(async () => { |
| 68 | + renderer = render(<Skeleton.Image data-testid="skeleton-image" width={200} ratio={1.5} />); |
| 69 | + }); |
| 70 | + |
| 71 | + it('match snapshot', () => { |
| 72 | + expect(renderer.container).toMatchSnapshot(); |
| 73 | + }); |
| 74 | + }); |
| 75 | +}); |
0 commit comments