Skip to content

Commit

Permalink
add privacy and opt in modal tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brenthagen committed Sep 12, 2023
1 parent 1f5f19d commit f3a8fbe
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 7 deletions.
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
)
})
})
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()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as React from 'react'
import { renderWithProviders } from '@opentrons/components'

import { i18n } from '../../../../i18n'
import { updateConfigValue } from '../../../../redux/config'
import { WelcomeModal } from '../WelcomeModal'
import { useCreateLiveCommandMutation } from '@opentrons/react-api-client'

Expand All @@ -20,10 +19,6 @@ const mockUseCreateLiveCommandMutation = useCreateLiveCommandMutation as jest.Mo
const mockFunc = jest.fn()
const WELCOME_MODAL_IMAGE_NAME = 'welcome_dashboard_modal.png'

const mockUpdateConfigValue = updateConfigValue as jest.MockedFunction<
typeof updateConfigValue
>

const render = (props: React.ComponentProps<typeof WelcomeModal>) => {
return renderWithProviders(<WelcomeModal {...props} />, {
i18nInstance: i18n,
Expand Down Expand Up @@ -70,8 +65,6 @@ describe('WelcomeModal', () => {
it('should call a mock function when tapping next button', () => {
const [{ getByText }] = render(props)
getByText('Next').click()
// move to analytics modal test
// expect(mockUpdateConfigValue).toHaveBeenCalled()
expect(props.setShowWelcomeModal).toHaveBeenCalled()
expect(props.setShowAnalyticsOptInModal).toHaveBeenCalled()
})
Expand Down

0 comments on commit f3a8fbe

Please sign in to comment.