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

fix(shared-data, app): fix small issues in app #14851

Merged
merged 2 commits into from
Apr 10, 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
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ type Story = StoryObj<typeof NumericalKeyboard>

const Keyboard = (args): JSX.Element => {
const { isDecimal, hasHyphen } = args
console.log(isDecimal, hasHyphen)
const [showKeyboard, setShowKeyboard] = React.useState(false)
const [value, setValue] = React.useState<string>('')
const keyboardRef = React.useRef(null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ vi.mock('../../../redux/protocol-storage')
vi.mock('../../RunTimeControl/hooks')
vi.mock('../HistoricalProtocolRunOverflowMenu')
vi.mock('react-router-dom', async importOriginal => {
const reactRouterDom = importOriginal<typeof Dom>()
return await {
const reactRouterDom = await importOriginal<typeof Dom>()
return {
...reactRouterDom,
useHistory: () => ({ push: mockPush } as any),
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/organisms/Devices/__tests__/RobotOverview.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ import type { State } from '../../../redux/types'
import type * as ReactApiClient from '@opentrons/react-api-client'

vi.mock('@opentrons/react-api-client', async importOriginal => {
const actual = importOriginal<typeof ReactApiClient>()
return await {
const actual = await importOriginal<typeof ReactApiClient>()
return {
...actual,
useAuthorization: vi.fn(),
}
Expand Down
2 changes: 0 additions & 2 deletions app/src/organisms/ModuleCard/TemperatureModuleData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ export const TemperatureModuleData = (
let pulse
switch (moduleStatus) {
case 'idle': {
backgroundColor = COLORS.grey30
iconColor = COLORS.grey60
textColor = COLORS.grey60
break
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import { describe, it, expect, vi } from 'vitest'
import { formatRunTimeParameterDefaultValue } from '../formatRunTimeParameterDefaultValue'

import type { RunTimeParameter } from '../../types'

const capitalizeFirstLetter = (str: string): string => {
return str.charAt(0).toUpperCase() + str.slice(1)
}

const mockTFunction = vi.fn(str => capitalizeFirstLetter(str))

describe('formatRunTimeParameterDefaultValue', () => {
it('should return value with suffix when type is int', () => {
const mockData = {
value: 6,
displayName: 'PCR Cycles',
variableName: 'PCR_CYCLES',
description: 'number of PCR cycles on a thermocycler',
type: 'int',
min: 1,
max: 10,
default: 6,
suffix: 'samples',
} as RunTimeParameter
const result = formatRunTimeParameterDefaultValue(mockData, mockTFunction)
expect(result).toEqual('6 samples')
})

it('should return value with suffix when type is float', () => {
const mockData = {
value: 6.5,
displayName: 'EtoH Volume',
variableName: 'ETOH_VOLUME',
description: '70% ethanol volume',
type: 'float',
suffix: 'mL',
min: 1.5,
max: 10.0,
default: 6.5,
} as RunTimeParameter
const result = formatRunTimeParameterDefaultValue(mockData, mockTFunction)
expect(result).toEqual('6.5 mL')
})

it('should return value when type is str', () => {
const mockData = {
value: 'left',
displayName: 'pipette mount',
variableName: 'mount',
description: 'pipette mount',
type: 'str',
choices: [
{
displayName: 'Left',
value: 'left',
},
{
displayName: 'Right',
value: 'right',
},
],
default: 'left',
} as RunTimeParameter
const result = formatRunTimeParameterDefaultValue(mockData, mockTFunction)
expect(result).toEqual('Left')
})

it('should return value when type is int choice with suffix', () => {
const mockData = {
value: 5,
displayName: 'num',
variableName: 'number',
description: 'its just number',
type: 'int',
suffix: 'mL',
min: 1,
max: 10,
choices: [
{
displayName: 'one',
value: 1,
},
{
displayName: 'six',
value: 6,
},
],
default: 5,
} as RunTimeParameter
const result = formatRunTimeParameterDefaultValue(mockData, mockTFunction)
expect(result).toEqual('5 mL')
})

it('should return value when type is float choice with suffix', () => {
const mockData = {
value: 5.0,
displayName: 'num',
variableName: 'number',
description: 'its just number',
type: 'float',
suffix: 'mL',
min: 1.0,
max: 10.0,
choices: [
{
displayName: 'one',
value: 1.0,
},
{
displayName: 'six',
value: 6.0,
},
],
default: 5.0,
} as RunTimeParameter
const result = formatRunTimeParameterDefaultValue(mockData, mockTFunction)
expect(result).toEqual('5 mL')
})

it('should return value when type is boolean true', () => {
const mockData = {
value: true,
displayName: 'Deactivate Temperatures',
variableName: 'DEACTIVATE_TEMP',
description: 'deactivate temperature on the module',
type: 'bool',
default: true,
} as RunTimeParameter
const result = formatRunTimeParameterDefaultValue(mockData, mockTFunction)
expect(result).toEqual('On')
})

it('should return value when type is boolean false', () => {
const mockData = {
value: false,
displayName: 'Dry Run',
variableName: 'DRYRUN',
description: 'Is this a dry or wet run? Wet is true, dry is false',
type: 'bool',
default: false,
} as RunTimeParameter
const result = formatRunTimeParameterDefaultValue(mockData, mockTFunction)
expect(result).toEqual('Off')
})
})
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, it, expect, vi } from 'vitest'
import { formatRunTimeParameterDefaultValue } from '../formatRunTimeParameterDefaultValue'
import { formatRunTimeParameterValue } from '../formatRunTimeParameterValue'

import type { RunTimeParameter } from '../../types'

Expand All @@ -21,7 +21,7 @@ describe('utils-formatRunTimeParameterDefaultValue', () => {
max: 10,
default: 6,
} as RunTimeParameter
const result = formatRunTimeParameterDefaultValue(mockData, mockTFunction)
const result = formatRunTimeParameterValue(mockData, mockTFunction)
expect(result).toEqual('6')
})

Expand All @@ -37,7 +37,7 @@ describe('utils-formatRunTimeParameterDefaultValue', () => {
max: 10.0,
default: 6.5,
} as RunTimeParameter
const result = formatRunTimeParameterDefaultValue(mockData, mockTFunction)
const result = formatRunTimeParameterValue(mockData, mockTFunction)
expect(result).toEqual('6.5 mL')
})

Expand All @@ -60,7 +60,7 @@ describe('utils-formatRunTimeParameterDefaultValue', () => {
],
default: 'left',
} as RunTimeParameter
const result = formatRunTimeParameterDefaultValue(mockData, mockTFunction)
const result = formatRunTimeParameterValue(mockData, mockTFunction)
expect(result).toEqual('Left')
})

Expand All @@ -86,7 +86,7 @@ describe('utils-formatRunTimeParameterDefaultValue', () => {
],
default: 5,
} as RunTimeParameter
const result = formatRunTimeParameterDefaultValue(mockData, mockTFunction)
const result = formatRunTimeParameterValue(mockData, mockTFunction)
expect(result).toEqual('5 mL')
})

Expand All @@ -112,7 +112,7 @@ describe('utils-formatRunTimeParameterDefaultValue', () => {
],
default: 5.0,
} as RunTimeParameter
const result = formatRunTimeParameterDefaultValue(mockData, mockTFunction)
const result = formatRunTimeParameterValue(mockData, mockTFunction)
expect(result).toEqual('5 mL')
})

Expand All @@ -125,7 +125,7 @@ describe('utils-formatRunTimeParameterDefaultValue', () => {
type: 'bool',
default: true,
} as RunTimeParameter
const result = formatRunTimeParameterDefaultValue(mockData, mockTFunction)
const result = formatRunTimeParameterValue(mockData, mockTFunction)
expect(result).toEqual('On')
})

Expand All @@ -138,7 +138,7 @@ describe('utils-formatRunTimeParameterDefaultValue', () => {
type: 'bool',
default: false,
} as RunTimeParameter
const result = formatRunTimeParameterDefaultValue(mockData, mockTFunction)
const result = formatRunTimeParameterValue(mockData, mockTFunction)
expect(result).toEqual('Off')
})
})
10 changes: 10 additions & 0 deletions shared-data/js/helpers/formatRunTimeParameterDefaultValue.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import type { RunTimeParameter } from '../types'

