|
| 1 | +import { describe, it, expect, vi, afterEach } from 'vitest' |
| 2 | +import { renderHook } from '@testing-library/react' |
| 3 | +import { useAwsAuth } from '../useAwsAuth' |
| 4 | + |
| 5 | +/** |
| 6 | + * Which tab the block opens on is decided once, at mount, from the author's |
| 7 | + * `defaultTab` prop. Detection is switched off in these tests so no IPC runs — |
| 8 | + * the starting tab is the only behaviour under test. |
| 9 | + */ |
| 10 | + |
| 11 | +vi.mock('@/contexts/useRunbook', () => ({ |
| 12 | + useRunbookContext: () => ({ registerOutputs: vi.fn(), blockOutputs: {} }), |
| 13 | +})) |
| 14 | +vi.mock('@/contexts/useSession', () => ({ |
| 15 | + useSession: () => ({ isReady: true }), |
| 16 | +})) |
| 17 | + |
| 18 | +const originalApi = window.api |
| 19 | + |
| 20 | +afterEach(() => { |
| 21 | + window.api = originalApi |
| 22 | +}) |
| 23 | + |
| 24 | +const renderAwsAuth = (defaultTab?: string) => |
| 25 | + renderHook(() => |
| 26 | + useAwsAuth({ |
| 27 | + id: 'aws', |
| 28 | + ssoRegion: 'us-east-1', |
| 29 | + defaultRegion: 'us-east-1', |
| 30 | + detectCredentials: false, |
| 31 | + defaultTab, |
| 32 | + }), |
| 33 | + ) |
| 34 | + |
| 35 | +describe('useAwsAuth — defaultTab', () => { |
| 36 | + it('opens on Static Credentials when no defaultTab is set', () => { |
| 37 | + expect(renderAwsAuth().result.current.authMethod).toBe('credentials') |
| 38 | + }) |
| 39 | + |
| 40 | + it('opens on the tab the author asked for', () => { |
| 41 | + expect(renderAwsAuth('sso').result.current.authMethod).toBe('sso') |
| 42 | + expect(renderAwsAuth('profile').result.current.authMethod).toBe('profile') |
| 43 | + }) |
| 44 | + |
| 45 | + it('falls back to Static Credentials for an unrecognized tab name', () => { |
| 46 | + // MDX props are untyped, so a typo must not leave the block formless. |
| 47 | + expect(renderAwsAuth('sso-tab').result.current.authMethod).toBe('credentials') |
| 48 | + }) |
| 49 | +}) |
0 commit comments