-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added test for markdown in initialConversation
- Loading branch information
Showing
10 changed files
with
113 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
specs/specs/customRenderers/react/responseRenderer-initialConversation.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import {AiChat, BatchResponseComponentProps} from '@nlux-dev/react/src'; | ||
import {render} from '@testing-library/react'; | ||
import {FC} from 'react'; | ||
import {afterEach, beforeEach, describe, expect, it} from 'vitest'; | ||
import {adapterBuilder} from '../../../utils/adapterBuilder'; | ||
import {AdapterController} from '../../../utils/adapters'; | ||
import {waitForReactRenderCycle} from '../../../utils/wait'; | ||
|
||
describe('<AiChat /> + responseRenderer + initialConversation', () => { | ||
let adapterController: AdapterController | undefined = undefined; | ||
|
||
describe('When a response renderer is used with initial conversation', () => { | ||
beforeEach(() => { | ||
adapterController = adapterBuilder() | ||
.withBatchText(true) | ||
.withStreamText(false) | ||
.create(); | ||
}); | ||
|
||
afterEach(() => { | ||
adapterController = undefined; | ||
}); | ||
|
||
it('Should render the custom component for the initial conversation messages', async () => { | ||
// Arrange | ||
const CustomResponseComponent: FC<BatchResponseComponentProps<string>> = ({content}) => ( | ||
<div>The AI response is: {content}</div> | ||
); | ||
|
||
|
||
// Act | ||
const {container} = render( | ||
<AiChat | ||
adapter={adapterController!.adapter} | ||
initialConversation={[ | ||
{role: 'user', message: 'Hello'}, | ||
{role: 'assistant', message: 'Hi. How can I help you?'}, | ||
]} | ||
messageOptions={{ | ||
responseRenderer: CustomResponseComponent, | ||
}} | ||
/>, | ||
); | ||
await waitForReactRenderCycle(); | ||
|
||
// Assert | ||
const responseElement = container.querySelector('.nlux-comp-chatItem--received'); | ||
expect(responseElement!.innerHTML).toEqual( | ||
expect.stringContaining('<div>The AI response is: Hi. How can I help you?</div>'), | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters