-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add tests and update constants
- Loading branch information
1 parent
21941e7
commit b6a0fa3
Showing
5 changed files
with
223 additions
and
24 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
105 changes: 105 additions & 0 deletions
105
opentrons-ai-client/src/molecules/PromptPreview/__tests__/PromptPreview.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 |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import { screen } from '@testing-library/react' | ||
import { describe, it, vi, beforeEach, expect } from 'vitest' | ||
import { renderWithProviders } from '../../../__testing-utils__' | ||
import { i18n } from '../../../i18n' | ||
import { PROMPT_PREVIEW_PLACEHOLDER_MESSAGE, PromptPreview } from '..' | ||
|
||
const mockHandleClick = vi.fn() | ||
const render = (props: React.ComponentProps<typeof PromptPreview>) => { | ||
return renderWithProviders(<PromptPreview {...props} />, { | ||
i18nInstance: i18n, | ||
}) | ||
} | ||
|
||
describe('PromptPreview', () => { | ||
let props: React.ComponentProps<typeof PromptPreview> | ||
|
||
beforeEach(() => { | ||
props = { | ||
isSubmitButtonEnabled: false, | ||
handleSubmit: () => { | ||
mockHandleClick() | ||
}, | ||
promptPreviewData: [ | ||
{ | ||
title: 'Test Section 1', | ||
items: ['item1', 'item2'], | ||
}, | ||
{ | ||
title: 'Test Section 2', | ||
items: ['item3', 'item4'], | ||
}, | ||
], | ||
} | ||
}) | ||
|
||
it('should render the PromptPreview component', () => { | ||
render(props) | ||
|
||
expect(screen.getByText('Prompt')).toBeInTheDocument() | ||
}) | ||
|
||
it('should render the submit button', () => { | ||
render(props) | ||
|
||
expect(screen.getByText('Submit prompt')).toBeInTheDocument() | ||
}) | ||
|
||
it('should render the placeholder message when all sections are empty', () => { | ||
props.promptPreviewData = [ | ||
{ | ||
title: 'Test Section 1', | ||
items: [], | ||
}, | ||
{ | ||
title: 'Test Section 2', | ||
items: [], | ||
}, | ||
] | ||
render(props) | ||
|
||
expect( | ||
screen.getByText(PROMPT_PREVIEW_PLACEHOLDER_MESSAGE) | ||
).toBeInTheDocument() | ||
}) | ||
|
||
it('should not render the placeholder message when at least one section has items', () => { | ||
render(props) | ||
|
||
expect( | ||
screen.queryByText(PROMPT_PREVIEW_PLACEHOLDER_MESSAGE) | ||
).not.toBeInTheDocument() | ||
}) | ||
|
||
it('should render the sections with items', () => { | ||
render(props) | ||
|
||
expect(screen.getByText('Test Section 1')).toBeInTheDocument() | ||
expect(screen.getByText('Test Section 2')).toBeInTheDocument() | ||
}) | ||
|
||
it('should display submit button disabled when isSubmitButtonEnabled is false', () => { | ||
render(props) | ||
|
||
expect(screen.getByRole('button', { name: 'Submit prompt' })).toBeDisabled() | ||
}) | ||
|
||
it('should display submit button enabled when isSubmitButtonEnabled is true', () => { | ||
props.isSubmitButtonEnabled = true | ||
render(props) | ||
|
||
expect( | ||
screen.getByRole('button', { name: 'Submit prompt' }) | ||
).not.toBeDisabled() | ||
}) | ||
|
||
it('should call handleSubmit when the submit button is clicked', () => { | ||
props.isSubmitButtonEnabled = true | ||
render(props) | ||
|
||
const submitButton = screen.getByRole('button', { name: 'Submit prompt' }) | ||
submitButton.click() | ||
|
||
expect(mockHandleClick).toHaveBeenCalled() | ||
}) | ||
}) |
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
51 changes: 51 additions & 0 deletions
51
...rons-ai-client/src/molecules/PromptPreviewSection/__tests__/PromptPreviewSection.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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import type * as React from 'react' | ||
import { screen } from '@testing-library/react' | ||
import { describe, it, beforeEach, expect } from 'vitest' | ||
import { renderWithProviders } from '../../../__testing-utils__' | ||
import { i18n } from '../../../i18n' | ||
|
||
import { PromptPreviewSection } from '../index' | ||
|
||
const render = (props: React.ComponentProps<typeof PromptPreviewSection>) => { | ||
return renderWithProviders(<PromptPreviewSection {...props} />, { | ||
i18nInstance: i18n, | ||
}) | ||
} | ||
|
||
describe('PromptPreviewSection', () => { | ||
let props: React.ComponentProps<typeof PromptPreviewSection> | ||
|
||
beforeEach(() => { | ||
props = { | ||
title: 'Test Section', | ||
items: ['test item 1', 'test item 2'], | ||
} | ||
}) | ||
|
||
it('should render the PromptPreviewSection component', () => { | ||
render(props) | ||
|
||
expect(screen.getByText('Test Section')).toBeInTheDocument() | ||
}) | ||
|
||
it('should render the section title', () => { | ||
render(props) | ||
|
||
expect(screen.getByText('Test Section')).toBeInTheDocument() | ||
}) | ||
|
||
it('should render the items', () => { | ||
render(props) | ||
|
||
expect(screen.getByText('test item 1')).toBeInTheDocument() | ||
expect(screen.getByText('test item 2')).toBeInTheDocument() | ||
}) | ||
|
||
it("should not render the item tag if it's an empty string", () => { | ||
props.items = ['test item 1', ''] | ||
render(props) | ||
|
||
const items = screen.getAllByTestId('Tag_default') | ||
expect(items).toHaveLength(1) | ||
}) | ||
}) |
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