/**
* Formats the runtime parameter's default value.
*
* @param {RunTimeParameter} runTimeParameter - The runtime parameter whose default value is to be formatted.
* @param {Function} [t] - An optional function for localization.
*
* @returns {string} The formatted default value of the runtime parameter.
*
*/

export const formatRunTimeParameterDefaultValue = (
runTimeParameter: RunTimeParameter,
t?: any
Expand Down
21 changes: 21 additions & 0 deletions shared-data/js/helpers/formatRunTimeParameterMinMax.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
import type { RunTimeParameter } from '../types'
/**
* Formats the runtime parameter's minimum and maximum values.
*
* @param {RunTimeParameter} runTimeParameter - The runtime parameter whose min and max values are to be formatted.
*
* @returns {string} The formatted min-max value of the runtime parameter.
*
* @example
* const runTimeParameter = {
* value: 6.5,
* displayName: 'EtoH Volume',
* variableName: 'ETOH_VOLUME',
* description: '70% ethanol volume',
* type: 'float',
* suffix: 'mL',
* min: 1.5,
* max: 10.0,
* default: 6.5,
* }
* console.log(formatRunTimeParameterMinMax(runTimeParameter)); // "1.5-10.0"
*/

export const formatRunTimeParameterMinMax = (
runTimeParameter: RunTimeParameter
Expand Down
10 changes: 10 additions & 0 deletions shared-data/js/helpers/formatRunTimeParameterValue.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import type { RunTimeParameter } from '../types'

/**
* Formats the runtime parameter value.
*
* @param {RunTimeParameter} runTimeParameter - The runtime parameter to be formatted.
* @param {Function} t - A function for localization.
*
* @returns {string} The formatted runtime parameter value.
*
*/

export const formatRunTimeParameterValue = (
runTimeParameter: RunTimeParameter,
t: any
Expand Down
26 changes: 13 additions & 13 deletions shared-data/js/helpers/orderRuntimeParameterRangeOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ export const isNumeric = (str: string): boolean => {
* @param {Choice[]} - The array of Choice
* Choice is an object like {displayName: 'Single channel 50µL', value: 'flex_1channel_50' }
* @returns {string} The ordered string with ","
*
* examples
* [
{ displayName: '20', value: 20 },
{ displayName: '16', value: 16 },
]
return 16, 20

[
{ displayName: 'Single channel 50µL', value: 'flex_1channel_50' },
{ displayName: 'Eight Channel 50µL', value: 'flex_8channel_50' },
]
return Eight Channel 50µL, Single channel 50µL
*
* @example
* const numChoices = [
* { displayName: '20', value: 20 },
* { displayName: '16', value: 16 },
* ]
* console.log(orderRuntimeParameterRangeOptions(numChoices) // 16,20
*
* const strChoices = [
* { displayName: 'Single channel 50µL', value: 'flex_1channel_50' },
* { displayName: 'Eight Channel 50µL', value: 'flex_8channel_50' },
* ]
* console.log(orderRuntimeParameterRangeOptions(strChoices) // Eight Channel 50µL, Single channel 50µL
*/
export const orderRuntimeParameterRangeOptions = (
choices: Choice[]
Expand Down
Loading