diff --git a/opentrons-ai-client/src/molecules/HeaderWithMeter/HeaderWithMeter.stories.tsx b/opentrons-ai-client/src/molecules/HeaderWithMeter/HeaderWithMeter.stories.tsx new file mode 100644 index 00000000000..80608117379 --- /dev/null +++ b/opentrons-ai-client/src/molecules/HeaderWithMeter/HeaderWithMeter.stories.tsx @@ -0,0 +1,20 @@ +import type { Meta, StoryObj } from '@storybook/react' +import { HeaderWithMeter as HeaderWithMeterComponent } from '.' +import { COLORS, Flex, SPACING } from '@opentrons/components' + +const meta: Meta = { + title: 'AI/Molecules/HeaderWithMeter', + component: HeaderWithMeterComponent, + decorators: [ + Story => ( + + + + ), + ], +} +export default meta + +type Story = StoryObj + +export const HeaderWithMeterExample: Story = {} diff --git a/opentrons-ai-client/src/molecules/HeaderWithMeter/__tests__/HeaderWithMeter.test.tsx b/opentrons-ai-client/src/molecules/HeaderWithMeter/__tests__/HeaderWithMeter.test.tsx new file mode 100644 index 00000000000..8d02aeb3e12 --- /dev/null +++ b/opentrons-ai-client/src/molecules/HeaderWithMeter/__tests__/HeaderWithMeter.test.tsx @@ -0,0 +1,51 @@ +import { renderWithProviders } from '../../../__testing-utils__' +import { i18n } from '../../../i18n' +import { HeaderWithMeter } from '../index' +import { describe, expect, it } from 'vitest' +import { screen, render as rtlRender } from '@testing-library/react' + +const render = (): ReturnType => { + return renderWithProviders(, { + i18nInstance: i18n, + }) +} + +describe('HeaderWithMeter', () => { + it('should render Header component', () => { + render() + screen.getByText('Opentrons') + }) + + it('should render progress bar', () => { + render() + screen.getByRole('progressbar') + }) + + it('should render progress bar with correct value', () => { + render() + const progressBar = screen.getByRole('progressbar') + expect(progressBar).toHaveAttribute('value', '0.3') + }) + + it('should update when progressPercentage prop changes', () => { + const { rerender } = rtlRender( + , + {} + ) + + const progressBar = screen.getByRole('progressbar') + expect(progressBar).toHaveAttribute('value', '0.3') + + rerender() + expect(progressBar).toHaveAttribute('value', '0.6') + + rerender() + expect(progressBar).toHaveAttribute('value', '1') + + rerender() + expect(progressBar).toHaveAttribute('value', '0') + + rerender() + expect(progressBar).toHaveAttribute('value', '0.2') + }) +}) diff --git a/opentrons-ai-client/src/molecules/HeaderWithMeter/index.tsx b/opentrons-ai-client/src/molecules/HeaderWithMeter/index.tsx new file mode 100644 index 00000000000..24bc1a89805 --- /dev/null +++ b/opentrons-ai-client/src/molecules/HeaderWithMeter/index.tsx @@ -0,0 +1,50 @@ +import { + Flex, + DIRECTION_COLUMN, + JUSTIFY_SPACE_BETWEEN, + COLORS, +} from '@opentrons/components' +import { Header } from '../Header' +import styled from 'styled-components' + +const SquareProgressBar = styled.progress` + width: 100%; + height: 4px; + border-radius: 0; + appearance: none; + + &::-webkit-progress-bar { + background-color: ${COLORS.grey30}; /* Background color of the progress bar */ + border-radius: 0; + } + + &::-webkit-progress-value { + background-color: ${COLORS.blue50}; /* Color of the progress value */ + border-radius: 0; + transition: width 1s; + } + + &::-moz-progress-bar { + background-color: ${COLORS.blue50}; /* Color of the progress value for Firefox */ + border-radius: 0; + } +` + +export interface ChatHeaderProps { + progressPercentage: number +} + +export function HeaderWithMeter({ + progressPercentage = 0.5, +}: ChatHeaderProps): JSX.Element { + return ( + +
+ + + ) +}