-
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.
refactor(app): add alert to SystemInfoCard if u2e driver outdated (#5638
) Closes #5491
- Loading branch information
Showing
22 changed files
with
653 additions
and
117 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// @flow | ||
import * as React from 'react' | ||
import { Provider } from 'react-redux' | ||
import { mount } from 'enzyme' | ||
import noop from 'lodash/noop' | ||
|
||
import * as Cfg from '../../config' | ||
import * as Mixpanel from '../mixpanel' | ||
import { useTrackEvent } from '../hooks' | ||
|
||
import type { State } from '../../types' | ||
import type { Config } from '../../config/types' | ||
import type { AnalyticsEvent, AnalyticsConfig } from '../types' | ||
|
||
jest.mock('../../config') | ||
jest.mock('../mixpanel') | ||
|
||
const getConfig: JestMockFn<[State], $Shape<Config>> = Cfg.getConfig | ||
const trackEvent: JestMockFn<[AnalyticsEvent, AnalyticsConfig], void> = | ||
Mixpanel.trackEvent | ||
|
||
const MOCK_STATE: State = ({ mockState: true }: any) | ||
|
||
const MOCK_ANALYTICS_CONFIG = { | ||
appId: 'abc', | ||
optedIn: true, | ||
seenOptIn: true, | ||
} | ||
|
||
describe('analytics hooks', () => { | ||
beforeEach(() => { | ||
getConfig.mockImplementation(state => { | ||
expect(state).toBe(MOCK_STATE) | ||
return { analytics: MOCK_ANALYTICS_CONFIG } | ||
}) | ||
}) | ||
|
||
afterEach(() => { | ||
jest.resetAllMocks() | ||
}) | ||
|
||
describe('useTrackEvent', () => { | ||
let trackEventResult | ||
|
||
const TestTrackEvent = () => { | ||
trackEventResult = useTrackEvent() | ||
return <></> | ||
} | ||
|
||
const render = () => { | ||
return mount(<TestTrackEvent />, { | ||
wrappingComponent: Provider, | ||
wrappingComponentProps: { | ||
store: { | ||
subscribe: noop, | ||
dispatch: noop, | ||
getState: () => MOCK_STATE, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
it('should return a trackEvent function with config bound from state', () => { | ||
const event = { name: 'someEvent', properties: { foo: 'bar' } } | ||
|
||
render() | ||
trackEventResult(event) | ||
|
||
expect(trackEvent).toHaveBeenCalledWith(event, MOCK_ANALYTICS_CONFIG) | ||
}) | ||
}) | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// @flow | ||
import { useSelector } from 'react-redux' | ||
|
||
import { getConfig } from '../config' | ||
import { trackEvent } from './mixpanel' | ||
|
||
import type { State } from '../types' | ||
import type { AnalyticsEvent } from './types' | ||
|
||
/** | ||
* React hook to send an analytics tracking event directly from a component | ||
* | ||
* @returns {AnalyticsEvent => void} track event function | ||
*/ | ||
export function useTrackEvent(): AnalyticsEvent => void { | ||
const config = useSelector((state: State) => getConfig(state).analytics) | ||
return event => trackEvent(event, config) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,54 @@ | ||
// @flow | ||
import * as React from 'react' | ||
import { useSelector } from 'react-redux' | ||
import { css } from 'styled-components' | ||
|
||
import { ControlSection } from '@opentrons/components' | ||
import { getU2EAdapterDevice } from '../../system-info' | ||
import { | ||
Text, | ||
FONT_SIZE_BODY_1, | ||
FONT_WEIGHT_SEMIBOLD, | ||
} from '@opentrons/components' | ||
|
||
import * as SystemInfo from '../../system-info' | ||
import { U2EDriverWarning } from './U2EDriverWarning' | ||
import { U2EDeviceDetails } from './U2EDeviceDetails' | ||
|
||
import type { State } from '../../types' | ||
|
||
const U2E_ADAPTER_INFORMATION = 'USB-to-Ethernet Adapter Information' | ||
|
||
export const U2EAdapterInfo = () => { | ||
const device = useSelector(getU2EAdapterDevice) | ||
const device = useSelector(SystemInfo.getU2EAdapterDevice) | ||
const driverOutdated = useSelector((state: State) => { | ||
const status = SystemInfo.getU2EWindowsDriverStatus(state) | ||
return status === SystemInfo.OUTDATED | ||
}) | ||
|
||
return ( | ||
<ControlSection title={U2E_ADAPTER_INFORMATION}> | ||
<div | ||
css={css` | ||
font-size: ${FONT_SIZE_BODY_1}; | ||
padding: 1rem; | ||
`} | ||
> | ||
<Text | ||
as="h3" | ||
fontSize={FONT_SIZE_BODY_1} | ||
fontWeight={FONT_WEIGHT_SEMIBOLD} | ||
css={css` | ||
margin-bottom: 0.5rem; | ||
`} | ||
> | ||
{U2E_ADAPTER_INFORMATION} | ||
</Text> | ||
{driverOutdated && ( | ||
<U2EDriverWarning | ||
css={css` | ||
margin-bottom: 1rem; | ||
`} | ||
/> | ||
)} | ||
<U2EDeviceDetails device={device} /> | ||
</ControlSection> | ||
</div> | ||
) | ||
} |
Oops, something went wrong.