-
Notifications
You must be signed in to change notification settings - Fork 314
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(content-uploader): migrate IconName component (#3613)
* refactor(content-uploader): migrate IconName component * fix: test case wording * fix: export and InTheDocument --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
- Loading branch information
1 parent
8a183e0
commit ccc1239
Showing
10 changed files
with
136 additions
and
230 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
File renamed without changes.
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,54 @@ | ||
import * as React from 'react'; | ||
import { useIntl } from 'react-intl'; | ||
import { FolderPersonal } from '@box/blueprint-web-assets/icons/Content'; | ||
import { Size8 } from '@box/blueprint-web-assets/tokens/tokens'; | ||
import Badgeable from '../../components/badgeable'; | ||
import FileIcon from '../../icons/file-icon/FileIcon'; | ||
import IconAlertDefault from '../../icons/general/IconAlertDefault'; | ||
import ItemName from './ItemName'; | ||
import { STATUS_ERROR } from '../../constants'; | ||
import messages from '../common/messages'; | ||
import type { UploadStatus } from '../../common/types/upload'; | ||
import './IconName.scss'; | ||
|
||
export interface IconNameProps { | ||
extension: string; | ||
isFolder?: boolean; | ||
isResumableUploadsEnabled: boolean; | ||
name: string; | ||
status: UploadStatus; | ||
} | ||
|
||
const IconName = ({ name, extension, isFolder = false, isResumableUploadsEnabled, status }: IconNameProps) => { | ||
const { formatMessage } = useIntl(); | ||
|
||
let icon = isFolder ? ( | ||
<FolderPersonal height={Size8} aria-label={formatMessage(messages.folder)} width={Size8} /> | ||
) : ( | ||
<FileIcon extension={extension} title={formatMessage(messages.file)} /> | ||
); | ||
|
||
if (isResumableUploadsEnabled && status === STATUS_ERROR) { | ||
icon = ( | ||
<Badgeable | ||
className="bcu-icon-badge" | ||
bottomRight={<IconAlertDefault height={18} title={formatMessage(messages.error)} width={18} />} | ||
> | ||
{icon} | ||
</Badgeable> | ||
); | ||
} | ||
|
||
return ( | ||
<div className="bcu-item-icon-name"> | ||
<div className="bcu-item-icon" data-testid="bcu-IconName-icon"> | ||
{icon} | ||
</div> | ||
<div className="bcu-item-name"> | ||
<ItemName name={name} /> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default IconName; |
This file was deleted.
Oops, something went wrong.
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,10 @@ | ||
import * as React from 'react'; | ||
import './ItemName.scss'; | ||
|
||
export interface ItemNameProps { | ||
name: string; | ||
} | ||
|
||
const ItemName = ({ name }: ItemNameProps) => <span className="bcu-item-label">{name}</span>; | ||
|
||
export default ItemName; |
This file was deleted.
Oops, something went wrong.
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,42 @@ | ||
import * as React from 'react'; | ||
import { render, screen } from '../../../test-utils/testing-library'; | ||
import IconName from '../IconName'; | ||
import { STATUS_ERROR, STATUS_IN_PROGRESS } from '../../../constants'; | ||
|
||
describe('elements/content-uploader/IconName', () => { | ||
const renderComponent = (props = {}) => { | ||
const defaultProps = { | ||
extension: 'pdf', | ||
name: 'test-item', | ||
isResumableUploadsEnabled: false, | ||
status: 'pending', | ||
}; | ||
render(<IconName {...defaultProps} {...props} />); | ||
}; | ||
|
||
test('renders component correctly', () => { | ||
renderComponent(); | ||
|
||
expect(screen.getByRole('img', { name: 'File' })).toBeInTheDocument(); | ||
expect(screen.getByText('test-item')).toBeInTheDocument(); | ||
}); | ||
|
||
test('renders component correctly when item is a folder', () => { | ||
renderComponent({ isFolder: true }); | ||
|
||
expect(screen.getByRole('img', { name: 'Folder' })).toBeInTheDocument(); | ||
expect(screen.getByText('test-item')).toBeInTheDocument(); | ||
}); | ||
|
||
test('renders alert badge when there is an error', () => { | ||
renderComponent({ isResumableUploadsEnabled: true, status: STATUS_ERROR }); | ||
|
||
expect(screen.getByRole('img', { name: 'Error' })).toBeInTheDocument(); | ||
}); | ||
|
||
test('does not render alert badge when there is no error', () => { | ||
renderComponent({ isResumableUploadsEnabled: true, status: STATUS_IN_PROGRESS }); | ||
|
||
expect(screen.queryByRole('img', { name: 'Error' })).not.toBeInTheDocument(); | ||
}); | ||
}); |
141 changes: 0 additions & 141 deletions
141
src/elements/content-uploader/__tests__/__snapshots__/IconName.test.js.snap
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.