-
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.
- Loading branch information
1 parent
1f5f19d
commit f3a8fbe
Showing
3 changed files
with
158 additions
and
7 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
app/src/organisms/RobotSettingsDashboard/__tests__/Privacy.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,73 @@ | ||
import * as React from 'react' | ||
|
||
import { renderWithProviders } from '@opentrons/components' | ||
|
||
import { i18n } from '../../../i18n' | ||
import { toggleAnalyticsOptedIn } from '../../../redux/analytics' | ||
import { getRobotSettings, updateSetting } from '../../../redux/robot-settings' | ||
|
||
import { Privacy } from '../Privacy' | ||
|
||
jest.mock('../../../redux/analytics') | ||
jest.mock('../../../redux/robot-settings') | ||
|
||
const mockGetRobotSettings = getRobotSettings as jest.MockedFunction< | ||
typeof getRobotSettings | ||
> | ||
const mockUpdateSetting = updateSetting as jest.MockedFunction< | ||
typeof updateSetting | ||
> | ||
const mockToggleAnalyticsOptedIn = toggleAnalyticsOptedIn as jest.MockedFunction< | ||
typeof toggleAnalyticsOptedIn | ||
> | ||
|
||
const render = (props: React.ComponentProps<typeof Privacy>) => { | ||
return renderWithProviders(<Privacy {...props} />, { | ||
i18nInstance: i18n, | ||
}) | ||
} | ||
|
||
describe('Privacy', () => { | ||
let props: React.ComponentProps<typeof Privacy> | ||
beforeEach(() => { | ||
props = { | ||
robotName: 'Otie', | ||
setCurrentOption: jest.fn(), | ||
} | ||
mockGetRobotSettings.mockReturnValue([]) | ||
}) | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks() | ||
}) | ||
|
||
it('should render text and buttons', () => { | ||
const [{ getByText }] = render(props) | ||
getByText('Privacy') | ||
getByText( | ||
'Opentrons cares about your privacy. We anonymize all data and only use it to improve our products.' | ||
) | ||
getByText('Share robot logs') | ||
getByText('Data on actions the robot does, like running protocols.') | ||
getByText('Share display usage') | ||
getByText('Data on how you interact with the touchscreen on Flex.') | ||
}) | ||
|
||
it('should toggle display usage sharing on click', () => { | ||
const [{ getByText }] = render(props) | ||
|
||
getByText('Share display usage').click() | ||
expect(mockToggleAnalyticsOptedIn).toBeCalled() | ||
}) | ||
|
||
it('should toggle robot logs sharing on click', () => { | ||
const [{ getByText }] = render(props) | ||
|
||
getByText('Share robot logs').click() | ||
expect(mockUpdateSetting).toBeCalledWith( | ||
'Otie', | ||
'disableLogAggregation', | ||
true | ||
) | ||
}) | ||
}) |
85 changes: 85 additions & 0 deletions
85
app/src/pages/OnDeviceDisplay/RobotDashboard/__tests__/AnalyticsOptInModal.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,85 @@ | ||
import * as React from 'react' | ||
|
||
import { renderWithProviders } from '@opentrons/components' | ||
|
||
import { i18n } from '../../../../i18n' | ||
import { updateConfigValue } from '../../../../redux/config' | ||
import { getLocalRobot } from '../../../../redux/discovery' | ||
import { updateSetting } from '../../../../redux/robot-settings' | ||
import { AnalyticsOptInModal } from '../AnalyticsOptInModal' | ||
|
||
import type { DiscoveredRobot } from '../../../../redux/discovery/types' | ||
|
||
jest.mock('../../../../redux/config') | ||
jest.mock('../../../../redux/discovery') | ||
jest.mock('../../../../redux/robot-settings') | ||
|
||
const mockUpdateConfigValue = updateConfigValue as jest.MockedFunction< | ||
typeof updateConfigValue | ||
> | ||
const mockGetLocalRobot = getLocalRobot as jest.MockedFunction< | ||
typeof getLocalRobot | ||
> | ||
const mockUpdateSetting = updateSetting as jest.MockedFunction< | ||
typeof updateSetting | ||
> | ||
|
||
const render = (props: React.ComponentProps<typeof AnalyticsOptInModal>) => { | ||
return renderWithProviders(<AnalyticsOptInModal {...props} />, { | ||
i18nInstance: i18n, | ||
}) | ||
} | ||
|
||
describe('AnalyticsOptInModal', () => { | ||
let props: React.ComponentProps<typeof AnalyticsOptInModal> | ||
|
||
beforeEach(() => { | ||
props = { | ||
setShowAnalyticsOptInModal: jest.fn(), | ||
} | ||
mockGetLocalRobot.mockReturnValue({ name: 'Otie' } as DiscoveredRobot) | ||
}) | ||
|
||
it('should render text and button', () => { | ||
const [{ getByText }] = render(props) | ||
|
||
getByText('Want to help out Opentrons?') | ||
getByText( | ||
'Automatically send us anonymous diagnostics and usage data. We only use this information to improve our products.' | ||
) | ||
getByText('Opt out') | ||
getByText('Opt in') | ||
}) | ||
|
||
it('should call a mock function when tapping opt out button', () => { | ||
const [{ getByText }] = render(props) | ||
getByText('Opt out').click() | ||
|
||
expect(mockUpdateConfigValue).toHaveBeenCalledWith( | ||
'analytics.optedIn', | ||
false | ||
) | ||
expect(mockUpdateSetting).toHaveBeenCalledWith( | ||
'Otie', | ||
'disableLogAggregation', | ||
true | ||
) | ||
expect(props.setShowAnalyticsOptInModal).toHaveBeenCalled() | ||
}) | ||
|
||
it('should call a mock function when tapping out in button', () => { | ||
const [{ getByText }] = render(props) | ||
getByText('Opt in').click() | ||
|
||
expect(mockUpdateConfigValue).toHaveBeenCalledWith( | ||
'analytics.optedIn', | ||
true | ||
) | ||
expect(mockUpdateSetting).toHaveBeenCalledWith( | ||
'Otie', | ||
'disableLogAggregation', | ||
true | ||
) | ||
expect(props.setShowAnalyticsOptInModal).toHaveBeenCalled() | ||
}) | ||
}) |
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