From 5388d2b812bd95ebb538c37ffd32690a16d03057 Mon Sep 17 00:00:00 2001 From: Sanniti Date: Thu, 7 May 2020 18:14:31 -0400 Subject: [PATCH] feat(app): add UI to clear cached robots Closes #2435 --- .../ClearDiscoveryCache.js | 4 +- .../__tests__/ClearDiscoveryCache.test.js | 41 +++++++++++++++---- .../__tests__/NetworkSettingsCard.test.js | 8 +++- 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/app/src/components/NetworkSettingsCard/ClearDiscoveryCache.js b/app/src/components/NetworkSettingsCard/ClearDiscoveryCache.js index 2c0e30c62b5..8bde2debbad 100644 --- a/app/src/components/NetworkSettingsCard/ClearDiscoveryCache.js +++ b/app/src/components/NetworkSettingsCard/ClearDiscoveryCache.js @@ -14,12 +14,12 @@ import type { Dispatch } from '../../types' export function ClearDiscoveryCache() { const dispatch = useDispatch() - return ( {dispatch(clearDiscoveryCache())}, children: CLEAR + onClick: () => dispatch(clearDiscoveryCache()), + children: CLEAR, }} >

{CLEAR_ROBOTS_DESCRIPTION}

diff --git a/app/src/components/NetworkSettingsCard/__tests__/ClearDiscoveryCache.test.js b/app/src/components/NetworkSettingsCard/__tests__/ClearDiscoveryCache.test.js index 7b7d7eca2c9..4709aa7e34f 100644 --- a/app/src/components/NetworkSettingsCard/__tests__/ClearDiscoveryCache.test.js +++ b/app/src/components/NetworkSettingsCard/__tests__/ClearDiscoveryCache.test.js @@ -1,15 +1,42 @@ // @flow import * as React from 'react' -import { shallow } from 'enzyme' - +import { Provider } from 'react-redux' +import { mount } from 'enzyme' +import noop from 'lodash/noop' import { LabeledButton } from '@opentrons/components' import { ClearDiscoveryCache } from '../ClearDiscoveryCache' +import { clearDiscoveryCache } from '../../../discovery' describe('ClearDiscoveryCache', () => { - it('renders clear discovery cache component', () => { - const wrapper = shallow() - expect(wrapper.find(LabeledButton).prop('label')).toBe( - 'Clear Discovered Robots List' - ) + const dispatch = jest.fn() + const MOCK_STORE = { + dispatch, + getState: noop, + subscribe: noop, + } + + const render = () => { + return mount(, { + wrappingComponent: Provider, + wrappingComponentProps: { store: MOCK_STORE }, + }) + } + + afterEach(() => { + jest.resetAllMocks() + }) + + it('renders a labelled button component', () => { + const wrapper = render() + const theButton = wrapper.find(LabeledButton) + expect(theButton.prop('label')).toBe('Clear Discovered Robots List') + expect(theButton.prop('buttonProps').children).toBe('clear') + }) + + it('dispatches a ClearDiscoveryCache Action', () => { + const wrapper = render() + const buttonProps = wrapper.find(LabeledButton).prop('buttonProps') + buttonProps.onClick() + expect(dispatch).toHaveBeenCalledWith(clearDiscoveryCache()) }) }) diff --git a/app/src/components/NetworkSettingsCard/__tests__/NetworkSettingsCard.test.js b/app/src/components/NetworkSettingsCard/__tests__/NetworkSettingsCard.test.js index f98bab4c364..ea0b540bcff 100644 --- a/app/src/components/NetworkSettingsCard/__tests__/NetworkSettingsCard.test.js +++ b/app/src/components/NetworkSettingsCard/__tests__/NetworkSettingsCard.test.js @@ -5,6 +5,7 @@ import { shallow } from 'enzyme' import { Card } from '@opentrons/components' import { AddManualIp } from '../AddManualIp' import { NetworkSettingsCard } from '..' +import { ClearDiscoveryCache } from '../ClearDiscoveryCache' describe('NetworkSettingsCard', () => { it('should render a card with the proper title', () => { @@ -14,6 +15,11 @@ describe('NetworkSettingsCard', () => { it('should render an AddManualIp setting component', () => { const wrapper = shallow() - expect(wrapper.find(AddManualIp)).toHaveLength(1) + expect(wrapper.exists(AddManualIp)).toBe(true) + }) + + it('should render a ClearDiscoveryCache component', () => { + const wrapper = shallow() + expect(wrapper.exists(ClearDiscoveryCache)).toBe(true) }) })