-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Refactor the viewer to let the app handle the action buttons
BREAKING CHANGE: The management of action buttons should now be handled on the application side via the `FooterActionButtons` component. The `disableSharing` prop has also been removed, as it is no longer needed. Example: ``` <Viewer {...props}> <FooterActionButtons> <SharingButton /> <ForwardOrDownloadButton /> </FooterActionButtons> </Viewer> ``` You can use a codemods `transform-viewer.js` to automatically handle this breaking change. [See the codemods documentation](https://github.com/cozy/cozy-libs/tree/master/packages/cozy-codemods). Using linter js auto-correction can be a good idea after that. Here a common example (don't forget to change `src` value): ``` jscodeshift -t $(yarn global dir)/node_modules/@cozy/codemods/src/transforms/transform-viewer.js src --parser babel --extensions js,jsx && yarn lint:js --fix ```
- Loading branch information
Showing
4 changed files
with
102 additions
and
36 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
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,63 @@ | ||
import React from 'react' | ||
import { render } from '@testing-library/react' | ||
|
||
import ViewerInformationsWrapper from './ViewerInformationsWrapper' | ||
|
||
/* eslint-disable react/display-name */ | ||
jest.mock('./Footer', () => ({ children }) => ( | ||
<div data-testid="Footer">{children}</div> | ||
)) | ||
jest.mock('./InformationPanel', () => ({ children }) => ( | ||
<div data-testid="InformationPanel">{children}</div> | ||
)) | ||
jest.mock('./Panel/PanelContent', () => () => ( | ||
<div data-testid="PanelContent" /> | ||
)) | ||
jest.mock('./Footer/FooterContent', () => () => ( | ||
<div data-testid="FooterContent" /> | ||
)) | ||
/* eslint-enable react/display-name */ | ||
|
||
const setup = ({ validForPanel, disableFooter } = {}) => { | ||
return render( | ||
<ViewerInformationsWrapper | ||
currentFile={{}} | ||
disableFooter={disableFooter} | ||
validForPanel={validForPanel} | ||
/> | ||
) | ||
} | ||
|
||
describe('ViewerInformationsWrapper', () => { | ||
describe('disableFooter', () => { | ||
it('should render FooterContent components', () => { | ||
const { getByTestId } = setup({ disableFooter: false }) | ||
|
||
expect(getByTestId('Footer')) | ||
expect(getByTestId('FooterContent')) | ||
}) | ||
|
||
it('should not render FooterContent components', () => { | ||
const { queryByTestId } = setup({ disableFooter: true }) | ||
|
||
expect(queryByTestId('Footer')).toBeNull() | ||
expect(queryByTestId('FooterContent')).toBeNull() | ||
}) | ||
}) | ||
|
||
describe('validForPanel', () => { | ||
it('should render InformationPanel & PanelContent components', () => { | ||
const { getByTestId } = setup({ validForPanel: true }) | ||
|
||
expect(getByTestId('InformationPanel')) | ||
expect(getByTestId('PanelContent')) | ||
}) | ||
|
||
it('should not render InformationPanel & PanelContent components', () => { | ||
const { queryByTestId } = setup({ validForPanel: false }) | ||
|
||
expect(queryByTestId('InformationPanel')).toBeNull() | ||
expect(queryByTestId('PanelContent')).toBeNull() | ||
}) | ||
}) | ||
}) |