-
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.
feat(app, app-shell): add ability to disable discovery cache (#5759)
- Loading branch information
Showing
6 changed files
with
194 additions
and
3 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
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
31 changes: 31 additions & 0 deletions
31
app/src/components/NetworkSettingsCard/DisableDiscoveryCache.js
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,31 @@ | ||
// @flow | ||
import * as React from 'react' | ||
import { useSelector, useDispatch } from 'react-redux' | ||
import { LabeledToggle } from '@opentrons/components' | ||
import type { State, Dispatch } from '../../types' | ||
import { getConfig, updateConfig } from '../../config' | ||
|
||
export const DisableDiscoveryCache = () => { | ||
const cacheDisabled = useSelector((state: State) => { | ||
const config = getConfig(state) | ||
return config.discovery.disableCache | ||
}) | ||
const dispatch = useDispatch<Dispatch>() | ||
return ( | ||
<LabeledToggle | ||
label="Disable robot caching" | ||
toggledOn={cacheDisabled} | ||
onClick={() => { | ||
dispatch(updateConfig('discovery.disableCache', !cacheDisabled)) | ||
}} | ||
> | ||
<p>NOTE: This will clear cached robots when switched ON.</p> | ||
<p> | ||
Disable caching of previously seen robots. Enabling this setting may | ||
improve overall networking performance in environments with many OT-2s, | ||
but may cause initial OT-2 discovery on app launch to be slower and more | ||
susceptible to failures. | ||
</p> | ||
</LabeledToggle> | ||
) | ||
} |
91 changes: 91 additions & 0 deletions
91
app/src/components/NetworkSettingsCard/__tests__/DisableDiscoveryCache.test.js
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,91 @@ | ||
// @flow | ||
import * as React from 'react' | ||
import { Provider } from 'react-redux' | ||
import { mount } from 'enzyme' | ||
import noop from 'lodash/noop' | ||
|
||
import * as AllConfig from '../../../config' | ||
import { LabeledToggle } from '@opentrons/components' | ||
import { DisableDiscoveryCache } from '../DisableDiscoveryCache' | ||
|
||
import type { State } from '../../../types' | ||
import type { Config } from '../../../config/types' | ||
|
||
jest.mock('../../../config/selectors') | ||
|
||
const MOCK_STATE: State = ({ mockState: true }: any) | ||
|
||
const getConfig: JestMockFn<[State], $Shape<Config>> = AllConfig.getConfig | ||
|
||
function stubSelector<R>(mock: JestMockFn<[State], R>, rVal: R) { | ||
mock.mockImplementation(state => { | ||
expect(state).toBe(MOCK_STATE) | ||
return rVal | ||
}) | ||
} | ||
|
||
describe('DisableDiscoveryCache', () => { | ||
const dispatch = jest.fn() | ||
const MOCK_STORE = { | ||
dispatch: dispatch, | ||
subscribe: noop, | ||
getState: () => MOCK_STATE, | ||
} | ||
|
||
const render = () => { | ||
return mount(<DisableDiscoveryCache />, { | ||
wrappingComponent: Provider, | ||
wrappingComponentProps: { store: MOCK_STORE }, | ||
}) | ||
} | ||
|
||
beforeEach(() => { | ||
stubSelector(getConfig, { | ||
discovery: { candidates: [], disableCache: false }, | ||
}) | ||
}) | ||
|
||
afterEach(() => { | ||
jest.resetAllMocks() | ||
}) | ||
|
||
it('renders a labelled toggle component', () => { | ||
const wrapper = render() | ||
const theToggle = wrapper.find(LabeledToggle) | ||
expect(theToggle.prop('label')).toBe('Disable robot caching') | ||
expect(theToggle.prop('toggledOn')).toBe(false) | ||
}) | ||
|
||
it('renders description of the toggle component', () => { | ||
const wrapper = render() | ||
expect(wrapper.children().html()).toMatch( | ||
/Disable caching of previously seen robots./ | ||
) | ||
}) | ||
|
||
it('updates the toggle status according to disableCache config', () => { | ||
stubSelector(getConfig, { | ||
discovery: { candidates: [], disableCache: true }, | ||
}) | ||
const wrapper = render() | ||
expect(wrapper.find(LabeledToggle).prop('toggledOn')).toBe(true) | ||
|
||
// toggle switches value | ||
stubSelector(getConfig, { | ||
discovery: { candidates: [], disableCache: false }, | ||
}) | ||
|
||
// trigger a re-render | ||
wrapper.setProps({}) | ||
expect(wrapper.find(LabeledToggle).prop('toggledOn')).toBe(false) | ||
}) | ||
|
||
it('dispatches config update on toggle', () => { | ||
const wrapper = render() | ||
const theToggle = wrapper.find(LabeledToggle) | ||
theToggle.prop('onClick')() | ||
expect(dispatch).toHaveBeenCalledWith( | ||
AllConfig.updateConfig('discovery.disableCache', true) | ||
) | ||
}) | ||
}) |
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