|
| 1 | +import { render } from '@testing-library/react'; |
| 2 | +import { describe, expect, it } from 'vitest'; |
| 3 | + |
| 4 | +import { AppearanceProvider } from '../AppearanceContext'; |
| 5 | +import { Flow } from '../Flow'; |
| 6 | + |
| 7 | +describe('Flow.Root data-component-status behavior', () => { |
| 8 | + it('does not set data-component-status if prop is omitted', () => { |
| 9 | + const { container } = render( |
| 10 | + <AppearanceProvider appearanceKey='signIn'> |
| 11 | + <Flow.Root flow='signIn'> |
| 12 | + <div data-testid='child' /> |
| 13 | + </Flow.Root> |
| 14 | + , |
| 15 | + </AppearanceProvider>, |
| 16 | + ); |
| 17 | + |
| 18 | + const host = container as HTMLElement | null; |
| 19 | + expect(host).toBeTruthy(); |
| 20 | + // Attribute should not be present |
| 21 | + expect(host?.getAttribute('data-component-status')).toBeNull(); |
| 22 | + }); |
| 23 | + |
| 24 | + it('sets data-component-status="awaiting-data" when isFlowReady=false', async () => { |
| 25 | + const { container } = render( |
| 26 | + <AppearanceProvider appearanceKey='signIn'> |
| 27 | + <Flow.Root |
| 28 | + flow='signIn' |
| 29 | + isFlowReady={false} |
| 30 | + > |
| 31 | + <div data-testid='child' /> |
| 32 | + </Flow.Root> |
| 33 | + , |
| 34 | + </AppearanceProvider>, |
| 35 | + ); |
| 36 | + |
| 37 | + const host = container as HTMLElement | null; |
| 38 | + expect(host).toBeTruthy(); |
| 39 | + expect(host?.getAttribute('data-component-status')).toBe('awaiting-data'); |
| 40 | + }); |
| 41 | + |
| 42 | + it('sets data-component-status="ready" when isFlowReady=true', () => { |
| 43 | + const { container } = render( |
| 44 | + <AppearanceProvider appearanceKey='signIn'> |
| 45 | + <Flow.Root |
| 46 | + flow='signIn' |
| 47 | + isFlowReady |
| 48 | + > |
| 49 | + <div data-testid='child' /> |
| 50 | + </Flow.Root> |
| 51 | + , |
| 52 | + </AppearanceProvider>, |
| 53 | + ); |
| 54 | + |
| 55 | + const host = container as HTMLElement | null; |
| 56 | + expect(host).toBeTruthy(); |
| 57 | + expect(host?.getAttribute('data-component-status')).toBe('ready'); |
| 58 | + }); |
| 59 | +}); |
0 commit comments