-
Notifications
You must be signed in to change notification settings - Fork 344
feat(preview-optimizations): modernize Versions sidebar #4381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
146 changes: 118 additions & 28 deletions
146
src/elements/content-sidebar/versions/__tests__/VersionsItemActions.test.js
This file contains hidden or 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,44 +1,134 @@ | ||
| import * as React from 'react'; | ||
| import { shallow } from 'enzyme/build'; | ||
| import IconClockPast from '../../../../icons/general/IconClockPast'; | ||
| import IconDownload from '../../../../icons/general/IconDownload'; | ||
| import IconEllipsis from '../../../../icons/general/IconEllipsis'; | ||
| import IconOpenWith from '../../../../icons/general/IconOpenWith'; | ||
| import IconTrash from '../../../../icons/general/IconTrash'; | ||
| import IconUpload from '../../../../icons/general/IconUpload'; | ||
| import Tooltip from '../../../../components/tooltip/Tooltip'; | ||
| import { userEvent } from '@testing-library/user-event'; | ||
| import { screen, render } from '../../../../test-utils/testing-library'; | ||
| import VersionsItemActions from '../VersionsItemActions'; | ||
|
|
||
| describe('elements/content-sidebar/versions/VersionsItemActions', () => { | ||
| const getWrapper = (props = {}) => shallow(<VersionsItemActions isDownloadable isPreviewable {...props} />); | ||
| const defaultProps = { | ||
| fileId: '12345', | ||
| }; | ||
|
|
||
| const renderComponent = (props = {}, features = {}) => | ||
| render(<VersionsItemActions {...defaultProps} {...props} />, { | ||
| wrapperProps: { features }, | ||
| }); | ||
|
|
||
| describe('render', () => { | ||
| test.each([true, false])('should return the correct menu items based on options', option => { | ||
| const wrapper = getWrapper({ | ||
| showDelete: option, | ||
| showDownload: option, | ||
| showPreview: option, | ||
| showPromote: option, | ||
| showRestore: option, | ||
| test('should return null when no actions are shown', () => { | ||
| const { container } = renderComponent({ | ||
| showDelete: false, | ||
| showDownload: false, | ||
| showPreview: false, | ||
| showPromote: false, | ||
| showRestore: false, | ||
| }); | ||
|
|
||
| expect(container).toBeEmptyDOMElement(); | ||
| }); | ||
|
|
||
| test('should render actions toggle button when at least one action is shown', () => { | ||
| renderComponent({ showDownload: true }); | ||
|
|
||
| expect(screen.getByRole('button', { name: 'Toggle Actions Menu' })).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test.each([ | ||
| { actionProp: 'showPreview', label: 'Preview' }, | ||
| { actionProp: 'showDownload', label: 'Download' }, | ||
| { actionProp: 'showPromote', label: 'Make Current' }, | ||
| { actionProp: 'showRestore', label: 'Restore' }, | ||
| { actionProp: 'showDelete', label: 'Delete' }, | ||
| ])('should render $label action when $actionProp is true', async ({ actionProp, label }) => { | ||
| renderComponent({ [actionProp]: true }); | ||
|
|
||
| const toggleButton = screen.getByRole('button', { name: 'Toggle Actions Menu' }); | ||
| await userEvent.click(toggleButton); | ||
|
|
||
| expect(screen.getByRole('menuitem', { name: new RegExp(label) })).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('should render all actions when all show props are true', async () => { | ||
| renderComponent({ | ||
| showDelete: true, | ||
| showDownload: true, | ||
| showPreview: true, | ||
| showPromote: true, | ||
| showRestore: true, | ||
| }); | ||
|
|
||
| expect(wrapper.find(IconEllipsis).exists()).toBe(option); // Versions show actions if any permission is true | ||
| expect(wrapper.find(IconClockPast).exists()).toBe(option); | ||
| expect(wrapper.find(IconDownload).exists()).toBe(option); | ||
| expect(wrapper.find(IconOpenWith).exists()).toBe(option); | ||
| expect(wrapper.find(IconTrash).exists()).toBe(option); | ||
| expect(wrapper.find(IconUpload).exists()).toBe(option); | ||
| expect(wrapper).toMatchSnapshot(); | ||
| const toggleButton = screen.getByRole('button', { name: 'Toggle Actions Menu' }); | ||
| await userEvent.click(toggleButton); | ||
|
|
||
| expect(screen.getByRole('menuitem', { name: /Preview/ })).toBeInTheDocument(); | ||
| expect(screen.getByRole('menuitem', { name: /Download/ })).toBeInTheDocument(); | ||
| expect(screen.getByRole('menuitem', { name: /Make Current/ })).toBeInTheDocument(); | ||
| expect(screen.getByRole('menuitem', { name: /Restore/ })).toBeInTheDocument(); | ||
| expect(screen.getByRole('menuitem', { name: /Delete/ })).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test.each([true, false])('should enable/disable actions and tooltips if isRetained is %s', option => { | ||
| const wrapper = getWrapper({ | ||
| isRetained: option, | ||
| test('should disable delete action when isRetained is true', async () => { | ||
| renderComponent({ | ||
| isRetained: true, | ||
| showDelete: true, | ||
| }); | ||
|
|
||
| expect(wrapper.find(Tooltip).prop('isDisabled')).toBe(!option); | ||
| expect(wrapper).toMatchSnapshot(); | ||
| const toggleButton = screen.getByRole('button', { name: 'Toggle Actions Menu' }); | ||
| await userEvent.click(toggleButton); | ||
|
|
||
| const deleteButton = screen.getByRole('menuitem', { name: /Delete/ }); | ||
| expect(deleteButton).toHaveAttribute('aria-disabled', 'true'); | ||
| }); | ||
|
|
||
| test('should not disable delete action when isRetained is false', async () => { | ||
| renderComponent({ | ||
| isRetained: false, | ||
| showDelete: true, | ||
| }); | ||
|
|
||
| const toggleButton = screen.getByRole('button', { name: 'Toggle Actions Menu' }); | ||
| await userEvent.click(toggleButton); | ||
|
|
||
| const deleteButton = screen.getByRole('menuitem', { name: /Delete/ }); | ||
| expect(deleteButton).not.toHaveAttribute('aria-disabled', 'true'); | ||
| }); | ||
|
|
||
| describe('with previewModernization feature enabled', () => { | ||
| const previewModernizationFeatures = { | ||
| previewModernization: { enabled: true }, | ||
| }; | ||
|
|
||
| test('should render modernized toggle button', () => { | ||
| renderComponent({ showDownload: true }, previewModernizationFeatures); | ||
|
|
||
| const toggleButton = screen.getByRole('button', { name: 'Toggle Actions Menu' }); | ||
| expect(toggleButton).toHaveClass('bcs-VersionsItemActions-toggle--modernized'); | ||
| }); | ||
|
|
||
| test('should render actions in dropdown menu', async () => { | ||
| renderComponent( | ||
| { | ||
| showDownload: true, | ||
| showPreview: true, | ||
| }, | ||
| previewModernizationFeatures, | ||
| ); | ||
|
|
||
| const toggleButton = screen.getByRole('button', { name: 'Toggle Actions Menu' }); | ||
| await userEvent.click(toggleButton); | ||
|
|
||
| expect(screen.getByRole('menuitem', { name: /Download/ })).toBeInTheDocument(); | ||
| expect(screen.getByRole('menuitem', { name: /Preview/ })).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('with previewModernization feature disabled', () => { | ||
| test('should render legacy toggle button', () => { | ||
| renderComponent({ showDownload: true }); | ||
|
|
||
| const toggleButton = screen.getByRole('button', { name: 'Toggle Actions Menu' }); | ||
| expect(toggleButton).toHaveClass('bcs-VersionsItemActions-toggle'); | ||
| expect(toggleButton).not.toHaveClass('bcs-VersionsItemActions-toggle--modernized'); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
37 changes: 32 additions & 5 deletions
37
src/elements/content-sidebar/versions/__tests__/VersionsItemBadge.test.js
This file contains hidden or 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,14 +1,41 @@ | ||
| import * as React from 'react'; | ||
| import { render } from 'enzyme/build'; | ||
| import { screen, render } from '../../../../test-utils/testing-library'; | ||
| import VersionsItemBadge from '../VersionsItemBadge'; | ||
|
|
||
| describe('elements/content-sidebar/versions/VersionsItemBadge', () => { | ||
| const getWrapper = (props = {}) => render(<VersionsItemBadge {...props} />); | ||
| const renderComponent = (props = {}) => render(<VersionsItemBadge {...props} />); | ||
|
|
||
| describe('render', () => { | ||
| test('should match its snapshot', () => { | ||
| const wrapper = getWrapper({ versionNumber: '1' }); | ||
| expect(wrapper).toMatchSnapshot(); | ||
| test('should render version number badge', () => { | ||
| renderComponent({ versionNumber: '1' }); | ||
|
|
||
| expect(screen.getByText('V1')).toBeInTheDocument(); | ||
ahorowitz123 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| test('should have correct aria-label', () => { | ||
| renderComponent({ versionNumber: '5' }); | ||
|
|
||
| expect(screen.getByLabelText('Version number 5')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test.each` | ||
| isCurrent | shouldHaveCurrentClass | ||
| ${true} | ${true} | ||
| ${false} | ${false} | ||
| ${undefined} | ${false} | ||
| `( | ||
| 'should apply current class correctly when isCurrent is $isCurrent', | ||
| ({ isCurrent, shouldHaveCurrentClass }) => { | ||
| renderComponent({ versionNumber: '1', isCurrent }); | ||
|
|
||
| const badge = screen.getByText('V1'); | ||
| expect(badge).toHaveClass('bcs-VersionsItemBadge'); | ||
| if (shouldHaveCurrentClass) { | ||
| expect(badge).toHaveClass('bcs-VersionsItemBadge--current'); | ||
| } else { | ||
| expect(badge).not.toHaveClass('bcs-VersionsItemBadge--current'); | ||
| } | ||
| }, | ||
| ); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.