Skip to content

Commit

Permalink
update tests for empty state
Browse files Browse the repository at this point in the history
  • Loading branch information
thenamankumar committed Jan 28, 2025
1 parent fa93bf6 commit e49c6a6
Showing 1 changed file with 27 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ describe('HumanMessageEditor', () => {
initialEditorState: serializedPromptEditorStateFromText('abc'),
isSent: false,
}),
{ toolbarVisible: true, submitButtonEnabled: true, submitButtonText: /send/i }
{
toolbarVisible: true,
submitButtonEnabled: true,
submitButtonText: /send/i,
}
)
})

Expand All @@ -78,35 +82,29 @@ describe('HumanMessageEditor', () => {
initialEditorState: undefined,
isPendingPriorResponse: true,
}),
{ toolbarVisible: true, submitButtonEnabled: true, submitButtonText: /stop/i }
{
toolbarVisible: true,
submitButtonEnabled: true,
submitButtonText: /stop/i,
}
)
})
})

describe('submitting', () => {
function testNoSubmitting({
editor,
submitButton,
onSubmit,
}: ReturnType<typeof renderWithMocks>): void {
if (submitButton) {
expect(submitButton).toBeDisabled()
// Click
fireEvent.click(submitButton!)
expect(onSubmit).toHaveBeenCalledTimes(0)
}
test('empty editor', () => {
const { submitButton, editor, onSubmit } = renderWithMocks({
initialEditorState: FILE_MENTION_EDITOR_STATE_FIXTURE,
})
expect(submitButton).toBeEnabled()

// Click
fireEvent.click(submitButton!)
expect(onSubmit).toHaveBeenCalledTimes(1)

// Enter
fireEvent.keyDown(editor, ENTER_KEYBOARD_EVENT_DATA)
expect(onSubmit).toHaveBeenCalledTimes(0)
}

test('empty editor', () => {
testNoSubmitting(
renderWithMocks({
initialEditorState: undefined,
})
)
expect(onSubmit).toHaveBeenCalledTimes(2)
})

test('isPendingPriorResponse', () => {
Expand Down Expand Up @@ -146,7 +144,9 @@ describe('HumanMessageEditor', () => {
})
})

type EditorHTMLElement = HTMLDivElement & { dataset: { lexicalEditor: 'true' } }
type EditorHTMLElement = HTMLDivElement & {
dataset: { lexicalEditor: 'true' }
}

function renderWithMocks(props: Partial<ComponentProps<typeof HumanMessageEditor>>): {
container: HTMLElement
Expand Down Expand Up @@ -182,7 +182,10 @@ function renderWithMocks(props: Partial<ComponentProps<typeof HumanMessageEditor
return {
container,
editor: container.querySelector<EditorHTMLElement>('[data-lexical-editor="true"]')!,
addContextButton: screen.queryByRole('button', { name: 'Add context', hidden: true }),
addContextButton: screen.queryByRole('button', {
name: 'Add context',
hidden: true,
}),
submitButton: screen.queryByRole('button', {
name: /send|stop/i,
hidden: true,
Expand Down

0 comments on commit e49c6a6

Please sign in to comment.