|
1 | 1 | import React from 'react'; |
2 | | -import { testComponentSnapshotsWithFixtures } from 'foremanReact/common/testHelpers'; |
| 2 | +import { render, screen } from '@testing-library/react'; |
| 3 | +import '@testing-library/jest-dom'; |
3 | 4 | import SkeletonLoader from '.'; |
4 | 5 | import { STATUS } from '../../../constants'; |
5 | | -const fixtures = { |
6 | | - 'should loading true': { |
7 | | - status: STATUS.PENDING, |
8 | | - skeletonProps: { count: 3 }, |
9 | | - }, |
10 | | - 'should loading finished with no children': { |
11 | | - status: STATUS.RESOLVED, |
12 | | - emptyState: 'custom empty', |
13 | | - }, |
14 | | - 'should loading true with a node child': { |
15 | | - status: STATUS.RESOLVED, |
16 | | - emptyState: 'custom empty', |
17 | | - children: <div>a child</div>, |
18 | | - }, |
19 | | - 'should render custom error': { |
20 | | - status: STATUS.ERROR, |
21 | | - errorNode: "custom error node" |
22 | | - }, |
23 | | -}; |
24 | | - |
25 | | -describe('SkeletonLoader', () => |
26 | | - testComponentSnapshotsWithFixtures(SkeletonLoader, fixtures)); |
| 6 | + |
| 7 | +describe('SkeletonLoader', () => { |
| 8 | + it('renders a skeleton while loading', () => { |
| 9 | + const { container } = render( |
| 10 | + <SkeletonLoader status={STATUS.PENDING} skeletonProps={{ count: 3 }} /> |
| 11 | + ); |
| 12 | + |
| 13 | + // react-loading-skeleton renders skeleton spans |
| 14 | + expect( |
| 15 | + container.querySelectorAll('.react-loading-skeleton') |
| 16 | + ).toHaveLength(3); |
| 17 | + }); |
| 18 | + |
| 19 | + it('renders the empty state when resolved with no children', () => { |
| 20 | + render( |
| 21 | + <SkeletonLoader status={STATUS.RESOLVED} emptyState="custom empty" /> |
| 22 | + ); |
| 23 | + |
| 24 | + expect(screen.getByText('custom empty')).toBeInTheDocument(); |
| 25 | + }); |
| 26 | + |
| 27 | + it('renders children when resolved', () => { |
| 28 | + render( |
| 29 | + <SkeletonLoader status={STATUS.RESOLVED} emptyState="custom empty"> |
| 30 | + <div>a child</div> |
| 31 | + </SkeletonLoader> |
| 32 | + ); |
| 33 | + |
| 34 | + expect(screen.getByText('a child')).toBeInTheDocument(); |
| 35 | + expect(screen.queryByText('custom empty')).not.toBeInTheDocument(); |
| 36 | + }); |
| 37 | + |
| 38 | + it('renders the custom error node on error', () => { |
| 39 | + render( |
| 40 | + <SkeletonLoader status={STATUS.ERROR} errorNode="custom error node" /> |
| 41 | + ); |
| 42 | + |
| 43 | + expect(screen.getByText('custom error node')).toBeInTheDocument(); |
| 44 | + }); |
| 45 | +}); |
0 commit comments