-
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.
fix(shared-data, app): fix small issues in app (#14851)
* fix(shared-data, app): fix small issues in app
- Loading branch information
Showing
10 changed files
with
211 additions
and
28 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
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
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
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
145 changes: 145 additions & 0 deletions
145
shared-data/js/helpers/__tests__/formatRunTimeParameterDefaultValue.test.ts
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,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') | ||
}) | ||
}) |
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
10 changes: 10 additions & 0 deletions
10
shared-data/js/helpers/formatRunTimeParameterDefaultValue.ts
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
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
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
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