|
| 1 | +import '../setup'; |
| 2 | + |
| 3 | +import React from 'react'; |
| 4 | +import { expectAssignable } from 'tsd'; |
| 5 | + |
| 6 | +import { type FullComposerProps } from '../../src/FullComposer'; |
| 7 | +import { type ComposerProps } from 'botframework-webchat-component'; |
| 8 | +import { Components } from 'botframework-webchat-component'; |
| 9 | + |
| 10 | +type ComposerCoreChildrenRenderProp = ComposerProps['children']; |
| 11 | + |
| 12 | +// We want to assert that `children` on FullComposerProps accepts: |
| 13 | +// 1. React.ReactNode |
| 14 | +// 2. ComposerCoreChildrenRenderProp |
| 15 | +// 3. AddFullBundleChildren (({ extraStyleSet }: { extraStyleSet: any }) => React.ReactNode) |
| 16 | +// and is optional. |
| 17 | + |
| 18 | +// Helper asserting assignability. |
| 19 | +const expectProps = <T extends FullComposerProps>(props: T) => expectAssignable<FullComposerProps>(props); |
| 20 | + |
| 21 | +// Minimal required props: we must supply a `directLine` from ComposerProps. |
| 22 | +// Using a minimal mock for `directLine` which satisfies DirectLineJSBotConnection shape needed for types only. |
| 23 | +const mockDirectLine: any = { |
| 24 | + activity$: { subscribe: () => ({ unsubscribe: () => undefined }) }, |
| 25 | + connectionStatus$: { subscribe: () => ({ unsubscribe: () => undefined }) }, |
| 26 | + postActivity: () => ({ subscribe: () => ({ unsubscribe: () => undefined }) }) |
| 27 | +}; |
| 28 | + |
| 29 | +// 1. Without children (children optional) |
| 30 | +expectProps({ directLine: mockDirectLine }); |
| 31 | + |
| 32 | +// 2. With ReactNode child |
| 33 | +expectProps({ directLine: mockDirectLine, children: <div /> }); |
| 34 | + |
| 35 | +// 3. With ComposerCoreChildrenRenderProp child |
| 36 | +// The API context type is opaque here; we just confirm it is callable. |
| 37 | +const composerCoreChildren: ComposerCoreChildrenRenderProp = () => <div />; |
| 38 | +expectProps({ directLine: mockDirectLine, children: composerCoreChildren }); |
| 39 | + |
| 40 | +// 4. With AddFullBundleChildren child (takes { extraStyleSet }) |
| 41 | +const addFullBundleChildren = ({ extraStyleSet }: { extraStyleSet: any }) => <div>{String(!!extraStyleSet)}</div>; |
| 42 | +expectProps({ directLine: mockDirectLine, children: addFullBundleChildren }); |
| 43 | + |
| 44 | +// Also ensure baseline Composer (from Components) still type checks for overlapping accepted children. |
| 45 | +const { Composer } = Components; |
| 46 | +const _c1 = <Composer directLine={mockDirectLine} />; |
| 47 | +const _c2 = <Composer directLine={mockDirectLine}>{composerCoreChildren}</Composer>; |
| 48 | +const _c3 = ( |
| 49 | + <Composer directLine={mockDirectLine}> |
| 50 | + <div /> |
| 51 | + </Composer> |
| 52 | +); |
0 commit comments