-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mespapiers): Add ScanFlagshipActions component
Addition of actions on the Scan step, if the application is used with the flagship app
- Loading branch information
Showing
7 changed files
with
257 additions
and
14 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
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
69 changes: 69 additions & 0 deletions
69
packages/cozy-mespapiers-lib/src/components/ModelSteps/ScanFlagshipActions.jsx
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,69 @@ | ||
import PropTypes from 'prop-types' | ||
import React from 'react' | ||
|
||
import Button from 'cozy-ui/transpiled/react/Buttons' | ||
import FileInput from 'cozy-ui/transpiled/react/FileInput' | ||
import { useI18n } from 'cozy-ui/transpiled/react/I18n' | ||
import Icon from 'cozy-ui/transpiled/react/Icon' | ||
import Divider from 'cozy-ui/transpiled/react/MuiCozyTheme/Divider' | ||
|
||
const styleBtn = { color: 'var(--primaryTextColor)' } | ||
|
||
const ScanFlagshipActions = ({ | ||
openFilePickerModal, | ||
onChangeFile, | ||
onOpenFlagshipScan | ||
}) => { | ||
const { t } = useI18n() | ||
|
||
return ( | ||
<> | ||
<div> | ||
<Divider textAlign="center" className="u-mv-1"> | ||
{t('Scan.divider')} | ||
</Divider> | ||
<Button | ||
variant="secondary" | ||
style={styleBtn} | ||
onClick={openFilePickerModal} | ||
startIcon={<Icon icon="folder-moveto" />} | ||
label={t('Scan.selectPicFromCozy')} | ||
data-testid="selectPicFromCozy-btn" | ||
/> | ||
<FileInput | ||
onChange={onChangeFile} | ||
className="u-w-100 u-ml-0" | ||
onClick={e => e.stopPropagation()} | ||
accept={'image/*,.pdf'} | ||
data-testid="importPicFromMobile-btn" | ||
> | ||
<Button | ||
variant="secondary" | ||
component="a" | ||
style={styleBtn} | ||
startIcon={<Icon icon="phone-upload" />} | ||
fullWidth | ||
className="u-m-0" | ||
label={t('Scan.importPicFromMobile')} | ||
/> | ||
</FileInput> | ||
</div> | ||
<Button | ||
onClick={onOpenFlagshipScan} | ||
startIcon={<Icon icon="camera" />} | ||
fullWidth | ||
className="u-m-0" | ||
label={t('Scan.takePic')} | ||
data-testid="importPicFromFlagshipScan-btn" | ||
/> | ||
</> | ||
) | ||
} | ||
|
||
ScanFlagshipActions.propTypes = { | ||
onChangeFile: PropTypes.func, | ||
openFilePickerModal: PropTypes.func, | ||
onOpenFlagshipScan: PropTypes.func | ||
} | ||
|
||
export default ScanFlagshipActions |
60 changes: 60 additions & 0 deletions
60
packages/cozy-mespapiers-lib/src/components/ModelSteps/ScanFlagshipActions.spec.jsx
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,60 @@ | ||
import { fireEvent, render } from '@testing-library/react' | ||
import React from 'react' | ||
|
||
import ScanFlagshipActions from './ScanFlagshipActions' | ||
import AppLike from '../../../test/components/AppLike' | ||
|
||
const setup = ({ | ||
onOpenFilePickerModal, | ||
onChangeFile, | ||
onOpenFlagshipScan | ||
} = {}) => { | ||
return render( | ||
<AppLike> | ||
<ScanFlagshipActions | ||
onOpenFilePickerModal={ | ||
onOpenFilePickerModal ? onOpenFilePickerModal : undefined | ||
} | ||
onChangeFile={onChangeFile ? onChangeFile : undefined} | ||
onOpenFlagshipScan={onOpenFlagshipScan ? onOpenFlagshipScan : undefined} | ||
/> | ||
</AppLike> | ||
) | ||
} | ||
|
||
describe('ScanFlagshipActions', () => { | ||
it('should called onOpenFilePickerModal function', () => { | ||
const onOpenFilePickerModal = jest.fn() | ||
const { getByTestId } = setup({ | ||
onOpenFilePickerModal | ||
}) | ||
|
||
const submitButton = getByTestId('selectPicFromCozy-btn') | ||
|
||
fireEvent.click(submitButton) | ||
|
||
expect(onOpenFilePickerModal).toBeCalledTimes(1) | ||
}) | ||
|
||
it('should have one input with type file attribute', () => { | ||
const { container } = setup() | ||
const inputFileButtons = container.querySelectorAll('input[type="file"]') | ||
|
||
expect(inputFileButtons).toHaveLength(1) | ||
}) | ||
|
||
it('should called onOpenFlagshipScan function', () => { | ||
const onOpenFlagshipScan = jest.fn() | ||
const { getByTestId } = setup({ | ||
onOpenFlagshipScan | ||
}) | ||
|
||
const importPicFromFlagshipScanButton = getByTestId( | ||
'importPicFromFlagshipScan-btn' | ||
) | ||
|
||
fireEvent.click(importPicFromFlagshipScanButton) | ||
|
||
expect(onOpenFlagshipScan).toBeCalledTimes(1) | ||
}) | ||
}) |
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