Skip to content

Commit 3d7750c

Browse files
committed
add very basic tests
1 parent 642bbde commit 3d7750c

File tree

2 files changed

+103
-9
lines changed

2 files changed

+103
-9
lines changed

protocol-designer/src/components/organisms/ProtocolStartingDeck/StartingDeckContainer.tsx

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useMemo, useState, Fragment } from 'react'
1+
import { Fragment, useMemo, useState } from 'react'
22
import { useDispatch, useSelector } from 'react-redux'
33
import {
44
ALIGN_CENTER,
@@ -72,6 +72,7 @@ export function StartingDeckContainer(): JSX.Element {
7272
const [hoveredLabware, setHoveredLabware] = useState<string | null>(null)
7373
const [hoveredModule, setHoveredModule] = useState<ModuleModel | null>(null)
7474
const [hoveredFixture, setHoveredFixture] = useState<Fixture | null>(null)
75+
console.log('zoomIn', zoomIn)
7576
const trash = Object.values(activeDeckSetup.additionalEquipmentOnDeck).find(
7677
ae => ae.name === 'trashBin'
7778
)
@@ -95,7 +96,6 @@ export function StartingDeckContainer(): JSX.Element {
9596
const [viewBoxX, viewBoxY] = deckDef.cornerOffsetFromOrigin
9697
const [viewBoxWidth, viewBoxHeight] = deckDef.dimensions
9798
const initialViewBox = `${viewBoxX} ${viewBoxY} ${viewBoxWidth} ${viewBoxHeight}`
98-
9999
const [viewBox, setViewBox] = useState<string>(initialViewBox)
100100

101101
const isZoomed = Object.values(zoomIn).some(val => val != null)
@@ -155,11 +155,6 @@ export function StartingDeckContainer(): JSX.Element {
155155
aa => isAddressableAreaStandardSlot(aa.id, deckDef)
156156
)
157157

158-
let containerPadding = '0'
159-
if (!isZoomed) {
160-
containerPadding = SPACING.spacing40
161-
}
162-
163158
return (
164159
<>
165160
<Flex
@@ -168,7 +163,7 @@ export function StartingDeckContainer(): JSX.Element {
168163
width="100%"
169164
height="100%"
170165
flexDirection={DIRECTION_COLUMN}
171-
padding={containerPadding}
166+
padding={isZoomed ? '0' : SPACING.spacing40}
172167
justifyContent={JUSTIFY_CENTER}
173168
position="relative"
174169
maxHeight="auto"
@@ -201,7 +196,6 @@ export function StartingDeckContainer(): JSX.Element {
201196
deckDef={deckDef}
202197
viewBox={viewBox}
203198
outline="auto"
204-
zoomed={zoomIn.slot != null}
205199
borderRadius={BORDERS.borderRadius12}
206200
>
207201
{() => (
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import { describe, it, beforeEach, vi } from 'vitest'
2+
import { when } from 'vitest-when'
3+
import { screen } from '@testing-library/react'
4+
import {
5+
getDeckDefFromRobotType,
6+
FLEX_ROBOT_TYPE,
7+
OT2_ROBOT_TYPE,
8+
ot2StandardDeckV4 as ot2StandardDeckDef,
9+
ot3StandardDeckV4 as ot3StandardDeckDef,
10+
} from '@opentrons/shared-data'
11+
12+
import { renderWithProviders } from '../../../../__testing-utils__'
13+
import { getDeckSetupForActiveItem } from '../../../../top-selectors/labware-locations'
14+
import { selectors } from '../../../../labware-ingred/selectors'
15+
import { getRobotType } from '../../../../file-data/selectors'
16+
import { getDisableModuleRestrictions } from '../../../../feature-flags/selectors'
17+
// import { DeckSetupDetails } from '../../../../pages/Designer/DeckSetup/DeckSetupDetails'
18+
import { DeckSetupTools } from '../../../../pages/Designer/DeckSetup/DeckSetupTools'
19+
import { StartingDeckContainer } from '../StartingDeckContainer'
20+
21+
import type * as OpentronsComponents from '@opentrons/components'
22+
23+
vi.mock('../../../../top-selectors/labware-locations')
24+
// vi.mock('../../../../pages/Designer/DeckSetup/DeckSetupDetails')
25+
vi.mock('../../../../pages/Designer/DeckSetup/DeckSetupTools')
26+
vi.mock('../../../../labware-ingred/selectors')
27+
vi.mock('../../../../feature-flags/selectors')
28+
vi.mock('../../../../file-data/selectors')
29+
vi.mock('../../../../pages/Designer/DeckSetup/utils')
30+
vi.mock('@opentrons/components', async importOriginal => {
31+
const actual = await importOriginal<typeof OpentronsComponents>()
32+
return {
33+
...actual,
34+
RobotCoordinateSpaceWithRef: () => (
35+
<div>mock RobotCoordinateSpaceWithRef</div>
36+
),
37+
SlotLabels: () => <div>mock SlotLabels</div>,
38+
DeckFromLayers: () => <div>mock DeckFromLayers</div>,
39+
SingleSlotFixture: () => <div>mock StagingAreaFixture</div>,
40+
}
41+
})
42+
vi.mock('@opentrons/shared-data', async importOriginal => {
43+
const actual = await importOriginal<typeof getDeckDefFromRobotType>()
44+
return {
45+
...actual,
46+
getDeckDefFromRobotType: vi.fn(),
47+
}
48+
})
49+
50+
const render = () => {
51+
return renderWithProviders(<StartingDeckContainer />)
52+
}
53+
54+
describe('StartingDeckContainer', () => {
55+
beforeEach(() => {
56+
// vi.mocked(DeckSetupDetails).mockReturnValue(
57+
// <div>mock DeckSetupDetails</div>
58+
// )
59+
vi.mocked(DeckSetupTools).mockReturnValue(<div>mock DeckSetupTools</div>)
60+
vi.mocked(getDisableModuleRestrictions).mockReturnValue(false)
61+
vi.mocked(getRobotType).mockReturnValue(FLEX_ROBOT_TYPE)
62+
when(vi.mocked(getDeckDefFromRobotType))
63+
.calledWith(FLEX_ROBOT_TYPE)
64+
.thenReturn(ot3StandardDeckDef as any)
65+
vi.mocked(getDeckSetupForActiveItem).mockReturnValue({
66+
labware: {},
67+
modules: {},
68+
additionalEquipmentOnDeck: {},
69+
pipettes: {},
70+
})
71+
vi.mocked(selectors.getZoomedInSlotInfo).mockReturnValue({
72+
selectedLabwareDefUri: null,
73+
selectedNestedLabwareDefUri: null,
74+
selectedFixture: null,
75+
selectedModuleModel: null,
76+
selectedSlot: { slot: 'D3', cutout: 'cutoutD3' },
77+
})
78+
vi.mocked(selectors.getZoomedInSlot).mockReturnValue({
79+
slot: 'D3',
80+
cutout: 'cutoutD3',
81+
})
82+
})
83+
84+
it('should render mock RobotCoordinateSpaceWithRef when robot type is Flex', () => {
85+
render()
86+
screen.getByText('mock RobotCoordinateSpaceWithRef')
87+
screen.getByText('mock DeckSetupTools')
88+
})
89+
90+
it('should render mock RobotCoordinateSpaceWithRef when robot type is OT-2', () => {
91+
when(vi.mocked(getDeckDefFromRobotType))
92+
.calledWith(OT2_ROBOT_TYPE)
93+
.thenReturn(ot2StandardDeckDef as any)
94+
render()
95+
screen.getByText('mock RobotCoordinateSpaceWithRef')
96+
screen.getByText('mock DeckSetupTools')
97+
})
98+
99+
// ToDo (kk:03/19/25) add more tests
100+
})

0 commit comments

Comments
 (0)