-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app): make protocol runs from history clickable
closes #10502
- Loading branch information
Showing
3 changed files
with
133 additions
and
34 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
82 changes: 65 additions & 17 deletions
82
app/src/organisms/Devices/__tests__/HistoricalProtocolRun.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 |
---|---|---|
@@ -1,57 +1,105 @@ | ||
import * as React from 'react' | ||
import { fireEvent } from '@testing-library/react' | ||
import { renderWithProviders } from '@opentrons/components' | ||
import { i18n } from '../../../i18n' | ||
import { getStoredProtocols } from '../../../redux/protocol-storage' | ||
import { storedProtocolData as storedProtocolDataFixture } from '../../../redux/protocol-storage/__fixtures__' | ||
import { useRunStatus } from '../../RunTimeControl/hooks' | ||
import { HistoricalProtocolRun } from '../HistoricalProtocolRun' | ||
import { HistoricalProtocolRunOverflowMenu } from '../HistoricalProtocolRunOverflowMenu' | ||
import type { RunStatus, RunData } from '@opentrons/api-client' | ||
|
||
const mockPush = jest.fn() | ||
|
||
jest.mock('../../../redux/protocol-storage') | ||
jest.mock('../../RunTimeControl/hooks') | ||
jest.mock('../HistoricalProtocolRunOverflowMenu') | ||
jest.mock('react-router-dom', () => { | ||
const reactRouterDom = jest.requireActual('react-router-dom') | ||
return { | ||
...reactRouterDom, | ||
useHistory: () => ({ push: mockPush } as any), | ||
} | ||
}) | ||
|
||
const mockUseRunStatus = useRunStatus as jest.MockedFunction< | ||
typeof useRunStatus | ||
> | ||
const mockHistoricalProtocolRunOverflowMenu = HistoricalProtocolRunOverflowMenu as jest.MockedFunction< | ||
typeof HistoricalProtocolRunOverflowMenu | ||
> | ||
const mockGetStoredProtocols = getStoredProtocols as jest.MockedFunction< | ||
typeof getStoredProtocols | ||
> | ||
|
||
const run = { | ||
createdAt: '2022-05-04T18:24:40.833862+00:00', | ||
current: false, | ||
id: 'test_id', | ||
protocolId: 'test_protocol_id', | ||
status: 'succeeded' as RunStatus, | ||
} as RunData | ||
const render = () => { | ||
return renderWithProviders( | ||
<HistoricalProtocolRun | ||
robotName="otie" | ||
protocolName="my protocol" | ||
robotIsBusy={false} | ||
run={run} | ||
key={1} | ||
/>, | ||
{ | ||
i18nInstance: i18n, | ||
} | ||
) | ||
|
||
const render = (props: React.ComponentProps<typeof HistoricalProtocolRun>) => { | ||
return renderWithProviders(<HistoricalProtocolRun {...props} />, { | ||
i18nInstance: i18n, | ||
})[0] | ||
} | ||
|
||
describe('RecentProtocolRuns', () => { | ||
let props: React.ComponentProps<typeof HistoricalProtocolRun> | ||
|
||
beforeEach(() => { | ||
props = { | ||
robotName: 'otie', | ||
protocolName: 'my protocol', | ||
protocolKey: 'protocolKeyStub', | ||
robotIsBusy: false, | ||
run: run, | ||
key: 1, | ||
} | ||
mockHistoricalProtocolRunOverflowMenu.mockReturnValue( | ||
<div>mock HistoricalProtocolRunOverflowMenu</div> | ||
) | ||
mockUseRunStatus.mockReturnValue('succeeded') | ||
mockGetStoredProtocols.mockReturnValue([storedProtocolDataFixture]) | ||
}) | ||
afterEach(() => { | ||
jest.resetAllMocks() | ||
}) | ||
it('renders the correct information derived from run and protocol', () => { | ||
mockUseRunStatus.mockReturnValue('succeeded') | ||
const [{ getByText }] = render() | ||
|
||
getByText('my protocol') | ||
const { getByText } = render(props) | ||
const protocolBtn = getByText('my protocol') | ||
getByText('Completed') | ||
getByText('mock HistoricalProtocolRunOverflowMenu') | ||
const runBtn = getByText('05/04/2022 14:24:40') | ||
fireEvent.click(protocolBtn) | ||
expect(mockPush).toHaveBeenCalledWith('/protocols/protocolKeyStub') | ||
fireEvent.click(runBtn) | ||
expect(mockPush).toHaveBeenCalledWith( | ||
'otie/protocol-runs/test_id/protocolRunDetailsTab?' | ||
) | ||
}) | ||
it('renders buttons that are not clickable when the protocol was deleted from the app directory', () => { | ||
mockGetStoredProtocols.mockReturnValue([storedProtocolDataFixture]) | ||
props = { | ||
robotName: 'otie', | ||
protocolName: 'my protocol', | ||
protocolKey: '12345', | ||
robotIsBusy: false, | ||
run: run, | ||
key: 1, | ||
} | ||
const { getByText } = render(props) | ||
const protocolBtn = getByText('my protocol') | ||
getByText('Completed') | ||
getByText('mock HistoricalProtocolRunOverflowMenu') | ||
const runBtn = getByText('05/04/2022 14:24:40') | ||
fireEvent.click(protocolBtn) | ||
expect(mockPush).not.toHaveBeenCalledWith('/protocols/12345') | ||
fireEvent.click(runBtn) | ||
expect(mockPush).not.toHaveBeenCalledWith( | ||
'otie/protocol-runs/test_id/protocolRunDetailsTab?' | ||
) | ||
}) | ||
}) |