Skip to content

Commit

Permalink
update protocol fixes for test
Browse files Browse the repository at this point in the history
  • Loading branch information
connected-znaim committed Oct 28, 2024
1 parent a512b8a commit 66632df
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
2 changes: 2 additions & 0 deletions opentrons-ai-client/src/molecules/ChatDisplay/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
SPACING,
LegacyStyledText,
TYPOGRAPHY,
OVERFLOW_AUTO,
} from '@opentrons/components'

import type { ChatData } from '../../resources/types'
Expand Down Expand Up @@ -63,6 +64,7 @@ export function ChatDisplay({ chat, chatId }: ChatDisplayProps): JSX.Element {
data-testid={`ChatDisplay_from_${isUser ? 'user' : 'backend'}`}
borderRadius={BORDERS.borderRadius12}
width="100%"
overflowY={OVERFLOW_AUTO}
flexDirection={DIRECTION_COLUMN}
gridGap={SPACING.spacing16}
position={POSITION_RELATIVE}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import type { NavigateFunction } from 'react-router-dom'
import { UpdateProtocol } from '../index'
import { i18n } from '../../../i18n'

// global.Blob = BlobPolyfill as any
global.Blob = require('node:buffer').Blob

const mockNavigate = vi.fn()
const mockUseTrackEvent = vi.fn()
const mockUseChatData = vi.fn()
Expand All @@ -14,6 +17,8 @@ vi.mock('../../../resources/hooks/useTrackEvent', () => ({
useTrackEvent: () => mockUseTrackEvent,
}))

File.prototype.text = vi.fn().mockResolvedValue('test file content')

vi.mock('../../../resources/chatDataAtom', () => ({
chatDataAtom: () => mockUseChatData,
}))
Expand Down Expand Up @@ -50,7 +55,7 @@ describe('Update Protocol', () => {
).toBeInTheDocument()
})

it.skip('should update the file value when the file is uploaded', async () => {
it('should update the file value when the file is uploaded', async () => {
render()

const blobParts: BlobPart[] = [
Expand All @@ -74,15 +79,47 @@ describe('Update Protocol', () => {
})
})

it.skip('should have the submit prompt button disabled when the progress percentage is not 1.0', () => {
it('should not proceed when you click the submit prompt when the progress percentage is not 1.0', () => {
render()
expect(screen.getByText('Submit prompt')).toBeDisabled()
expect(mockNavigate).not.toHaveBeenCalled()
})

it.skip('should call navigate to the chat page when the submit prompt button is clicked', () => {
it.skip('should call navigate to the chat page when the submit prompt button is clicked when progress is 1.0', async () => {
render()

// upload file
const blobParts: BlobPart[] = [
'x = 1\n',
'x = 2\n',
'x = 3\n',
'x = 4\n',
'print("x is 1.")\n',
]
const file = new File(blobParts, 'test-file.py', { type: 'text/python' })
fireEvent.drop(screen.getByTestId('file_drop_zone'), {
dataTransfer: {
files: [file],
},
})

// input description
const describeInput = screen.getByRole('textbox')
fireEvent.change(describeInput, { target: { value: 'Test description' } })

expect(screen.getByDisplayValue('Test description')).toBeInTheDocument()

// select update type
const applicationDropdown = screen.getByText('Select an option')
fireEvent.click(applicationDropdown)

const basicOtherOption = screen.getByText('Other')
fireEvent.click(basicOtherOption)

const submitPromptButton = screen.getByText('Submit prompt')
submitPromptButton.click()
await waitFor(() => {
expect(submitPromptButton).toBeEnabled()
submitPromptButton.click()
})
expect(mockNavigate).toHaveBeenCalledWith('/chat')
})
})

0 comments on commit 66632df

Please sign in to comment.