Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(app): replace Flex+icon+text with Chip #15728

Merged
merged 3 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 8 additions & 30 deletions app/src/pages/ProtocolDashboard/ProtocolCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import {
ALIGN_CENTER,
ALIGN_END,
BORDERS,
Chip,
COLORS,
DIRECTION_COLUMN,
DIRECTION_ROW,
Flex,
Icon,
LegacyStyledText,
OVERFLOW_WRAP_ANYWHERE,
OVERFLOW_WRAP_BREAK_WORD,
SPACING,
LegacyStyledText,
TYPOGRAPHY,
useLongPress,
} from '@opentrons/components'
Expand Down Expand Up @@ -230,36 +230,14 @@ export function ProtocolCard(props: ProtocolCardProps): JSX.Element {
gridGap={SPACING.spacing8}
>
{isFailedAnalysis ? (
<Flex
color={COLORS.red60}
flexDirection={DIRECTION_ROW}
gridGap={SPACING.spacing8}
>
<Icon
name="ot-alert"
size="1.5rem"
aria-label="failedAnalysis_icon"
/>
<LegacyStyledText as="p" fontWeight={TYPOGRAPHY.fontWeightSemiBold}>
{i18n.format(t('failed_analysis'), 'capitalize')}
</LegacyStyledText>
</Flex>
<Chip
type="error"
text={i18n.format(t('failed_analysis'), 'capitalize')}
background={false}
/>
) : null}
{isRequiredCSV ? (
<Flex
color={COLORS.yellow60}
flexDirection={DIRECTION_ROW}
gridGap={SPACING.spacing8}
>
<Icon
name="ot-alert"
size="1.5rem"
aria-label="requiresCsv_file_icon"
/>
<LegacyStyledText as="p" fontWeight={TYPOGRAPHY.fontWeightSemiBold}>
{t('requires_csv')}
</LegacyStyledText>
</Flex>
<Chip type="warning" text={t('requires_csv')} background={false} />
) : null}
<LegacyStyledText
as="p"
Expand Down
18 changes: 11 additions & 7 deletions app/src/pages/ProtocolDashboard/__tests__/ProtocolCard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import type {
CompletedProtocolAnalysis,
ProtocolResource,
} from '@opentrons/shared-data'
import type { Chip } from '@opentrons/components'

const mockPush = vi.fn()

Expand All @@ -32,6 +33,13 @@ vi.mock('react-router-dom', async importOriginal => {
})
vi.mock('@opentrons/react-api-client')
vi.mock('../../../redux/config')
vi.mock('@opentrons/components', async importOriginal => {
const actual = await importOriginal<typeof Chip>()
return {
...actual,
Chip: vi.fn(() => <div>mock Chip</div>),
}
})

const mockProtocol: ProtocolResource = {
id: 'mockProtocol1',
Expand Down Expand Up @@ -119,10 +127,8 @@ describe('ProtocolCard', () => {
} as UseQueryResult<CompletedProtocolAnalysis>)
render(props)

screen.getByLabelText('failedAnalysis_icon')
screen.getByText('Failed analysis')
fireEvent.click(screen.getByText('yay mock protocol'))
screen.getByText('Protocol analysis failed')
screen.getByText('mock Chip')
screen.getByText(
'Delete the protocol, make changes to address the error, and resend the protocol to this robot from the Opentrons App.'
)
Expand Down Expand Up @@ -164,8 +170,7 @@ describe('ProtocolCard', () => {
vi.advanceTimersByTime(1005)
})
expect(props.longPress).toHaveBeenCalled()
screen.getByLabelText('failedAnalysis_icon')
screen.getByText('Failed analysis')
screen.getByText('mock Chip')
const card = screen.getByTestId('protocol_card')
expect(card).toHaveStyle(`background-color: ${COLORS.red35}`)
fireEvent.click(screen.getByText('yay mock protocol'))
Expand Down Expand Up @@ -204,8 +209,7 @@ describe('ProtocolCard', () => {
data: { result: 'parameter-value-required' } as any,
} as UseQueryResult<CompletedProtocolAnalysis>)
render({ ...props, protocol: mockProtocolWithCSV })
screen.getByLabelText('requiresCsv_file_icon')
screen.getByText('Requires CSV')
screen.getByText('mock Chip')
const card = screen.getByTestId('protocol_card')
expect(card).toHaveStyle(`background-color: ${COLORS.yellow35}`)
})
Expand Down
2 changes: 1 addition & 1 deletion app/src/pages/ProtocolDashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import {
DIRECTION_COLUMN,
DIRECTION_ROW,
Flex,
LegacyStyledText,
POSITION_STATIC,
POSITION_STICKY,
SPACING,
LegacyStyledText,
} from '@opentrons/components'
import { useAllProtocolsQuery } from '@opentrons/react-api-client'

Expand Down
Loading