-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(app): refactor show labware offset snippets (#14367)
* refactor(app): refactor ShowLabwareOffsetSnippets
- Loading branch information
Showing
5 changed files
with
128 additions
and
53 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
app/src/organisms/AdvancedSettings/ShowLabwareOffsetSnippets.tsx
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,60 @@ | ||
import * as React from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import { useSelector, useDispatch } from 'react-redux' | ||
|
||
import { | ||
Flex, | ||
Box, | ||
ALIGN_CENTER, | ||
JUSTIFY_SPACE_BETWEEN, | ||
TYPOGRAPHY, | ||
SPACING, | ||
} from '@opentrons/components' | ||
|
||
import { StyledText } from '../../atoms/text' | ||
import { ToggleButton } from '../../atoms/buttons' | ||
import { | ||
getIsLabwareOffsetCodeSnippetsOn, | ||
updateConfigValue, | ||
} from '../../redux/config' | ||
import { Dispatch } from '../../redux/types' | ||
|
||
export function ShowLabwareOffsetSnippets(): JSX.Element { | ||
const { t } = useTranslation(['app_settings', 'shared']) | ||
const dispatch = useDispatch<Dispatch>() | ||
const isLabwareOffsetCodeSnippetsOn = useSelector( | ||
getIsLabwareOffsetCodeSnippetsOn | ||
) | ||
|
||
const toggleLabwareOffsetData = (): void => { | ||
dispatch( | ||
updateConfigValue( | ||
'labware.showLabwareOffsetCodeSnippets', | ||
Boolean(!isLabwareOffsetCodeSnippetsOn) | ||
) | ||
) | ||
} | ||
|
||
return ( | ||
<Flex alignItems={ALIGN_CENTER} justifyContent={JUSTIFY_SPACE_BETWEEN}> | ||
<Box width="70%"> | ||
<StyledText | ||
css={TYPOGRAPHY.h3SemiBold} | ||
paddingBottom={SPACING.spacing8} | ||
id="AdvancedSettings_showLink" | ||
> | ||
{t('show_labware_offset_snippets')} | ||
</StyledText> | ||
<StyledText as="p"> | ||
{t('show_labware_offset_snippets_description')} | ||
</StyledText> | ||
</Box> | ||
<ToggleButton | ||
label="show_link_to_get_labware_offset_data" | ||
toggledOn={isLabwareOffsetCodeSnippetsOn} | ||
onClick={toggleLabwareOffsetData} | ||
id="AdvancedSettings_showLinkToggleButton" | ||
/> | ||
</Flex> | ||
) | ||
} |
54 changes: 54 additions & 0 deletions
54
app/src/organisms/AdvancedSettings/__tests__/ShowLabwareOffsetSnippets.test.tsx
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,54 @@ | ||
import * as React from 'react' | ||
import { fireEvent, screen } from '@testing-library/react' | ||
|
||
import { i18n } from '../../../i18n' | ||
import { renderWithProviders } from '@opentrons/components' | ||
import { | ||
getIsLabwareOffsetCodeSnippetsOn, | ||
updateConfigValue, | ||
} from '../../../redux/config' | ||
import { ShowLabwareOffsetSnippets } from '../ShowLabwareOffsetSnippets' | ||
|
||
jest.mock('../../../redux/config') | ||
|
||
const mockGetIsLabwareOffsetCodeSnippetsOn = getIsLabwareOffsetCodeSnippetsOn as jest.MockedFunction< | ||
typeof getIsLabwareOffsetCodeSnippetsOn | ||
> | ||
const mockUpdateConfigValue = updateConfigValue as jest.MockedFunction< | ||
typeof updateConfigValue | ||
> | ||
|
||
const render = () => { | ||
return ( | ||
renderWithProviders(<ShowLabwareOffsetSnippets />), | ||
{ | ||
i18nInstance: i18n, | ||
} | ||
) | ||
} | ||
|
||
describe('ShowLabwareOffsetSnippets', () => { | ||
beforeEach(() => { | ||
mockGetIsLabwareOffsetCodeSnippetsOn.mockReturnValue(true) | ||
}) | ||
it('renders the display show link to get labware offset data section', () => { | ||
render() | ||
screen.getByText('Show Labware Offset data code snippets') | ||
screen.getByText( | ||
'Only for users who need to apply Labware Offset data outside of the Opentrons App. When enabled, code snippets for Jupyter Notebook and SSH are available during protocol setup.' | ||
) | ||
screen.getByRole('switch', { name: 'show_link_to_get_labware_offset_data' }) | ||
}) | ||
|
||
it('should call a mock function when clicking toggle button', () => { | ||
render() | ||
const toggleButton = screen.getByRole('switch', { | ||
name: 'show_link_to_get_labware_offset_data', | ||
}) | ||
fireEvent.click(toggleButton) | ||
expect(mockUpdateConfigValue).toHaveBeenCalledWith( | ||
'labware.showLabwareOffsetCodeSnippets', | ||
false | ||
) | ||
}) | ||
}) |
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