-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(opentrons-ai-client): fix example buttons and clear text after su…
- Loading branch information
Showing
7 changed files
with
69 additions
and
43 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
20 changes: 19 additions & 1 deletion
20
opentrons-ai-client/src/molecules/InputPrompt/__tests__/InputPrompt.test.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
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
27 changes: 20 additions & 7 deletions
27
opentrons-ai-client/src/organisms/PromptButton/__tests__/PromptButton.test.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 |
---|---|---|
@@ -1,36 +1,49 @@ | ||
import React from 'react' | ||
import { useAtom } from 'jotai' | ||
import { fireEvent, screen, renderHook } from '@testing-library/react' | ||
import { describe, it, beforeEach, expect } from 'vitest' | ||
import { fireEvent, screen } from '@testing-library/react' | ||
import { describe, it, beforeEach, expect, vi } from 'vitest' | ||
|
||
import { renderWithProviders } from '../../../__testing-utils__' | ||
import { reagentTransfer } from '../../../assets/prompts' | ||
import { preparedPromptAtom } from '../../../resources/atoms' | ||
import { PromptButton } from '../index' | ||
|
||
import type * as ReactHookForm from 'react-hook-form' | ||
|
||
vi.mock('react-hook-form', async importOriginal => { | ||
const actual = await importOriginal<typeof ReactHookForm>() | ||
return { | ||
...actual, | ||
useFormContext: vi.fn(() => ({ | ||
setValue: mockSetValue, | ||
})), | ||
} | ||
}) | ||
|
||
const render = (props: React.ComponentProps<typeof PromptButton>) => { | ||
return renderWithProviders(<PromptButton {...props} />) | ||
} | ||
|
||
let mockSetValue = vi.fn() | ||
|
||
describe('PromptButton', () => { | ||
let props: React.ComponentProps<typeof PromptButton> | ||
|
||
beforeEach(() => { | ||
props = { | ||
buttonText: 'Reagent Transfer', | ||
} | ||
mockSetValue = vi.fn() | ||
}) | ||
|
||
it('should render text', () => { | ||
render(props) | ||
screen.getByRole('button', { name: 'Reagent Transfer' }) | ||
}) | ||
|
||
it('should call a mock function when clicking a button', () => { | ||
it('should render reagent transfer text into the form', () => { | ||
render(props) | ||
const button = screen.getByRole('button', { name: 'Reagent Transfer' }) | ||
fireEvent.click(button) | ||
const { result } = renderHook(() => useAtom(preparedPromptAtom)) | ||
expect(mockSetValue).toHaveBeenCalledWith('userPrompt', reagentTransfer) | ||
fireEvent.click(button) | ||
expect(result.current[0]).toBe(reagentTransfer) | ||
}) | ||
}) |
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