|
| 1 | +/** |
| 2 | + * @vitest-environment jsdom |
| 3 | + */ |
| 4 | +import type { ReactElement } from 'react' |
| 5 | +import { renderToStaticMarkup } from 'react-dom/server' |
| 6 | +import { describe, expect, it } from 'vitest' |
| 7 | +import { |
| 8 | + AuthLoadingAlternateActions, |
| 9 | + AuthLoadingField, |
| 10 | + AuthLoadingFrame, |
| 11 | + AuthLoadingSkeleton, |
| 12 | +} from '@/app/(auth)/components/auth-loading-skeleton' |
| 13 | + |
| 14 | +function render(element: ReactElement): HTMLDivElement { |
| 15 | + const container = document.createElement('div') |
| 16 | + container.innerHTML = renderToStaticMarkup(element) |
| 17 | + return container |
| 18 | +} |
| 19 | + |
| 20 | +describe('auth loading skeletons', () => { |
| 21 | + it.each([ |
| 22 | + ['title', 'h-[38px]', 'rounded-[4px]'], |
| 23 | + ['label', 'h-[14px]', 'rounded-[4px]'], |
| 24 | + ['control', 'h-[44px]', 'rounded-[10px]'], |
| 25 | + ['divider', 'h-[1px]', 'rounded-[1px]'], |
| 26 | + ] as const)('retains the %s placeholder geometry', (shape, height, radius) => { |
| 27 | + const container = render(<AuthLoadingSkeleton shape={shape} className='w-[93px]' />) |
| 28 | + const skeleton = container.firstElementChild |
| 29 | + |
| 30 | + expect(skeleton?.classList.contains('animate-pulse')).toBe(true) |
| 31 | + expect(skeleton?.classList.contains('bg-[var(--surface-active)]')).toBe(true) |
| 32 | + expect(skeleton?.classList.contains(height)).toBe(true) |
| 33 | + expect(skeleton?.classList.contains(radius)).toBe(true) |
| 34 | + expect(skeleton?.classList.contains('w-[93px]')).toBe(true) |
| 35 | + }) |
| 36 | + |
| 37 | + it('keeps one label, three controls, and one divider in the shared field and actions', () => { |
| 38 | + const container = render( |
| 39 | + <AuthLoadingFrame> |
| 40 | + <AuthLoadingField labelWidthClassName='w-[86px]' /> |
| 41 | + <AuthLoadingAlternateActions /> |
| 42 | + </AuthLoadingFrame> |
| 43 | + ) |
| 44 | + const frame = container.firstElementChild |
| 45 | + const skeletons = Array.from(container.querySelectorAll('.animate-pulse')) |
| 46 | + |
| 47 | + expect(frame?.classList.contains('flex-col')).toBe(true) |
| 48 | + expect(skeletons).toHaveLength(5) |
| 49 | + expect(skeletons.filter((el) => el.classList.contains('h-[14px]'))).toHaveLength(1) |
| 50 | + expect(skeletons.filter((el) => el.classList.contains('h-[44px]'))).toHaveLength(3) |
| 51 | + expect(skeletons.filter((el) => el.classList.contains('h-[1px]'))).toHaveLength(1) |
| 52 | + expect(skeletons[0].classList.contains('w-[86px]')).toBe(true) |
| 53 | + }) |
| 54 | +}) |
0 commit comments