diff --git a/app/src/organisms/AdvancedSettings/ShowLabwareOffsetSnippets.tsx b/app/src/organisms/AdvancedSettings/ShowLabwareOffsetSnippets.tsx new file mode 100644 index 00000000000..7223ca39e31 --- /dev/null +++ b/app/src/organisms/AdvancedSettings/ShowLabwareOffsetSnippets.tsx @@ -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() + const isLabwareOffsetCodeSnippetsOn = useSelector( + getIsLabwareOffsetCodeSnippetsOn + ) + + const toggleLabwareOffsetData = (): void => { + dispatch( + updateConfigValue( + 'labware.showLabwareOffsetCodeSnippets', + Boolean(!isLabwareOffsetCodeSnippetsOn) + ) + ) + } + + return ( + + + + {t('show_labware_offset_snippets')} + + + {t('show_labware_offset_snippets_description')} + + + + + ) +} diff --git a/app/src/organisms/AdvancedSettings/__tests__/ShowLabwareOffsetSnippets.test.tsx b/app/src/organisms/AdvancedSettings/__tests__/ShowLabwareOffsetSnippets.test.tsx new file mode 100644 index 00000000000..ecce36d0631 --- /dev/null +++ b/app/src/organisms/AdvancedSettings/__tests__/ShowLabwareOffsetSnippets.test.tsx @@ -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(), + { + 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 + ) + }) +}) diff --git a/app/src/organisms/AdvancedSettings/index.ts b/app/src/organisms/AdvancedSettings/index.ts index a402af06dae..ae080fa2bb4 100644 --- a/app/src/organisms/AdvancedSettings/index.ts +++ b/app/src/organisms/AdvancedSettings/index.ts @@ -4,4 +4,5 @@ export * from './OT2AdvancedSettings' export * from './OverridePathToPython' export * from './PreventRobotCaching' export * from './ShowHeaterShakerAttachmentModal' +export * from './ShowLabwareOffsetSnippets' export * from './U2EInformation' diff --git a/app/src/pages/AppSettings/AdvancedSettings.tsx b/app/src/pages/AppSettings/AdvancedSettings.tsx index d2af61bbfde..0e2972b3eec 100644 --- a/app/src/pages/AppSettings/AdvancedSettings.tsx +++ b/app/src/pages/AppSettings/AdvancedSettings.tsx @@ -25,7 +25,7 @@ import { ANALYTICS_CHANGE_CUSTOM_LABWARE_SOURCE_FOLDER, } from '../../redux/analytics' import { Divider } from '../../atoms/structure' -import { TertiaryButton, ToggleButton } from '../../atoms/buttons' +import { TertiaryButton } from '../../atoms/buttons' import { StyledText } from '../../atoms/text' import { ClearUnavailableRobots, @@ -35,6 +35,7 @@ import { PreventRobotCaching, ShowHeaterShakerAttachmentModal, U2EInformation, + ShowLabwareOffsetSnippets, } from '../../organisms/AdvancedSettings' import type { Dispatch } from '../../redux/types' @@ -47,19 +48,7 @@ export function AdvancedSettings(): JSX.Element { Config.getUpdateChannelOptions ) const labwarePath = useSelector(CustomLabware.getCustomLabwareDirectory) - const isLabwareOffsetCodeSnippetsOn = useSelector( - Config.getIsLabwareOffsetCodeSnippetsOn - ) const dispatch = useDispatch() - const toggleLabwareOffsetData = (): void => { - dispatch( - Config.updateConfigValue( - 'labware.showLabwareOffsetCodeSnippets', - Boolean(!isLabwareOffsetCodeSnippetsOn) - ) - ) - } - const handleChannel = (_: string, value: string): void => { dispatch(Config.updateConfigValue('update.channel', value)) } @@ -186,26 +175,7 @@ export function AdvancedSettings(): JSX.Element { - - - - {t('show_labware_offset_snippets')} - - - {t('show_labware_offset_snippets_description')} - - - - + diff --git a/app/src/pages/AppSettings/__test__/AdvancedSettings.test.tsx b/app/src/pages/AppSettings/__test__/AdvancedSettings.test.tsx index c428ce7d223..a7598322bf8 100644 --- a/app/src/pages/AppSettings/__test__/AdvancedSettings.test.tsx +++ b/app/src/pages/AppSettings/__test__/AdvancedSettings.test.tsx @@ -18,6 +18,7 @@ import { OT2AdvancedSettings, OverridePathToPython, PreventRobotCaching, + ShowLabwareOffsetSnippets, U2EInformation, ShowHeaterShakerAttachmentModal, } from '../../../organisms/AdvancedSettings' @@ -52,10 +53,6 @@ const getChannelOptions = Config.getUpdateChannelOptions as jest.MockedFunction< typeof Config.getUpdateChannelOptions > -const mockGetIsLabwareOffsetCodeSnippetsOn = Config.getIsLabwareOffsetCodeSnippetsOn as jest.MockedFunction< - typeof Config.getIsLabwareOffsetCodeSnippetsOn -> - const mockUseTrackEvent = useTrackEvent as jest.MockedFunction< typeof useTrackEvent > @@ -72,6 +69,9 @@ const mockEnableDevTools = EnableDevTools as jest.MockedFunction< const mockU2EInformation = U2EInformation as jest.MockedFunction< typeof U2EInformation > +const mockShowLabwareOffsetSnippets = ShowLabwareOffsetSnippets as jest.MockedFunction< + typeof ShowLabwareOffsetSnippets +> const mockClearUnavailableRobots = ClearUnavailableRobots as jest.MockedFunction< typeof ClearUnavailableRobots > @@ -101,6 +101,9 @@ describe('AdvancedSettings', () => { mockOT2AdvancedSettings.mockReturnValue(
mock OT2AdvancedSettings
) mockEnableDevTools.mockReturnValue(
mock EnableDevTools
) mockU2EInformation.mockReturnValue(
mock U2EInformation
) + mockShowLabwareOffsetSnippets.mockReturnValue( +
mock ShowLabwareOffsetSnippets
+ ) mockClearUnavailableRobots.mockReturnValue(
mock ClearUnavailableRobots
) @@ -166,22 +169,9 @@ describe('AdvancedSettings', () => { expect(screen.getByText('mock U2EInformation')) }) - it('renders the display show link to get labware offset data section', () => { - const [{ getByText, getByRole }] = render() - getByText('Show Labware Offset data code snippets') - 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.' - ) - getByRole('switch', { name: 'show_link_to_get_labware_offset_data' }) - }) - - it('renders the toggle button on when show link to labware offset data setting is true', () => { - mockGetIsLabwareOffsetCodeSnippetsOn.mockReturnValue(true) - const [{ getByRole }] = render() - const toggleButton = getByRole('switch', { - name: 'show_link_to_get_labware_offset_data', - }) - expect(toggleButton.getAttribute('aria-checked')).toBe('true') + it('should render mock show link to get labware offset data section', () => { + render() + screen.getByText('mock ShowLabwareOffsetSnippets') }) it('should render mock ShowHeaterShakerAttachmentModal section', () => {